Commit da4308a1 authored by Philippe Gaussier's avatar Philippe Gaussier
Browse files

Suppress unused files

PG.
parent c923962e
/**
* @author Sylvain Colomer
* @date 18/04/19.
*/
#include "../include/PixhawkServer.h"
std::shared_ptr<Drone> drone1;
/**
* Only the main exe of the programm
* @return
*/
int main(int argc, char *argv[]){
// General var
bool flag_run = true; //Flag use for the main loop of the system
std::string device_path = "/dev/ttyUSB0";
int device_baudrate = 57600;
std::string buffer1="";
// General object
drone1 = std::shared_ptr<Drone>(new Drone(device_path, device_baudrate));
std::shared_ptr<Serial_Port_ReadingThread> readingThread;
std::shared_ptr<Serial_Port_WritingThread> writingThread;
std::shared_ptr<Display_IHM> ihm;
readingThread = std::shared_ptr<Serial_Port_ReadingThread>(new Serial_Port_ReadingThread(500, 200, drone1));
writingThread = std::shared_ptr<Serial_Port_WritingThread>(new Serial_Port_WritingThread(500, 200, drone1));
//Display_IHM::getInstanceOf().printLog("Welcome to pixhawk server");
//Display_IHM::getInstanceOf().printLog("Init communication");
//buffer1= "-> Open "+device_path;
//Display_IHM::getInstanceOf().printLog(buffer1);
if(drone1.get()->init_communication()==0){
//Display_IHM::getInstanceOf().printLog("-> Succes");
}else{
//Display_IHM::getInstanceOf().printLog("-> Fail, exiting now");
sleep(2);
exit(1);
}
//Display_IHM::getInstanceOf().printLog("Pull parameters");
if(drone1.get()->init_parameters(10000)==0){
//Display_IHM::getInstanceOf().printLog("-> Succes");
}else{
//Display_IHM::getInstanceOf().printLog("-> Fail, exiting");
sleep(2);
exit(1);
}
// Display
//Display_IHM::getInstanceOf().displayDroneState(drone1);
//Display_IHM::getInstanceOf().displayMotorsState(drone1);
//Display_IHM::getInstanceOf().printLog("Begin");
readingThread.get()->start();
writingThread.get()->start();
while(flag_run){
command_loop();
}
readingThread.get()->stop();
writingThread.get()->stop();
return 0;
}
void command_loop()
{
mavlink_message_t message;
std::string buffer_command = "";
std::cin >> buffer_command;
if(buffer_command=="a1")
{
drone1.get()->command_arm(1);
}
else if(buffer_command=="!a1")
{
drone1.get()->command_arm(0);
}
else if(buffer_command=="k1")
{
drone1.get()->command_kill(1);
}
else if(buffer_command=="!k1")
{
drone1.get()->command_kill(0);
}
else if(buffer_command=="m1")
{
drone1.get()->command_directControl(1000,0,0,0);
}
else if(buffer_command=="m2")
{
drone1.get()->command_directControl(0,1000,0,0);
}
else if(buffer_command=="m3")
{
drone1.get()->command_directControl(0,0,1000,0);
}
else if(buffer_command=="m4")
{
drone1.get()->command_directControl(0,0,0,1000);
}
else if(buffer_command=="!m")
{
drone1.get()->command_directControl(0,0,0,0);
}
else if(buffer_command=="tone")
{
//Display_IHM::getInstanceOf().printLog("PLAY TONE");
mavlink_msg_play_tune_pack(255, drone1.get()->component_id, &message, 1, 1 , "AAAA", "");
drone1.get()->write_message(message);
}
else
{
//Display_IHM::getInstanceOf().printLog("Error: what ?");
}
//PARAM_REQUEST_READ
}
// else if(buffer_command=="1") // SET_ATTITUDE_TARGET
// {
// Display_IHM::getInstanceOf().printLog("U");
// mavlink_setAttitudeTarget(&message, *drone1.get(), 800, 0, 0, 0);
// drone1.get()->write_message(message);
// }
// else if(buffer_command=="2") // SET_ATTITUDE_TARGET
// {
// Display_IHM::getInstanceOf().printLog("");
// mavlink_setAttitudeTarget(&message, *drone1.get(), 0, 800, 0, 0);
// drone1.get()->write_message(message);
// }
// else if(buffer_command=="3") // SET_ATTITUDE_TARGET
// {
// Display_IHM::getInstanceOf().printLog("");
// mavlink_setAttitudeTarget(&message, *drone1.get(), 0, 0, 800, 0);
// drone1.get()->write_message(message);
// }
// else if(buffer_command=="4") // SET_ATTITUDE_TARGET
// {
// Display_IHM::getInstanceOf().printLog("");
// mavlink_setAttitudeTarget(&message, *drone1.get(), 0, 0, 0, 800);
// drone1.get()->write_message(message);
// }
/**
* @brief Class that model a Display_IHM
*
* @author Sylvain Colomer
* @date 23/04/19
* @version 1.0
*/
#include "../include/Display_IHM.h"
Display_IHM::Display_IHM()
{
}
Display_IHM::~Display_IHM()
{
}
void printMessage(std::string message){
}
void printLog(std::string message){
}
\ No newline at end of file
#include "../include/Tools_SDL2.h"
using namespace std;
SDL2Tools::SDL2Tools(){
if(SDL_Init(SDL_INIT_VIDEO) < 0){
std::cout <<"Erreur d'initialisation de la SDL " << SDL_GetError() <<endl;
exit(EXIT_FAILURE);
}
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
}
SDL2Tools::~SDL2Tools(){
TTF_Quit();
SDL_Quit();
}
/**
* Function that convey to creat a SDL frame
*/
SDL_Window* SDL2Tools::creatSDLFrame(int widht, int height){
SDL_Window* frame1 = NULL;
frame1 = SDL_CreateWindow("Test SDL 2.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, widht, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
if(frame1 == 0){
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
SDL_Quit();
}
return frame1;
}
void SDL2Tools::deleteSDLFrame(SDL_Window* frame1){
SDL_DestroyWindow(frame1);
}
void SDL2Tools::drawText(SDL_Renderer * renderer, char* text, int x, int y, int size){
SDL_Surface *textSurface;
SDL_Color black = {0, 0, 0};
SDL_Rect textArea;
TTF_Font* font1;
SDL_Texture* renderTexture;
font1 = TTF_OpenFont("../data/font/arial.ttf", size);
if(!font1) {
printf("TTF_OpenFont: %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
//writing of the text in the surface
textSurface = TTF_RenderText_Blended(font1, text, black);
renderTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
textArea.x=x;
textArea.y=y;
textArea.w=textSurface->w;
textArea.h=textSurface->h;
SDL_RenderCopy(renderer, renderTexture, NULL, &textArea);
TTF_CloseFont(font1);
}
/*void SDL2Tools::launchSDLCore(SDL_Window* frame1){
int continuer = 1;
SDL_Event event;
SDL_Renderer * renderer;
SDL_Color white = {255,255,255,255};
renderer = SDL_CreateRenderer(frame1, -1, SDL_RENDERER_ACCELERATED);
while(continuer){
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
SDL_RenderDrawLine(renderer, 50, 50,100,100);
SDL_RenderPresent(renderer);
SDL_WaitEvent(&event);
switch(event.type){
case SDL_QUIT:
continuer = 0;
break;
}
}
SDL_DestroyRenderer(renderer);
}*/
/**
* point position
* 1 4
*
* 2 3
*/
/*void SDL2Tools::drawSDLGraph(SDL_Window* frame1, SDL_Renderer * renderer, GraphStructure structure){
int widht, height;
int x1, y1, x2, y2, x3, y3, x4, y4;
float scale_x=0, scale_y=0;
float origin_x=0, origin_y=0;
float tmp;
int counter=0;
char *buffer1=NULL;
SDL_GetWindowSize(frame1, &widht,&height);
drawText(frame1, renderer, structure.title, 10, 10, 24);
x1=(widht/100)*10;
y1=(height/100)*10;
x2=(widht/100)*10;
y2=(height/100)*90;
x3=(widht/100)*90;
y3=(height/100)*90;
x4=(widht/100)*90;
y4=(height/100)*10;
origin_x=x2;
origin_y=y2;
scale_x=(structure.max_x-structure.min_x)/structure.scale_x;
scale_y=(structure.max_y-structure.min_y)/structure.scale_y;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
//Draw of the graphe border
SDL_RenderDrawLine(renderer, x1,y1,x2,y2);
SDL_RenderDrawLine(renderer, x2,y2,x3,y3);
SDL_RenderDrawLine(renderer, x3,y3,x4,y4);
SDL_RenderDrawLine(renderer, x1,y1,x4,y4);
//Draw y line
counter=structure.scale_y;
for(float i=structure.min_y;i<=structure.max_y;i=i+scale_y){
sprintf(buffer1,"%+.3f", i);
tmp = y1 + counter * ((y2-y1)/(structure.scale_y));
SDL_RenderDrawLine(renderer, x1, tmp, x2+5, tmp);
drawText(frame1, renderer, buffer1,x1-50, tmp-7, 14);
counter--;
}
//Draw x line
counter=0;
for(float i=structure.min_x;i<=structure.max_x;i=i+scale_x){
sprintf(buffer1,"%+.0f", i);
tmp = x2 + counter * ((x3-x2)/(structure.scale_x));
SDL_RenderDrawLine(renderer, tmp,y2,tmp,y2-5);
drawText(frame1, renderer, buffer1, tmp-7,y2+2, 14);
counter++;
}
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for(int i=-10;i<10;i++){
drawSDLGraphPoint(frame1, renderer, structure, 0, 0);
}
}*/
/*void SDL2Tools::drawSDLGraphLine(SDL_Window* frame1, SDL_Renderer * renderer, GraphStructure structure, float x1, float y1, float x2, float y2){
float scale_x=0, scale_y=0;
int final_x1=0, final_y1=0, final_x2=0, final_y2=0;
int origin_x, origin_y;
int widht, height;
int border_x1, border_x2, border_x3, border_x4, border_y1, border_y2, border_y3, border_y4;
SDL_GetWindowSize(frame1, &widht,&height);
border_x1=(widht/100)*10;
border_y1=(height/100)*10;
border_x2=(widht/100)*10;
border_y2=(height/100)*90;
border_x3=(widht/100)*90;
border_y3=(height/100)*90;
border_x4=(widht/100)*90;
border_y4=(height/100)*10;
scale_x=((border_x3-border_x2)/(structure.max_x-structure.min_x));
scale_y=(border_y2-border_y1)/(structure.max_y-structure.min_y);
origin_x=border_x1 +(-structure.min_x)*scale_x;
origin_y=border_y1 + (-structure.min_y)*scale_y;
final_x1=origin_x + x1*scale_x;
final_y1=origin_y - y1*scale_y;
final_x2=origin_x + x2*scale_x;
final_y2=origin_y - y2*scale_y;
SDL_RenderDrawLine(renderer, final_x1, final_y1, final_x2, final_y2);
}*/
/*void SDL2Tools::drawSDLGraphPoint(SDL_Window* frame1, SDL_Renderer * renderer, GraphStructure structure, float x1, float y1){
float scale_x=0, scale_y=0;
int final_x1=0, final_y1=0, final_x2=0, final_y2=0;
int widht, height;
int border_x1, border_x2, border_x3, border_x4, border_y1, border_y2, border_y3, border_y4;
int origin_x, origin_y;
SDL_GetWindowSize(frame1, &widht,&height);
border_x1=(widht/100)*10;
border_y1=(height/100)*10;
border_x2=(widht/100)*10;
border_y2=(height/100)*90;
border_x3=(widht/100)*90;
border_y3=(height/100)*90;
border_x4=(widht/100)*90;
border_y4=(height/100)*10;
scale_x=((border_x3-border_x2)/(structure.max_x-structure.min_x));
scale_y=(border_y2-border_y1)/(structure.max_y-structure.min_y);
origin_x=border_x1 +(-structure.min_x)*scale_x;
origin_y=border_y1 + (-structure.min_y)*scale_y;
final_x1=origin_x + x1*scale_x;
final_y1=origin_y - y1*scale_y;
for(int i=-5;i<5;i++)
SDL_RenderDrawPoint(renderer, final_x1+i, final_y1);
for(int i=-5;i<5;i++)
SDL_RenderDrawPoint(renderer, final_x1, final_y1+i);
}*/
Markdown is supported
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