Commit 36277d0e authored by Philippe Gaussier's avatar Philippe Gaussier
Browse files

Program to communicate with the drone

parent 4a982eed
Pipeline #1262 failed with stage
in 3 minutes and 20 seconds
# Root Cmake. Use to link the different libraries
#
# @author sylvain Colomer, P. Gaussier
# @version 1.0
#########################################################################################################
### GENERAL CONFIG ##
#########################################################################################################
message("%%% PROJECT DRONE-FLY-MONITOR")
message("\n%% GENERAL CONFIGURATION")
# GENERAL SETTINGS
project(PixhawkProject CXX)
cmake_minimum_required(VERSION 3.2)
set(VERSION 1.0.0)
# OUTPUT DIR SETTINGS
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# COMPILER OPTIONS
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_DEBUG " -g3 -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE " -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wextra") # Warning : option are important for some lib
########################################################################################################
### LIBRARY CONFIG ##
########################################################################################################
message("\n%% EXTERNALS libs configuration")
message("- Checking : pkg")
find_package(PkgConfig REQUIRED)
if(PkgConfig_FOUND)
message("-> succes " )
endif()
message("- Checking : mavlink")
if(EXISTS ${CMAKE_SOURCE_DIR}/lib/mavlink)
message("-> succes " )
else()
message("Fail: You must install mavlink")
endif()
set(MAVLINK_LIB -I/lib/mavlink)
include_directories(./lib/mavlink)
message("- Checking : Loguru")
if(EXISTS ${CMAKE_SOURCE_DIR}/lib/loguru)
message("-> succes " )
else()
message("Fail: You must add loguru log system in lib folder")
endif()
include_directories(./lib/loguru)
message("- Checking : Blc channels")
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
include_directories( ${BL_INCLUDE_DIRS} )
add_definitions( ${BL_DEFINITIONS} )
message("- Checking : Thread")
find_package(Threads)
message("- Checking : Curses")
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
######################################################################################################
### LINKS ##
######################################################################################################
link_libraries(
${BL_LIBRARIES}
${MAVLINK_LIB}
${CURSES_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
dl
panel
ncurses
)
######################################################################################################
### APPLICATION ##
######################################################################################################
message("\n%% APPLICATION GENERATION")
# %% APP 1
add_executable(
mavlink_server
src/MainApp.cpp
src/Display_MainFrame.cpp
src/Display_Panel.cpp
src/Com_SerialPort.cpp
src/Com_WifiPort.cpp
src/Thread_SerialPort.cpp
src/Engine_mainLoop.cpp
src/DataListener_Keyboard.cpp
src/Com_Mavlink.cpp
src/Data_Bus.cpp
src/Data_Drone.cpp
src/Abstract_ThreadClass.cpp
lib/loguru/loguru.cpp
)
# Root Cmake. Use to link the different libraries
#
# @author sylvain Colomer, P. Gaussier
# @version 1.0
#########################################################################################################
### GENERAL CONFIG ##
#########################################################################################################
message("%%% PROJECT DRONE-FLY-MONITOR")
message("\n%% GENERAL CONFIGURATION")
# GENERAL SETTINGS
project(PixhawkProject CXX)
cmake_minimum_required(VERSION 3.2)
set(VERSION 1.0.0)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
# OUTPUT DIR SETTINGS
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# COMPILER OPTIONS
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_DEBUG " -g3 -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE " -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ")
#########################################################################################################
### EXTERNAL LIBS ##
#########################################################################################################libncurses5-dev
message("\n%% EXTERNALS libs configuration")
message("- Checking : pkg")
find_package(PkgConfig REQUIRED)
if(PkgConfig_FOUND)
message("-> succes " )
endif()
message("- Checking : mavlink")
if(EXISTS ${CMAKE_SOURCE_DIR}/lib/mavlink)
set(MAVLINK_LIB -I/lib/mavlink)
message("-> succes " )
else()
message("You must install mavlink")
endif()
message("- Checking : Curses")
find_package(Curses REQUIRED)
message("- Checking : GTK3")
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
message("- Checking : Blc channels")
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
# SDL configuration
find_package(SDL2 REQUIRED)
set(SDL2_LIB_TTF SDL2_ttf)
#########################################################################################################
### EXE GENERATION ##
#########################################################################################################
message("\n%% EXE GENERATION")
# Global adding
add_definitions(
${BL_DEFINITIONS}
# ${GTK3_CFLAGS_OTHER}
-Wall -W
-lpthread
-lncurses
)
include_directories(
./pixhawk_library/include
./lib/mavlink
${BL_INCLUDE_DIRS}
${CURSES_INCLUDE_DIR}
${SDL2_INCLUDE_DIRS}
${GTK3_INCLUDE_DIRS}
)
link_directories(
${GTK3_LIBRARY_DIRS}
)
link_libraries(
${BL_LIBRARIES}
${MAVLINK_LIB}
${CURSES_LIBRARIES}
${SDL2_LIBRARIES}
${SDL2_LIB_TTF}
${GTK3_LIBRARIES}
)
add_definitions(
${GTK3_CFLAGS_OTHER}
)
#%% APP 1
add_executable(
pixhawkServer
pixhawk_server/src/PixhawkServer.cpp pixhawk_server/include/PixhawkServer.h
pixhawk_server/src/Data_Drone.cpp pixhawk_server/include/Data_Drone.h
pixhawk_server/src/Display_IHM.cpp pixhawk_server/include/Display_IHM.h
pixhawk_server/src/Com_SerialReadingThread.cpp pixhawk_server/include/Com_SerialReadingThread.h
pixhawk_server/src/Com_SerialWritingThread.cpp pixhawk_server/include/Com_SerialWritingThread.h
pixhawk_library/src/Com_Serial.cpp
pixhawk_library/src/Abstract_ThreadClass.cpp
pixhawk_library/src/Tools_SDL2.cpp
)
# Test trajectory launch
add_executable(TestDrone
pixhawk_server/test/TestDroneRemoteControl.cpp pixhawk_server/include/PixhawkServer.h
pixhawk_server/src/Data_Drone.cpp pixhawk_server/include/Data_Drone.h
pixhawk_server/src/Display_IHM.cpp pixhawk_server/include/Display_IHM.h
pixhawk_server/src/Com_SerialReadingThread.cpp pixhawk_server/include/Com_SerialReadingThread.h
pixhawk_server/src/Com_SerialWritingThread.cpp pixhawk_server/include/Com_SerialWritingThread.h
pixhawk_library/src/Com_Serial.cpp
pixhawk_library/src/Abstract_ThreadClass.cpp
pixhawk_library/src/Tools_SDL2.cpp
)
# Test pixhawk library
add_executable(TestNcurses
pixhawk_library/test/TestNcurses.cpp
pixhawk_library/src/Display_FrameNcurses.cpp pixhawk_library/include/Display_FrameNcurses.h
pixhawk_library/src/Abstract_ThreadClass.cpp
)
#add_executable(TestSDL2
# pixhawk_library/test/TestSDL2.cpp
# pixhawk_library/src/Display_FrameSdl.cpp pixhawk_library/include/Display_FrameSdl.h
# pixhawk_library/src/Abstract_ThreadClass.cpp
#)
# add_executable(TestGtk
# pixhawk_library/test/TestGtk.cpp
# pixhawk_library/src/Display_FrameGtk.cpp pixhawk_library/include/Display_FrameGtk.h
# pixhawk_library/src/Abstract_ThreadClass.cpp
# )
[![Awesome Badges](https://img.shields.io/badge/Laboratory-Etis-purple.svg)](https://www-etis.ensea.fr)
[![Awesome Badges](https://img.shields.io/badge/Team-Neurocyber-red.svg)](https://www-etis.ensea.fr)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](sylvain.colomer.pro@gmail.com)
# drone-controlServer #
## Introduction ##
The pixhawk service program is a simple application that allow user to communicate though Mavlink to a pixhawk flying controler. It use Blc channels, a lib to use shared memory make by a collegue, Arnaud Blanchard (See blaar lib).
## Application structure ##
The application is a C++ service use to send messages on a mavlink drone. It operation is simple :
* The drone upon ignition sends data called heartbeat
* The system watch over available drone with a DataListenerThread. It's a thread that listen data.
* If a drone is available, the system advertise user an begin to display heartbeat information
The project word in real time with multiple thread :
* Serial port thread in reading and writing
* IHM thread
* Joystick thread
* Main thread
![Image of structure application](./doc/images/program.svg)
### Language ###
C++
### Dependencies ###
This project use :
* https://promethe.u-cergy.fr/blaar/blaar -> important
* librapidxml-dev 1.13-1
* libncurses5-dev
### Organisation ###
The project is organized in different specific folders :
* bin : application exe folder
* build: cmake folder
* data : explicit
* include : all header of the application
* lib : all lib use in the project like Mavlink v2.0
* log : classic
* src : all the source file of the project
* test : unit test use by the system
## How to ? ##
# see blc_channels
cd $HOME/blaar
./run.sh gnuplot/o_gnuplot /pixhawk.control.arm
./run.sh gnuplot/o_gnuplot /pixhawk.control.motors -m-1000 -M1000
### Resolve serial port problem ?
http://tvaira.free.fr/bts-sn/activites/preparation-ccf-e52/activite-port-serie-usb.html
### Compilate the project ###
Don't lose your time with greedy IDE :P. Use Cmake in the build folder.
```
mkdir build
cd build
cmake ..
make
```
### Execute tests ###
No unitary test support was made but the system was prepared. It's only a simple option on cmake.
## Other ##
Some links are interresting to consult to contributre to this program.
* https://www.google.com/search?client=ubuntu&channel=fs&q=mavlink+mode+guided&ie=utf-8&oe=utf-8
* https://gitter.im/dronekit/dronekit-python/archives/2017/06/04
* ardupilot.org/copter/docs/common-mavlink-mission-command-messages-mav_cmd.html -> tone
* https://dev.px4.io/en/qgc/video_streaming.html
* https://dev.px4.io/en/advanced/parameter_reference.html -> pixhawk flight stack
* https://msgpack.org/ -> format
* https://capnproto.org/ -> format
* https://docs.qgroundcontrol.com/en/SetupView/Joystick.html JOYSTICK
### Wiki ###
### Author ###
Sylvain Colomer into the Laboratory Etis, University of Cergy-Pontoise
Don't hesitate to contact me trough gitLab !
/**
* @author Sylvain Colomer
* @date 17/08/18.
*/
#ifndef ABSTRACT_FRAME_H_
#define ABSTRACT_FRAME_H_
#include <iostream>
#include <string>
#include <iostream>
#include <unistd.h>
#include <termios.h>
#include <thread>
#include <mutex>
/**
* Abstract class use to contruct a common structure for display classes. Now only a prototype.
*/
class Abstract_Frame {
private:
/**
* Different important vaar about the position of created screen
*/
int screen_widht = -1;
int screen_height = -1;
int screen_x = -1;
int screen_y = -1;
public :
/**
* Default destructor
*/
virtual ~Abstract_Frame();
/**
* Default constructor of a frame. Only get user information about desired frame position and size
*/
Abstract_Frame(int screen_widht, int screen_height, int screen_x, int screen_y)
{
Abstract_Frame::screen_widht = screen_widht;
Abstract_Frame::screen_height = screen_height;
Abstract_Frame::screen_x = screen_x;
Abstract_Frame::screen_y = screen_y;
}
/**
* Function that allow to construct with the different function the classes
*/
virtual void initFrame() = 0;
/**
* Method that set the style of the Frame. Generraly use a constant classes
*/
virtual void setStyle() = 0;
/**
* Method that set the layout of the frame
*/
virtual void setLayout() = 0;
/**
* Method that add object to the principal frame
*/
virtual void setComponent() = 0;
/**
* Method that add the different action Listener to current component
*/
virtual void setAction() = 0;
/**
* Typical method that allow to display the frame
*/
virtual void buildFrame() = 0;
/**
* Typical method that allow to erase cleanly the frame
*/
virtual void eraseFrame() = 0;
};
#endif
/**
* @author Sylvain Colomer
* @date 17/08/18.
*/
#ifndef ABSTRACT_THREADCLASS_H_
#define ABSTRACT_THREADCLASS_H_
#include <iostream>
#include <string>
#include <iostream>
#include <unistd.h>
#include <termios.h>
#include <thread>
#include <mutex>
#include <functional>
#include <memory>
#include <algorithm>
#include <loguru.hpp>
#define THREAD_STATE_VOID 0 // Thread created and ready to be used
#define THREAD_STATE_READY 1 // Thread created and ready to be used
#define THREAD_STATE_WORK_TASK 2
#define THREAD_STATE_WORK_SLEEP 3
#define THREAD_STATE_WORK_DEADLINE 4
/**
* Abstract class which convey to implement a thread brick
* Use a real time context
*/
class Abstract_ThreadClass {
protected:
// REAL TIME VAR
/**
* timeval that save the begin of the running method
*/
struct timeval begin;
/**
* timeval use to control the period of the real time thread
*/
struct timeval front_checkpoint;
/**
* timeval use to control the period of the real time thread
*/
struct timeval end_checkpoint;
/**
* Represent the period between all task in ms
*/
int task_period = 1000;
/**
* Var use to define when a task is overcome is execution delay
*/
int task_deadline = 1000; //ms
// RUN VAR
/**
* Mutex of the run flag
*/
std::mutex runFlag_mutex;
/**
* Run flag : convey to loop the system
*/
volatile bool runFlag = true;
// MAIN THREAD VAR
/**
* The principal thread of the system
*/
std::thread principalThread;
/**
* State flag use to know current state of the tread
*/
int state = THREAD_STATE_VOID;
public :
/**
* Default constructor : take in parameters the task period time and the task deadline time
* @param task_period period between all task execution
* @param task_deadline alert limit use to send an alert message when the task are too long (see the notion of real time context)
*/
Abstract_ThreadClass(int task_period, int task_deadline);
/**
* Default destructor
*/
virtual ~Abstract_ThreadClass();
/**
* Method which convey to initialise the thread
* Don't overwrite it without knowledge of the method goal
*/
void init();
/**
* Start method : use it to first start the thread (only one time)
* It create the thread associated to the run method
*/
void start();
/**
* Convey to stop the thread.
*/
void stop();
/**
* Warning : bad method
*/
void stop_force();
/**
* Play method : convey to restart the thread before a first start and after a pause
*/
void play();
/**
* Pause method : convey to pause the thread without quit it
*/
void pause();
/**
* Method wich allow to join the thread
* Warning : don't double join a thread
*/
void join();
/**
* Method main loop. Implement a soft real time context
* Overwrite it to create your real time thread
*/
virtual void run() = 0;
// GETTER AND SETTERS
/**
* Only a setter
* @return
*/
bool isRunFlag();
};
#endif
/**
* @brief Tool class which convey to open a serial port
* @file serial_port.cpp
*
* @author Sylvain Colomer
* @date 19/04/19
* @version 1.1
*/
#ifndef COMM_MAVLIN_H_
#define COMM_MAVLIN_H