Commit d3491fa6 authored by roangel's avatar roangel
Browse files

first time getting GUI connected to ROS via new thread

parent fd9a13f7
cmake_minimum_required(VERSION 2.8.3)
project(d_fall_pps)
# GUI -- CMakeLists.txt
include(${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/CMakeLists.txt)
## Add support for C++11, supported in ROS Kinetic and newer
# add_definitions(-std=c++11)
......@@ -19,14 +15,47 @@ find_package(catkin REQUIRED COMPONENTS
genmsg
)
# GUI -- Add precompiler definitions to include ROS things in GUI compilation
add_definitions(-DCATKIN_MAKE)
# GUI -- Things needed for Qt wrapper build process
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
# GUI -- Add Qt support
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
# GUI -- Add src and includes
set(MY_LIB_PATH_SRC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/src)
set(MY_LIB_PATH_INC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/include)
# #set the default path for built executables to the "bin" directory
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# #set the default path for built libraries to the "lib" directory
# set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
# GUI -- need c++11 for some things
add_definitions(-std=c++11)
# GUI -- Special Qt sources that need to be wrapped before being compiled
# they have the Qt macro QOBJECT inside, the MOC cpp file needs to be done manually
set(SRC_HDRS_QOBJECT
${MY_LIB_PATH_INC}/crazyFlyZoneTab.h
${MY_LIB_PATH_INC}/myGraphicsScene.h
${MY_LIB_PATH_INC}/myGraphicsView.h
${MY_LIB_PATH_INC}/mainguiwindow.h
${MY_LIB_PATH_INC}/rosNodeThread.h
)
# GUI -- wrap UI file and QOBJECT files
qt5_wrap_ui(UIS_HDRS GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui)
qt5_wrap_cpp(SRC_MOC_HDRS ${SRC_HDRS_QOBJECT})
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
......@@ -150,6 +179,7 @@ catkin_package(
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
${MY_LIB_PATH_INC} # GUI -- include directory inside GUI folder
${catkin_INCLUDE_DIRS}
include
)
......@@ -174,11 +204,38 @@ add_executable(SafeControllerService src/SafeControllerService.cpp)
add_executable(CentralManagerService src/CentralManagerService.cpp)
# GUI -- add sources here
set(MY_CPP_SOURCES # compilation of sources
${MY_LIB_PATH_SRC}/mainguiwindow.cpp
${MY_LIB_PATH_SRC}/main.cpp
${MY_LIB_PATH_SRC}/cornergrabber.cpp
${MY_LIB_PATH_SRC}/crazyFlyZone.cpp
${MY_LIB_PATH_SRC}/crazyFlyZoneTab.cpp
${MY_LIB_PATH_SRC}/myGraphicsRectItem.cpp
${MY_LIB_PATH_SRC}/myGraphicsScene.cpp
${MY_LIB_PATH_SRC}/myGraphicsView.cpp
${MY_LIB_PATH_SRC}/tablePiece.cpp
${MY_LIB_PATH_SRC}/marker.cpp
${MY_LIB_PATH_SRC}/rosNodeThread.cpp
)
# GUI -- add executables here
add_executable(my_GUI ${MY_CPP_SOURCES} ${UIS_HDRS} ${SRC_MOC_HDRS})
qt5_use_modules(my_GUI Widgets)
add_dependencies(ViconDataPublisher d_fall_pps_generate_messages_cpp ${catkin_EXPORTED_TARGETS})
add_dependencies(PPSClient d_fall_pps_generate_messages_cpp ${catkin_EXPORTED_TARGETS})
add_dependencies(SafeControllerService d_fall_pps_generate_messages_cpp ${catkin_EXPORTED_TARGETS})
add_dependencies(CentralManagerService d_fall_pps_generate_messages_cpp ${catkin_EXPORTED_TARGETS})
add_dependencies(my_GUI d_fall_pps_generate_messages_cpp ${catkin_EXPORTED_TARGETS})
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
......@@ -206,6 +263,17 @@ target_link_libraries(SafeControllerService ${catkin_LIBRARIES})
target_link_libraries(CentralManagerService ${catkin_LIBRARIES})
# # GUI -- add libraries
# add_library(my_library ${MY_LIB_SOURCES})
# GUI -- link libraries
target_link_libraries(my_GUI Qt5::Widgets) # GUI -- let my_GUI have acesss to Qt stuff
# target_link_libraries(my_library Qt5::Widgets) # GUI -- let my_library have access to Qt stuff
# target_link_libraries(my_GUI my_library)
target_link_libraries(my_GUI ${catkin_LIBRARIES})
#############
## Install ##
#############
......
......@@ -46,6 +46,7 @@ set(SRC_HDRS_QOBJECT
${MY_LIB_PATH_INC}/myGraphicsScene.h
${MY_LIB_PATH_INC}/myGraphicsView.h
${MY_LIB_PATH_INC}/mainguiwindow.h
${MY_LIB_PATH_INC}/rosNodeThread.h
)
# GUI -- wrap UI file and QOBJECT files
......@@ -173,14 +174,10 @@ include_directories(
# add_executable(${PROJECT_NAME}_node src/d_fall_gui_node.cpp)
# Add executables here
add_executable(my_GUI GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp GUI_Qt/CrazyFlyGUI/src/main.cpp ${UIS_HDRS} ${SRC_HDRS_QOBJECT})
qt5_use_modules(my_GUI Widgets)
# Add sources here
set(MY_LIB_SOURCES # compilation of sources
set(MY_CPP_SOURCES # compilation of sources
${MY_LIB_PATH_SRC}/mainguiwindow.cpp
${MY_LIB_PATH_SRC}/main.cpp
${MY_LIB_PATH_SRC}/cornergrabber.cpp
${MY_LIB_PATH_SRC}/crazyFlyZone.cpp
${MY_LIB_PATH_SRC}/crazyFlyZoneTab.cpp
......@@ -189,16 +186,25 @@ set(MY_LIB_SOURCES # compilation of sources
${MY_LIB_PATH_SRC}/myGraphicsView.cpp
${MY_LIB_PATH_SRC}/tablePiece.cpp
${MY_LIB_PATH_SRC}/marker.cpp
${MY_LIB_PATH_SRC}/rosNodeThread.cpp
)
# Add libraries
add_library(my_library ${MY_LIB_SOURCES})
# Add executables here
add_executable(my_GUI ${MY_CPP_SOURCES} ${UIS_HDRS} ${SRC_MOC_HDRS})
qt5_use_modules(my_GUI Widgets)
# # Add libraries
# add_library(my_library ${MY_CPP_SOURCES})
# Link libraries
target_link_libraries(my_GUI Qt5::Widgets) # let my_GUI have acesss to Qt stuff
target_link_libraries(my_library Qt5::Widgets) # let my_library have access to Qt stuff
target_link_libraries(my_GUI my_library)
# target_link_libraries(my_library Qt5::Widgets) # let my_library have access to Qt stuff
# target_link_libraries(my_GUI my_library)
target_link_libraries(my_GUI ${catkin_LIBRARIES})
## Rename C++ executable without prefix
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2017-04-20T13:52:03. -->
<!-- Written by QtCreator 4.0.2, 2017-04-27T17:56:07. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......@@ -66,7 +66,7 @@
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_gui/GUI_Qt/build-CrazyFlyGUI-Desktop_Qt_5_7_0_GCC_64bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_pps/GUI_Qt/build-CrazyFlyGUI-Desktop_Qt_5_7_0_GCC_64bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
......@@ -303,14 +303,14 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">CrazyFlyGUI</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_gui/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">CrazyFlyGUI2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro</value>
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">CrazyFlyGUI.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_gui/GUI_Qt/build-CrazyFlyGUI-Desktop_Qt_5_7_0_GCC_64bit-Debug</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/gazebo-cf/work/D-FaLL-System/pps_ws/src/d_fall_pps/GUI_Qt/build-CrazyFlyGUI-Desktop_Qt_5_7_0_GCC_64bit-Debug</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
......
......@@ -8,9 +8,7 @@
#include <QGraphicsRectItem>
#ifdef CATKIN_MAKE
#include "ros/callback_queue.h"
#include "ros/ros.h"
#include "d_fall_pps/ViconData.h"
#include "rosNodeThread.h"
#endif
#include "ui_mainguiwindow.h"
......@@ -62,11 +60,8 @@ class MainGUIWindow : public QMainWindow
Q_OBJECT
public:
#ifdef CATKIN_MAKE
explicit MainGUIWindow(ros::NodeHandle* pNodeHandle, QWidget *parent = 0);
#else
explicit MainGUIWindow(QWidget *parent = 0);
#endif
explicit MainGUIWindow(int argc, char **argv, QWidget *parent = 0);
~MainGUIWindow();
public slots:
......@@ -111,9 +106,7 @@ private:
Marker* marker;
#ifdef CATKIN_MAKE
ros::NodeHandle* _pNodeHandle;
ros::Subscriber* ViconSubscriber;
rosNodeThread _rosNodeThread;
#endif
};
......
#ifndef ___ROSNODETHREAD_H___
#define ___ROSNODETHREAD_H___
#include <QtCore>
#include <QThread>
#include <QStringList>
#include <stdlib.h>
#include <QMutex>
#include <iostream>
#include "assert.h"
#include <ros/ros.h>
#include <ros/network.h>
#include "d_fall_pps/ViconData.h"
using namespace d_fall_pps;
class rosNodeThread : public QObject {
Q_OBJECT
public:
rosNodeThread(int argc, char **pArgv, const char * topic);
virtual ~rosNodeThread();
bool init();
void messageCallback(const ViconData& data);
Q_SLOT void run();
// Q_SIGNAL void newPose(double,double,double);
private:
int m_Init_argc;
char** m_pInit_argv;
const char * m_topic;
QThread * m_pThread;
ros::Subscriber test;
// ros::Publisher sim_velocity;
};
#endif
......@@ -2,34 +2,11 @@
#include "ui_mainguiwindow.h"
#include <QApplication>
#ifdef CATKIN_MAKE
#endif
#ifdef CATKIN_MAKE
using namespace d_fall_pps;
#endif
int main(int argc, char *argv[])
{
#ifdef CATKIN_MAKE
ros::init(argc, argv, "GUI");
ros::NodeHandle nodeHandle("~");
#endif
QApplication applicationGUI(argc, argv);
#ifdef CATKIN_MAKE
MainGUIWindow mainWindow(&nodeHandle);
#else
MainGUIWindow mainWindow;
#endif
MainGUIWindow mainWindow(argc, argv);
mainWindow.show();
applicationGUI.exec();
#ifdef CATKIN_MAKE
ROS_WARN("GUI application terminated");
#endif
}
......@@ -11,43 +11,20 @@
#include <string>
#ifdef CATKIN_MAKE
#define N_MAX_CRAZYFLIES 20 // protection number
using namespace d_fall_pps;
void viconCallback(const ViconData& data)
{
ROS_INFO("in viconCallback");
qDebug("in viconCallback");
}
#endif
#define N_MAX_CRAZYFLIES 20 // protection number
#ifdef CATKIN_MAKE
MainGUIWindow::MainGUIWindow(ros::NodeHandle* pNodeHandle, QWidget *parent) :
MainGUIWindow::MainGUIWindow(int argc, char **argv, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainGUIWindow),
_pNodeHandle(pNodeHandle)
{
ui->setupUi(this);
_init();
}
#else
MainGUIWindow::MainGUIWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainGUIWindow)
_rosNodeThread(argc, argv, "/ViconDataPublisher/ViconData")
{
ui->setupUi(this);
_init();
}
#endif
MainGUIWindow::~MainGUIWindow()
{
......@@ -69,12 +46,12 @@ void MainGUIWindow::set_tabs(int n)
void MainGUIWindow::_init()
{
sleep(1000);
#ifdef CATKIN_MAKE
ViconSubscriber = new ros::Subscriber(_pNodeHandle->subscribe("/ViconDataPublisher/ViconData", 1, viconCallback));
ROS_INFO("successfully subscribed to ViconData from GUI");
qDebug("successfully subscribed to ViconData from GUI");
#endif
// #ifdef CATKIN_MAKE
// ViconSubscriber = new ros::Subscriber(_pNodeHandle->subscribe("/ViconDataPublisher/ViconData", 1, viconCallback));
// ros::spin();
// ROS_INFO("successfully subscribed to ViconData from GUI");
// qDebug("successfully subscribed to ViconData from GUI");
// #endif
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
......@@ -94,12 +71,9 @@ void MainGUIWindow::_init()
QObject::connect(scene, SIGNAL(numTablePiecesChanged(int)), this, SLOT(handleTablePiecesNumChanged(int)));
ui->checkBox_vicon_highlight_markers->setEnabled(false);
}
#ifndef CATKIN_MAKE
#endif
_rosNodeThread.init();
}
......
#include "rosNodeThread.h"
rosNodeThread::rosNodeThread(int argc, char** pArgv, const char * topic)
: m_Init_argc(argc),
m_pInit_argv(pArgv),
m_topic(topic)
{
/** Constructor for the robot thread **/
}
rosNodeThread::~rosNodeThread()
{
if (ros::isStarted())
{
ros::shutdown();
ros::waitForShutdown();
}//end if
m_pThread->wait();
}//end destructor
bool rosNodeThread::init()
{
m_pThread = new QThread();
this->moveToThread(m_pThread); // QObject method
connect(m_pThread, &QThread::started, this, &rosNodeThread::run);
ros::init(m_Init_argc, m_pInit_argv, "GUI"); // GUI is the name of this node
if (!ros::master::check())
return false; // do not start without ros.
ros::start();
ros::Time::init();
ros::NodeHandle nh("~");
// sim_velocity = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 100);
test = nh.subscribe(m_topic, 10, &rosNodeThread::messageCallback, this);
m_pThread->start();
return true;
} // set up the thread
void rosNodeThread::messageCallback(const ViconData& data) // When a message arrives to the topic, this callback is executed
{
QMutex * pMutex = new QMutex();
pMutex->lock();
// m_xPos = msg.pose.pose.position.x;
// m_yPos = msg.pose.pose.position.y;
// m_aPos = msg.pose.pose.orientation.w;
pMutex->unlock();
ROS_INFO("in viconCallback");
qDebug("in viconCallback");
delete pMutex;
// Q_EMIT newPose(m_xPos, m_yPos, m_aPos);
}
void rosNodeThread::run()
{
ros::Rate loop_rate(100);
QMutex * pMutex;
while (ros::ok())
{
pMutex = new QMutex();
// geometry_msgs::Twist cmd_msg;
pMutex->lock();
// cmd_msg.linear.x = m_speed;
// cmd_msg.angular.z = m_angle;
pMutex->unlock();
// sim_velocity.publish(cmd_msg);
ros::spinOnce();
loop_rate.sleep();
delete pMutex;
} // do ros things.
}
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