Commit 1072e6c8 authored by beuchatp's avatar beuchatp
Browse files

Yaml connections working (for student and demo controller), and title is now...

Yaml connections working (for student and demo controller), and title is now proper. Ready for testing on real system before cleaning up the controllers and their interface
parent 339bac5f
......@@ -325,8 +325,10 @@ add_executable(PPSClient src/nodes/PPSClient.cpp
add_executable(BatteryMonitor src/nodes/BatteryMonitor.cpp
src/classes/GetParamtersAndNamespaces.cpp)
add_executable(SafeControllerService src/nodes/SafeControllerService.cpp)
add_executable(DemoControllerService src/nodes/DemoControllerService.cpp)
add_executable(StudentControllerService src/nodes/StudentControllerService.cpp)
add_executable(DemoControllerService src/nodes/DemoControllerService.cpp
src/classes/GetParamtersAndNamespaces.cpp)
add_executable(StudentControllerService src/nodes/StudentControllerService.cpp
src/classes/GetParamtersAndNamespaces.cpp)
add_executable(MpcControllerService src/nodes/MpcControllerService.cpp)
add_executable(RemoteControllerService src/nodes/RemoteControllerService.cpp)
add_executable(TuningControllerService src/nodes/TuningControllerService.cpp)
......
// Copyright (C) 2018, ETH Zurich, D-ITET, Paul Beuchat
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// D-FaLL-System is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with D-FaLL-System. If not, see <http://www.gnu.org/licenses/>.
//
//
// ----------------------------------------------------------------------------------
// DDDD FFFFF L L SSSS Y Y SSSS TTTTT EEEEE M M
// D D F aaa L L S Y Y S T E MM MM
// D D --- FFFF a a L L --- SSS Y SSS T EEE M M M
// D D F a aa L L S Y S T E M M
// DDDD F aa a LLLL LLLL SSSS Y SSSS T EEEEE M M
//
//
// DESCRIPTION:
// The bar of the GUI for (dis-)connecting (from)to the Crazyradio
// and for sending the {take-off,land,motors-off} commands//
// ----------------------------------------------------------------------------------
#ifndef CONNECTSTARTSTOPBAR_H
#define CONNECTSTARTSTOPBAR_H
......@@ -74,9 +106,6 @@ private:
// > For the ID of this node
int m_ID = 0;
// The namespace into which node operates
std::string m_base_namespace;
// For coordinating multiple agents
std::vector<int> m_vector_of_agentIDs_toCoordinate;
bool m_shouldCoordinateAll = true;
......@@ -99,27 +128,8 @@ private:
//QMutex m_battery_voltage_lineEdit_mutex;
// > For the "battery_status_label" UI element
QMutex m_battery_status_label_mutex;
#ifdef CATKIN_MAKE
// PUBLISHERS AND SUBSRIBERS
// > For Crazyradio commands based on button clicks
ros::Publisher crazyRadioCommandPublisher;
// > For updating the "rf_status_label" picture
ros::Subscriber crazyRadioStatusSubscriber;
// > For updating the current battery voltage
ros::Subscriber batteryVoltageSubscriber;
// > For updating the current battery state
//ros::Subscriber batteryStateSubscriber;
// > For updating the current battery level
ros::Subscriber batteryLevelSubscriber;
// > For Flying state commands based on button clicks
ros::Publisher flyingStateCommandPublisher;
// > For updating the "flying_state_label" picture
ros::Subscriber flyingStateSubscriber;
#endif
// --------------------------------------------------- //
// PRIVATE FUNCTIONS
......@@ -129,22 +139,50 @@ private:
void disableFlyingStateButtons();
void enableFlyingStateButtons();
// > For updating the RF Radio status shown in the
// UI element of "rf_status_label"
// > For updating the RF Radio status shown in the UI element
// of "rf_status_label"
void setCrazyRadioStatus(int radio_status);
// > For updating the battery state
void setBatteryState(int new_battery_state);
// > For updating the battery voltage shown in the UI elements
// of "battery_voltage_lineEdit" and "battery_status_label"
void setBatteryVoltageText(float battery_voltage);
void setBatteryImageBasedOnLevel(int battery_level);
// > For updating the "my_flying_state" variable, and
// the UI element of "flying_state_label"
// > For updating the "my_flying_state" variable, and the
// UI element of "flying_state_label"
void setFlyingState(int new_flying_state);
#ifdef CATKIN_MAKE
// --------------------------------------------------- //
// PRIVATE VARIABLES FOR ROS
// PUBLISHERS AND SUBSRIBERS
// > For Crazyradio commands based on button clicks
ros::Publisher crazyRadioCommandPublisher;
// > For updating the "rf_status_label" picture
ros::Subscriber crazyRadioStatusSubscriber;
// > For updating the current battery voltage
ros::Subscriber batteryVoltageSubscriber;
// > For updating the current battery state
//ros::Subscriber batteryStateSubscriber;
// > For updating the current battery level
ros::Subscriber batteryLevelSubscriber;
// > For Flying state commands based on button clicks
ros::Publisher flyingStateCommandPublisher;
// > For updating the "flying_state_label" picture
ros::Subscriber flyingStateSubscriber;
// --------------------------------------------------- //
// PRIVATE CALLBACKS IN RESPONSE TO ROS MESSAGES
// Get the type and ID of this node
bool getTypeAndIDParameters();
// Fill the head for a message
......@@ -153,6 +191,7 @@ private:
// > For the CrazyRadio status, received on the
// "crazyRadioStatusSubscriber"
void crazyRadioStatusCallback(const std_msgs::Int32& msg);
// > For the Battery Voltage, received on the
// "batteryVoltageSubscriber"
void batteryVoltageCallback(const std_msgs::Float32& msg);
......@@ -162,6 +201,7 @@ private:
// > For the Battery Level, receieved on the
// "batteryLevelSubscriber"
void batteryLevelCallback(const std_msgs::Int32& msg);
// > For the Flying State, received on the
// "flyingStateSubscriber"
void flyingStateChangedCallback(const std_msgs::Int32& msg);
......
......@@ -57,7 +57,7 @@
#include "nodes/Constants.h"
// SPECIFY THE PACKAGE NAMESPACE
using namespace d_fall_pps;
//using namespace d_fall_pps;
#else
// Include the shared definitions
......@@ -131,21 +131,32 @@ private:
// --------------------------------------------------- //
// PRIVATE FUNCTIONS
// > For updating the RF Radio status shown in the UI element of "rf_status_label"
// > For making the "enable flight" and "disable flight" buttons
// (un-)available
void disableFlyingStateButtons();
void enableFlyingStateButtons();
// > For updating the RF Radio status shown in the UI element
// of "rf_status_label"
void setCrazyRadioStatus(int radio_status);
// > For updating the battery state
void setBatteryState(int new_battery_state);
// > For updating the battery voltage shown in the UI elements of "battery_voltage_lineEdit" and "battery_status_label"
// > For updating the battery voltage shown in the UI elements
// of "battery_voltage_lineEdit" and "battery_status_label"
void setBatteryVoltageText(float battery_voltage);
void setBatteryImageBasedOnLevel(int battery_level);
// > For making the "enable flight" and "disable flight" buttons (un-)available
void disableFlyingStateButtons();
void enableFlyingStateButtons();
// > For updating the "my_flying_state" variable, and the UI element of "flying_state_label"
// > For updating the "my_flying_state" variable, and the
// UI element of "flying_state_label"
void setFlyingState(int new_flying_state);
// > For loading the "context" for this agent, i.e., the {agentID,cfID,flying zone} tuple
// > For loading the "context" for this agent,
// i.e., the {agentID,cfID,flying zone} tuple
void loadCrazyflieContext();
// > For updating the text in the UI element of "controller_enabled_label"
// > For updating the text in the UI element of
// "controller_enabled_label"
void setControllerEnabled(int new_controller);
......@@ -154,30 +165,27 @@ private:
// --------------------------------------------------- //
// PRIVATE VARIABLES FOR ROS
// > For running this is a ROS node thread
//rosNodeThread* myrosNodeThread;
// > For the namespace of this node
std::string my_ros_namespace;
// > For the "context" of this agent
CrazyflieContext my_context;
d_fall_pps::CrazyflieContext my_context;
// PUBLISHERS AND SUBSRIBERS
// > For Crazyradio commands based on button clicks
ros::Publisher crazyRadioCommandPublisher;
// > For updating the "rf_status_label" picture
ros::Subscriber crazyRadioStatusSubscriber;
// > For updating the current battery voltage
ros::Subscriber batteryVoltageSubscriber;
// > For updating the current battery state
//ros::Subscriber batteryStateSubscriber;
// > For updating the current battery level
ros::Subscriber batteryLevelSubscriber;
// > For Flying state commands based on button clicks
ros::Publisher flyingStateCommandPublisher;
// > For updating the "flying_state_label" picture
ros::Subscriber flyingStateSubscriber;
// > For changes in the database that defines {agentID,cfID,flying zone} links
ros::Subscriber databaseChangedSubscriber;
ros::ServiceClient centralManagerDatabaseService;
......@@ -188,19 +196,30 @@ private:
// --------------------------------------------------- //
// PRIVATE CALLBACKS IN RESPONSE TO ROS MESSAGES
// > For the CrazyRadio status, received on the "crazyRadioStatusSubscriber"
// > For the CrazyRadio status, received on the
// "crazyRadioStatusSubscriber"
void crazyRadioStatusCallback(const std_msgs::Int32& msg);
// > For the Battery Voltage, received on the "batteryVoltageSubscriber"
// > For the Battery Voltage, received on the
// "batteryVoltageSubscriber"
void batteryVoltageCallback(const std_msgs::Float32& msg);
// > For the Battery State, receieved on the "batteryStateSubscriber"
// > For the Battery State, receieved on the
// "batteryStateSubscriber"
void batteryStateChangedCallback(const std_msgs::Int32& msg);
// > For the Battery Level, receieved on the "batteryLevelSubscriber"
// > For the Battery Level, receieved on the
// "batteryLevelSubscriber"
void batteryLevelCallback(const std_msgs::Int32& msg);
// > For the Flying State, received on the "flyingStateSubscriber"
// > For the Flying State, received on the
// "flyingStateSubscriber"
void flyingStateChangedCallback(const std_msgs::Int32& msg);
// > For the notification that the database was changes, received on the "DatabaseChangedSubscriber"
// > For the notification that the database was changes,
// received on the "DatabaseChangedSubscriber"
void databaseChangedCallback(const std_msgs::Int32& msg);
// > For the controller currently operating, received on "controllerUsedSubscriber"
// > For the controller currently operating, received on
// "controllerUsedSubscriber"
void controllerUsedChangedCallback(const std_msgs::Int32& msg);
......
......@@ -12,10 +12,11 @@
// Include the standard message types
#include "std_msgs/Int32.h"
#include "std_msgs/Float32.h"
//#include <std_msgs/String.h>
#include <std_msgs/String.h>
// Include the DFALL message types
#include "d_fall_pps/IntWithHeader.h"
#include "d_fall_pps/StringWithHeader.h"
// Include the DFALL service types
// #include "d_fall_pps/AreaBounds.h"
......@@ -102,14 +103,18 @@ private:
// PUBLISHERS AND SUBSRIBERS
// > For {take-off,land,motors-off} and controller selection
ros::Publisher commandPublisher;
// > For requesting the loading of yaml files
ros::Publisher m_requestLoadYamlFilenamePublisher;
#endif
// --------------------------------------------------- //
// PRIVATE FUNCTIONS
#ifdef CATKIN_MAKE
// Fill the head for a message
// Fill the header for a message
void fillIntMessageHeader( d_fall_pps::IntWithHeader & msg );
void fillStringMessageHeader( d_fall_pps::StringWithHeader & msg );
// Get the paramters that specify the type and ID
bool getTypeAndIDParameters();
......
// Copyright (C) 2017, ETH Zurich, D-ITET, Paul Beuchat
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// D-FaLL-System is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with D-FaLL-System. If not, see <http://www.gnu.org/licenses/>.
//
//
// ----------------------------------------------------------------------------------
// DDDD FFFFF L L SSSS Y Y SSSS TTTTT EEEEE M M
// D D F aaa L L S Y Y S T E MM MM
// D D --- FFFF a a L L --- SSS Y SSS T EEE M M M
// D D F a aa L L S Y S T E M M
// DDDD F aa a LLLL LLLL SSSS Y SSSS T EEEEE M M
//
//
// DESCRIPTION:
// The title displayed at the top of the GUI
//
// ----------------------------------------------------------------------------------
#ifndef TOPBANNER_H
#define TOPBANNER_H
#include <QWidget>
#ifdef CATKIN_MAKE
#include <ros/ros.h>
#include <ros/network.h>
#include <ros/package.h>
// Include the standard message types
#include "std_msgs/Int32.h"
//#include "std_msgs/Float32.h"
//#include <std_msgs/String.h>
// Include the DFALL message types
//#include "d_fall_pps/IntWithHeader.h"
#include "d_fall_pps/AreaBounds.h"
#include "d_fall_pps/CrazyflieContext.h"
#include "d_fall_pps/CMQuery.h"
// Include the shared definitions
#include "nodes/Constants.h"
// SPECIFY THE PACKAGE NAMESPACE
//using namespace d_fall_pps;
#endif
namespace Ui {
class TopBanner;
}
......@@ -16,7 +75,57 @@ public:
~TopBanner();
private:
// --------------------------------------------------- //
// PRIVATE VARIABLES
Ui::TopBanner *ui;
// > For the type of this node,
// i.e., an agent or a coordinator
int m_type = 0;
// > For the ID of this node
int m_ID = 0;
// The namespace into which node operates
std::string m_base_namespace;
// --------------------------------------------------- //
// PRIVATE FUNCTIONS
// > For loading the "context" for this agent,
// i.e., the {agentID,cfID,flying zone} tuple
void loadCrazyflieContext();
#ifdef CATKIN_MAKE
// --------------------------------------------------- //
// PRIVATE VARIABLES FOR ROS
// > For the "context" of this agent
d_fall_pps::CrazyflieContext my_context;
// PUBLISHERS AND SUBSRIBERS
// > For changes in the database that defines {agentID,cfID,flying zone} links
ros::Subscriber databaseChangedSubscriber;
ros::ServiceClient centralManagerDatabaseService;
// --------------------------------------------------- //
// PRIVATE CALLBACKS IN RESPONSE TO ROS MESSAGES
// Get the type and ID of this node
bool getTypeAndIDParameters();
// > For the notification that the database was changes,
// received on the "DatabaseChangedSubscriber"
void databaseChangedCallback(const std_msgs::Int32& msg);
#endif
};
#endif // TOPBANNER_H
......@@ -50,8 +50,8 @@ ConnectStartStopBar::ConnectStartStopBar(QWidget *parent) :
#ifdef CATKIN_MAKE
// Get the namespace of this node
std::string this_namespace = ros::this_node::getNamespace();
ROS_INFO_STREAM("[CONNECT START STOP GUI BAR] ros::this_node::getNamespace() = " << this_namespace);
std::string base_namespace = ros::this_node::getNamespace();
ROS_INFO_STREAM("[CONNECT START STOP GUI BAR] ros::this_node::getNamespace() = " << base_namespace);
// Get the type and ID of this parameter service
......@@ -98,7 +98,7 @@ ConnectStartStopBar::ConnectStartStopBar(QWidget *parent) :
#ifdef CATKIN_MAKE
// CREATE A NODE HANDLE TO THE BASE NAMESPACE
ros::NodeHandle base_nodeHandle(this_namespace);
ros::NodeHandle base_nodeHandle(base_namespace);
// CREATE A NODE HANDLE TO THE ROOT OF THE D-FaLL SYSTEM
ros::NodeHandle dfall_root_nodeHandle("/dfall");
......@@ -132,10 +132,11 @@ ConnectStartStopBar::ConnectStartStopBar(QWidget *parent) :
// FURTHER INITILIASATIONS NEED TO OCCUR AFTER THE ROS RELATED
// INITIALISATIONS ARE COMPLETE
if (m_type == TYPE_AGENT)
{
//if (m_type == TYPE_AGENT)
//{
// The loading of the "Context" is handled by the "topbanner"
//loadCrazyflieContext();
}
//}
// ADD KEYBOARD SHORTCUTS
// > For "all motors off", press the space bar
......@@ -152,17 +153,17 @@ ConnectStartStopBar::~ConnectStartStopBar()
// > For making the "enable flight" and "disable flight" buttons unavailable
void ConnectStartStopBar::disableFlyingStateButtons()
{
//ui->motors_off_button->setEnabled(true);
//ui->enable_flying_button->setEnabled(false);
//ui->disable_flying_button->setEnabled(false);
ui->motors_off_button->setEnabled(true);
ui->enable_flying_button->setEnabled(false);
ui->disable_flying_button->setEnabled(false);
}
// > For making the "enable flight" and "disable flight" buttons available
void ConnectStartStopBar::enableFlyingStateButtons()
{
//ui->motors_off_button->setEnabled(true);
//ui->enable_flying_button->setEnabled(true);
//ui->disable_flying_button->setEnabled(true);
ui->motors_off_button->setEnabled(true);
ui->enable_flying_button->setEnabled(true);
ui->disable_flying_button->setEnabled(true);
}
......@@ -473,7 +474,6 @@ void ConnectStartStopBar::setFlyingState(int new_flying_state)
case STATE_LAND:
{
//qstr.append("Land");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_disabling_pixmap(":/images/flying_state_disabling.png");
ui->flying_state_label->setPixmap(flying_state_disabling_pixmap);
......
......@@ -62,9 +62,9 @@ CoordinatorRow::CoordinatorRow(QWidget *parent, int agentID) :
m_agentID_as_string = QString::number(m_agentID).rightJustified(3, '0');
// CONVERT THE AGENT ID TO A STRING FOR THE BASE NAMESPACE
QString qstr_ros_base_namespace = "/dfall/agent";
qstr_ros_base_namespace.append(m_agentID_as_string);
std::string ros_base_namespace = qstr_ros_base_namespace.toStdString();
QString qstr_base_namespace = "/dfall/agent";
qstr_base_namespace.append(m_agentID_as_string);
std::string base_namespace = qstr_base_namespace.toStdString();
// SET THE INITIAL VALUE OF THE PRIVATE VARIABLES FOR THIS CLASS
// > For keeping track of the current battery state
......@@ -90,52 +90,43 @@ CoordinatorRow::CoordinatorRow(QWidget *parent, int agentID) :
#ifdef CATKIN_MAKE
//m_rosNodeThread = new rosNodeThread(argc, argv, "coordinatorRowGUI");
//m_rosNodeThread->init();
//m_ros_namespace = ros::this_node::getNamespace();
//qRegisterMetaType<ptrToMessage>("ptrToMessage");
//QObject::connect(m_rosNodeThread, SIGNAL(newViconData(const ptrToMessage&)), this, SLOT(updateNewViconData(const ptrToMessage&)));
//ros::NodeHandle nodeHandle(m_ros_namespace);
// communication with PPS Client, just to make it possible to communicate through terminal also we use PPSClient's name
//ros::NodeHandle nh_PPSClient(m_ros_namespace + "/PPSClient");
//ros::NodeHandle nh_PPSClient("PPSClient");
// LET THE USER KNOW WHAT THE BASE NAMESPACE IS
ROS_INFO_STREAM("[COORDINATOR ROW GUI] using base namespace: " << ros_base_namespace.c_str() << ", for agentID = " << m_agentID);
ROS_INFO_STREAM("[COORDINATOR ROW agentID:" << m_agentID << " GUI] using base namespace: " << base_namespace.c_str() << ", for agentID = " << m_agentID);
// DEBUGGING FOR NAMESPACES
//std::string temp_ros_namespace = ros::this_node::getNamespace();
//ROS_INFO_STREAM("[COORDINATOR ROW GUI] compared to: ros::this_node::getNamespace() = " << temp_ros_namespace.c_str());
// CREATE A NODE HANDLE TO THE BASE NAMESPACE
ros::NodeHandle base_nodeHandle(ros_base_namespace);
ros::NodeHandle base_nodeHandle(base_namespace);
// CREATE A NODE HANDLE TO THE ROOT OF THE D-FaLL SYSTEM
ros::NodeHandle dfall_root_nodeHandle("/dfall");
// SUBSCRIBERS AND PUBLISHERS:
// > For Crazyradio commands based on button clicks
crazyRadioCommandPublisher = base_nodeHandle.advertise<d_fall_pps::IntWithHeader>("PPSClient/crazyRadioCommand", 1);
// > For updating the "rf_status_label" picture
crazyRadioStatusSubscriber = base_nodeHandle.subscribe("CrazyRadio/CrazyRadioStatus", 1, &CoordinatorRow::crazyRadioStatusCallback, this);
// > For updating the current battery voltage
batteryVoltageSubscriber = base_nodeHandle.subscribe("BatteryMonitor/FilteredVoltage", 1, &CoordinatorRow::batteryVoltageCallback, this);
// > For updating the current battery state
//batteryStateSubscriber = base_nodeHandle.subscribe("BatteryMonitor/ChangedStateTo", 1, &CoordinatorRow::batteryStateChangedCallback, this);
// > For updating the current battery level
batteryLevelSubscriber = base_nodeHandle.subscribe("BatteryMonitor/Level", 1, &CoordinatorRow::batteryLevelCallback, this);
// > For Flying state commands based on button clicks
flyingStateCommandPublisher = base_nodeHandle.advertise<d_fall_pps::IntWithHeader>("PPSClient/Command", 1);
// > For updating the "flying_state_label" picture
flyingStateSubscriber = base_nodeHandle.subscribe("PPSClient/flyingState", 1, &CoordinatorRow::flyingStateChangedCallback, this);
// > For changes in the database that defines {agentID,cfID,flying zone} links
databaseChangedSubscriber = dfall_root_nodeHandle.subscribe("CentralManagerService/DBChanged", 1, &CoordinatorRow::databaseChangedCallback, this);;
centralManagerDatabaseService = dfall_root_nodeHandle.serviceClient<CMQuery>("CentralManagerService/Query", false);
centralManagerDatabaseService = dfall_root_nodeHandle.serviceClient<d_fall_pps::CMQuery>("CentralManagerService/Query", false);
// > For updating the controller that is currently operating
controllerUsedSubscriber = base_nodeHandle.subscribe("PPSClient/controllerUsed", 1, &CoordinatorRow::controllerUsedChangedCallback, this);
......@@ -145,9 +136,6 @@ CoordinatorRow::CoordinatorRow(QWidget *parent, int agentID) :
// INITIALISATIONS ARE COMPLETE
loadCrazyflieContext();
// FOR DEBUGGING:
//ui->shouldCoordinate_checkBox->setText(m_agentID_as_string);
//ui->shouldCoordinate_checkBox->setText(QString::fromStdString(base_namespace));
}
CoordinatorRow::~CoordinatorRow()
......@@ -546,7 +534,6 @@ void CoordinatorRow::setFlyingState(int new_flying_state)
case STATE_LAND:
{
//qstr.append("Land");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_disabling_pixmap(":/images/flying_state_disabling.png");
ui->flying_state_label->setPixmap(flying_state_disabling_pixmap);
......@@ -569,6 +556,13 @@ void CoordinatorRow::setFlyingState(int new_flying_state)
// ----------------------------------------------------------------------------------