diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h index 9c2c9673055686c487e3fbde624f9817333c4925..327a8cc94bc5b14363b8aec0a25f64497c0a9ac4 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/CFLinker.h @@ -25,7 +25,7 @@ public: explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones); ~CFLinker(); - void link(); + void link(int student_id, int cf_zone_index, std::string cf_name); void unlink_selection(); void unlink_cf_zone(int cf_zone_index); @@ -37,6 +37,8 @@ public: int getCFZoneIndexFromName(QString name); int getCFIndexFromName(std::string name); + void clear_all_links(); + signals: void updateComboBoxes(); diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h index c7a1beba556331002a6ee22991f6c3758b351b0b..cd1adc1f30c14c817b6d0baa4bc12c520c3def35 100755 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h @@ -13,6 +13,11 @@ #include "marker.h" #include "crazyFly.h" #include "CFLinker.h" + +#include "d_fall_pps/CrazyflieDB.h" + + +using namespace d_fall_pps; #endif @@ -99,6 +104,10 @@ private slots: void on_checkBox_vicon_highlight_markers_toggled(bool checked); + void on_save_in_DB_button_clicked(); + + void on_load_from_DB_button_clicked(); + #ifdef CATKIN_MAKE void updateNewViconData(const ptrToMessage& p_msg); #endif @@ -138,6 +147,7 @@ private: int getTabIndexFromName(QString name); + CrazyflieDB m_data_base; }; diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/rosNodeThread.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/rosNodeThread.h index c40195aeae94e7b4ef229e218ff2acd96f51191f..ec6cffd8d3bbe67f307cd3397223108a61047bf0 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/rosNodeThread.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/rosNodeThread.h @@ -33,6 +33,8 @@ public: // void messageCallback(const ViconData& data); void messageCallback(const ptrToMessage& p_msg); + ros::ServiceClient m_read_db_client; + signals: diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp index 5c80c475c5a7c3ffa6bae57493d29020cc83cf20..f1f3eb119486dc5f86d3cd513493ec4b0100f6dc 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/CFLinker.cpp @@ -91,20 +91,20 @@ void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_ m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, item_cf_zone); } -void CFLinker::link() +void CFLinker::link(int student_id, int cf_zone_index, std::string cf_name) { m_ui->table_links->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); struct link tmp_link; - tmp_link.student_id = m_ui->spinBox_student_ids->value(); - tmp_link.cf_zone_index = getCFZoneIndexFromName(m_ui->comboBoxCFZones->currentText()); - tmp_link.cf_name = m_ui->comboBoxCFs->currentText().toStdString(); + tmp_link.student_id = student_id; + tmp_link.cf_zone_index = cf_zone_index; + tmp_link.cf_name = cf_name; ROS_INFO("tmp_link.cf_zone_index %d", tmp_link.cf_zone_index); ROS_INFO("tmp_link.cf_name %s", tmp_link.cf_name.c_str()); - (*m_crazyfly_zones)[tmp_link.cf_zone_index]->linkCF(tmp_link.cf_name); - (*m_crazyflies_vector)[getCFIndexFromName(tmp_link.cf_name)]->assignCFZone(tmp_link.cf_zone_index); + // (*m_crazyfly_zones)[tmp_link.cf_zone_index]->linkCF(tmp_link.cf_name); + // (*m_crazyflies_vector)[getCFIndexFromName(tmp_link.cf_name)]->assignCFZone(tmp_link.cf_zone_index); addNewRow(m_ui->spinBox_student_ids->value(), tmp_link.cf_name, tmp_link.cf_zone_index); @@ -123,6 +123,13 @@ void CFLinker::link() // ui->comboBox->setItemData(index, 33, Qt::UserRole - 1); } +void CFLinker::clear_all_links() +{ + links.clear(); + m_ui->table_links->setRowCount(0); + emit updateComboBoxes(); +} + void CFLinker::unlink_cf_zone(int cf_zone_index) { for(int i = 0; i < links.size(); i++) diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp index 0c00c48ed80131be980ac2f66e9dc4d6ca5c3ec9..1073d852812f331cbc6a54632580c0a9287de6c1 100755 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp @@ -14,6 +14,7 @@ #ifdef CATKIN_MAKE #include "d_fall_pps/UnlabeledMarker.h" +#include "d_fall_pps/CMRead.h" #endif #include <string> @@ -678,7 +679,7 @@ void MainGUIWindow::on_link_button_clicked() if(!error) { - cf_linker->link(); + cf_linker->link(ui->spinBox_student_ids->value(), cf_linker->getCFZoneIndexFromName(ui->comboBoxCFZones->currentText()), ui->comboBoxCFs->currentText().toStdString()); } #endif } @@ -689,3 +690,34 @@ void MainGUIWindow::on_unlink_button_clicked() cf_linker->unlink_selection(); #endif } + +void MainGUIWindow::on_save_in_DB_button_clicked() +{ + // we need to update and then save? +} + +void MainGUIWindow::on_load_from_DB_button_clicked() +{ + // need to reload and then read? + CMRead getDBCall; + _rosNodeThread->m_read_db_client.waitForExistence(ros::Duration(-1)); + if(_rosNodeThread->m_read_db_client.call(getDBCall)) + { + m_data_base = getDBCall.response.crazyflieDB; + ROS_INFO_STREAM("database:\n" << m_data_base); + // TODO: update links table + cf_linker->clear_all_links(); + for(int i = 0; i < m_data_base.crazyflieEntries.size(); i++) + { + std::string cf_name = m_data_base.crazyflieEntries[i].crazyflieContext.crazyflieName; + int cf_zone_index = m_data_base.crazyflieEntries[i].crazyflieContext.localArea.crazyfly_zone_index; + // we should first create the cf zones that are in the database? + int student_id = m_data_base.crazyflieEntries[i].studentID; + cf_linker->link(student_id, cf_zone_index, cf_name); + } + } + else + { + ROS_ERROR("Failed to read DB"); + } +} diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui index 5310f5690d00b25947312a836fa095031d79c37b..0aed3657776ddcda956755965c466f4f76c2ea08 100755 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>866</width> - <height>587</height> + <height>663</height> </rect> </property> <property name="windowTitle"> @@ -258,8 +258,8 @@ <string>Links</string> </attribute> <layout class="QGridLayout" name="gridLayout"> - <item row="12" column="1" colspan="2"> - <widget class="QLabel" name="err_message_cf_zone"> + <item row="5" column="1" colspan="6"> + <widget class="QLabel" name="err_message_student_id"> <property name="font"> <font> <pointsize>7</pointsize> @@ -270,8 +270,8 @@ </property> </widget> </item> - <item row="9" column="1" colspan="2"> - <widget class="QLabel" name="err_message_cf"> + <item row="12" column="1" colspan="6"> + <widget class="QLabel" name="err_message_cf_zone"> <property name="font"> <font> <pointsize>7</pointsize> @@ -282,8 +282,8 @@ </property> </widget> </item> - <item row="5" column="1" colspan="2"> - <widget class="QLabel" name="err_message_student_id"> + <item row="9" column="1" colspan="6"> + <widget class="QLabel" name="err_message_cf"> <property name="font"> <font> <pointsize>7</pointsize> @@ -323,6 +323,12 @@ </property> </widget> </item> + <item row="11" column="1"> + <widget class="QComboBox" name="comboBoxCFZones"/> + </item> + <item row="8" column="1"> + <widget class="QComboBox" name="comboBoxCFs"/> + </item> <item row="3" column="1"> <widget class="QLabel" name="label_4"> <property name="text"> @@ -330,12 +336,6 @@ </property> </widget> </item> - <item row="8" column="1"> - <widget class="QComboBox" name="comboBoxCFs"/> - </item> - <item row="11" column="1"> - <widget class="QComboBox" name="comboBoxCFZones"/> - </item> <item row="6" column="1"> <widget class="QLabel" name="label_2"> <property name="text"> @@ -350,28 +350,21 @@ </property> </widget> </item> - <item row="8" column="2"> + <item row="8" column="6"> <widget class="QPushButton" name="refresh_cfs_button"> <property name="text"> <string>Refresh CFs</string> </property> </widget> </item> - <item row="2" column="2"> + <item row="2" column="6"> <widget class="QPushButton" name="refresh_student_ids_button"> <property name="text"> <string>Refresh IDs</string> </property> </widget> </item> - <item row="11" column="2"> - <widget class="QPushButton" name="link_button"> - <property name="text"> - <string>Link!</string> - </property> - </widget> - </item> - <item row="13" column="1" colspan="2"> + <item row="13" column="1" colspan="6"> <widget class="QTableWidget" name="table_links"> <property name="minimumSize"> <size> @@ -393,13 +386,34 @@ </attribute> </widget> </item> - <item row="14" column="2"> + <item row="11" column="6"> + <widget class="QPushButton" name="link_button"> + <property name="text"> + <string>Link!</string> + </property> + </widget> + </item> + <item row="15" column="6"> <widget class="QPushButton" name="unlink_button"> <property name="text"> <string>Unlink!</string> </property> </widget> </item> + <item row="17" column="6"> + <widget class="QPushButton" name="save_in_DB_button"> + <property name="text"> + <string>Save in DB</string> + </property> + </widget> + </item> + <item row="16" column="6"> + <widget class="QPushButton" name="load_from_DB_button"> + <property name="text"> + <string>Load from DB</string> + </property> + </widget> + </item> </layout> </widget> </widget> diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/rosNodeThread.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/rosNodeThread.cpp index 557211176c8080fb55a1a973b3adfb8b88abe6aa..157b5f84fceb719c3fd9729539f65383d5c1d6ab 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/rosNodeThread.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/rosNodeThread.cpp @@ -1,5 +1,7 @@ #include "rosNodeThread.h" +#include "d_fall_pps/CMRead.h" + rosNodeThread::rosNodeThread(int argc, char** pArgv, const char * topic, QObject* parent) : QObject(parent), @@ -37,9 +39,11 @@ bool rosNodeThread::init() ros::Time::init(); ros::NodeHandle nh("~"); - // sim_velocity = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 100); m_vicon_subscriber = nh.subscribe(m_topic, 100, &rosNodeThread::messageCallback, this); + // clients for db services: + m_read_db_client = nh.serviceClient<CMRead>("/CentralManagerService/Read", false); + m_pThread->start(); return true; } // set up the thread diff --git a/pps_ws/src/d_fall_pps/msg/AreaBounds.msg b/pps_ws/src/d_fall_pps/msg/AreaBounds.msg index 4230649fcaf859ca7391a10e637bbf1a255bbc01..b367b15d881e07d6863e968894758df1abbdb421 100755 --- a/pps_ws/src/d_fall_pps/msg/AreaBounds.msg +++ b/pps_ws/src/d_fall_pps/msg/AreaBounds.msg @@ -1,3 +1,4 @@ +uint32 crazyfly_zone_index float32 xmin float32 xmax float32 ymin