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:
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();
......
......@@ -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;
};
......
......@@ -33,6 +33,8 @@ public:
// void messageCallback(const ViconData& data);
void messageCallback(const ptrToMessage& p_msg);
ros::ServiceClient m_read_db_client;
signals:
......
......@@ -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++)
......
......@@ -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");
}
}
......@@ -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>
......
#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
......
uint32 crazyfly_zone_index
float32 xmin
float32 xmax
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