Commit 6e29ce67 authored by roangel's avatar roangel
Browse files

already reading DB. Problem: what do we do with the data? We should create the...

already reading DB. Problem: what do we do with the data? We should create the necessary crazyfly zones, in the exact position?
parent 81d608a4
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones); explicit CFLinker(Ui::MainGUIWindow* ui, std::vector<crazyFly*> *crazyflies_vector, std::vector<crazyFlyZone*> *crazyfly_zones);
~CFLinker(); ~CFLinker();
void link(); void link(int student_id, int cf_zone_index, std::string cf_name);
void unlink_selection(); void unlink_selection();
void unlink_cf_zone(int cf_zone_index); void unlink_cf_zone(int cf_zone_index);
...@@ -37,6 +37,8 @@ public: ...@@ -37,6 +37,8 @@ public:
int getCFZoneIndexFromName(QString name); int getCFZoneIndexFromName(QString name);
int getCFIndexFromName(std::string name); int getCFIndexFromName(std::string name);
void clear_all_links();
signals: signals:
void updateComboBoxes(); void updateComboBoxes();
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
#include "marker.h" #include "marker.h"
#include "crazyFly.h" #include "crazyFly.h"
#include "CFLinker.h" #include "CFLinker.h"
#include "d_fall_pps/CrazyflieDB.h"
using namespace d_fall_pps;
#endif #endif
...@@ -99,6 +104,10 @@ private slots: ...@@ -99,6 +104,10 @@ private slots:
void on_checkBox_vicon_highlight_markers_toggled(bool checked); 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 #ifdef CATKIN_MAKE
void updateNewViconData(const ptrToMessage& p_msg); void updateNewViconData(const ptrToMessage& p_msg);
#endif #endif
...@@ -138,6 +147,7 @@ private: ...@@ -138,6 +147,7 @@ private:
int getTabIndexFromName(QString name); int getTabIndexFromName(QString name);
CrazyflieDB m_data_base;
}; };
......
...@@ -33,6 +33,8 @@ public: ...@@ -33,6 +33,8 @@ public:
// void messageCallback(const ViconData& data); // void messageCallback(const ViconData& data);
void messageCallback(const ptrToMessage& p_msg); void messageCallback(const ptrToMessage& p_msg);
ros::ServiceClient m_read_db_client;
signals: signals:
......
...@@ -91,20 +91,20 @@ void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_ ...@@ -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); 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); m_ui->table_links->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
struct link tmp_link; struct link tmp_link;
tmp_link.student_id = m_ui->spinBox_student_ids->value(); tmp_link.student_id = student_id;
tmp_link.cf_zone_index = getCFZoneIndexFromName(m_ui->comboBoxCFZones->currentText()); tmp_link.cf_zone_index = cf_zone_index;
tmp_link.cf_name = m_ui->comboBoxCFs->currentText().toStdString(); tmp_link.cf_name = cf_name;
ROS_INFO("tmp_link.cf_zone_index %d", tmp_link.cf_zone_index); 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()); 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_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_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); addNewRow(m_ui->spinBox_student_ids->value(), tmp_link.cf_name, tmp_link.cf_zone_index);
...@@ -123,6 +123,13 @@ void CFLinker::link() ...@@ -123,6 +123,13 @@ void CFLinker::link()
// ui->comboBox->setItemData(index, 33, Qt::UserRole - 1); // 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) void CFLinker::unlink_cf_zone(int cf_zone_index)
{ {
for(int i = 0; i < links.size(); i++) for(int i = 0; i < links.size(); i++)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#ifdef CATKIN_MAKE #ifdef CATKIN_MAKE
#include "d_fall_pps/UnlabeledMarker.h" #include "d_fall_pps/UnlabeledMarker.h"
#include "d_fall_pps/CMRead.h"
#endif #endif
#include <string> #include <string>
...@@ -678,7 +679,7 @@ void MainGUIWindow::on_link_button_clicked() ...@@ -678,7 +679,7 @@ void MainGUIWindow::on_link_button_clicked()
if(!error) if(!error)
{ {
cf_linker->link(); cf_linker->link(ui->spinBox_student_ids->value(), cf_linker->getCFZoneIndexFromName(ui->comboBoxCFZones->currentText()), ui->comboBoxCFs->currentText().toStdString());
} }
#endif #endif
} }
...@@ -689,3 +690,34 @@ void MainGUIWindow::on_unlink_button_clicked() ...@@ -689,3 +690,34 @@ void MainGUIWindow::on_unlink_button_clicked()
cf_linker->unlink_selection(); cf_linker->unlink_selection();
#endif #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");
}
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>866</width> <width>866</width>
<height>587</height> <height>663</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -258,8 +258,8 @@ ...@@ -258,8 +258,8 @@
<string>Links</string> <string>Links</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="12" column="1" colspan="2"> <item row="5" column="1" colspan="6">
<widget class="QLabel" name="err_message_cf_zone"> <widget class="QLabel" name="err_message_student_id">
<property name="font"> <property name="font">
<font> <font>
<pointsize>7</pointsize> <pointsize>7</pointsize>
...@@ -270,8 +270,8 @@ ...@@ -270,8 +270,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1" colspan="2"> <item row="12" column="1" colspan="6">
<widget class="QLabel" name="err_message_cf"> <widget class="QLabel" name="err_message_cf_zone">
<property name="font"> <property name="font">
<font> <font>
<pointsize>7</pointsize> <pointsize>7</pointsize>
...@@ -282,8 +282,8 @@ ...@@ -282,8 +282,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1" colspan="2"> <item row="9" column="1" colspan="6">
<widget class="QLabel" name="err_message_student_id"> <widget class="QLabel" name="err_message_cf">
<property name="font"> <property name="font">
<font> <font>
<pointsize>7</pointsize> <pointsize>7</pointsize>
...@@ -323,6 +323,12 @@ ...@@ -323,6 +323,12 @@
</property> </property>
</widget> </widget>
</item> </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"> <item row="3" column="1">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
...@@ -330,12 +336,6 @@ ...@@ -330,12 +336,6 @@
</property> </property>
</widget> </widget>
</item> </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"> <item row="6" column="1">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
...@@ -350,28 +350,21 @@ ...@@ -350,28 +350,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="2"> <item row="8" column="6">
<widget class="QPushButton" name="refresh_cfs_button"> <widget class="QPushButton" name="refresh_cfs_button">
<property name="text"> <property name="text">
<string>Refresh CFs</string> <string>Refresh CFs</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="6">
<widget class="QPushButton" name="refresh_student_ids_button"> <widget class="QPushButton" name="refresh_student_ids_button">
<property name="text"> <property name="text">
<string>Refresh IDs</string> <string>Refresh IDs</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="2"> <item row="13" column="1" colspan="6">
<widget class="QPushButton" name="link_button">
<property name="text">
<string>Link!</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="2">
<widget class="QTableWidget" name="table_links"> <widget class="QTableWidget" name="table_links">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
...@@ -393,13 +386,34 @@ ...@@ -393,13 +386,34 @@
</attribute> </attribute>
</widget> </widget>
</item> </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"> <widget class="QPushButton" name="unlink_button">
<property name="text"> <property name="text">
<string>Unlink!</string> <string>Unlink!</string>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</widget> </widget>
......
#include "rosNodeThread.h" #include "rosNodeThread.h"
#include "d_fall_pps/CMRead.h"
rosNodeThread::rosNodeThread(int argc, char** pArgv, const char * topic, QObject* parent) rosNodeThread::rosNodeThread(int argc, char** pArgv, const char * topic, QObject* parent)
: QObject(parent), : QObject(parent),
...@@ -37,9 +39,11 @@ bool rosNodeThread::init() ...@@ -37,9 +39,11 @@ bool rosNodeThread::init()
ros::Time::init(); ros::Time::init();
ros::NodeHandle nh("~"); ros::NodeHandle nh("~");
// sim_velocity = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 100);
m_vicon_subscriber = nh.subscribe(m_topic, 100, &rosNodeThread::messageCallback, this); 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(); m_pThread->start();
return true; return true;
} // set up the thread } // set up the thread
......
uint32 crazyfly_zone_index
float32 xmin float32 xmin
float32 xmax float32 xmax
float32 ymin float32 ymin
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment