close Warning: Can't use blame annotator:
svn blame failed on branches/mavlink/tools/Controller/Mavlink/src/GuiInterface.cpp: 200029 - Couldn't perform atomic initialization

source: flair-src/branches/mavlink/tools/Controller/Mavlink/src/GuiInterface.cpp@ 77

Last change on this file since 77 was 77, checked in by Thomas Fuhrmann, 8 years ago

Change the GUI of MavPlanner to match with mission planning (only GUI is working)

File size: 5.2 KB
RevLine 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2016/09/02
6// filename: GuiInterface.cpp
7//
8// authors: Thomas Fuhrmann
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Create the GUI and give an abstract interface to it
14//
15//
16/*********************************************************************/
17
18#include "GuiInterface.h"
19
20#include <cvmatrix.h>
21#include <FrameworkManager.h>
22#include <Socket.h>
23#include <Thread.h>
24
25#include <Tab.h>
26#include <TabWidget.h>
27#include <DoubleSpinBox.h>
28#include <PushButton.h>
29#include <GroupBox.h>
30#include <ListWidget.h>
31#include <Label.h>
32#include <ComboBox.h>
33
34#include <string>
35#include <sstream>
36
37using namespace flair::core;
38using namespace flair::gui;
39using namespace std;
40
41GuiInterface::GuiInterface(const FrameworkManager *parent, string name)
42 : Thread(parent, name, 6),
43 mainTab(new Tab(parent->GetTabWidget(), name)) {
44
45 tabWidget = new TabWidget(mainTab->NewRow(), name);
46
47 // Main tab
48 Tab* settingsTab = new Tab(tabWidget, "Settings");
49
50 // Controls group
51 controlsGroupBox = new GroupBox(settingsTab->NewRow(), "Controls");
52 btnStartMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Start mission");
53 btnStopMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Stop mission");
54 btnResumeMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Resume mission");
55
56 // Add cmd group
57 addCmdGroupBox = new GroupBox(settingsTab->NewRow(), "Add mission command");
58 // commandLabel = new Label(addCmdGroupBox->NewRow(), "Command label");
59 // commandLabel->SetText("Command");
60 // param1Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param1 label");
61 // commandLabel->SetText("Param1");
62 // param2Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param2 label");
63 // commandLabel->SetText("Param2");
64 // param3Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param3 label");
65 // commandLabel->SetText("Param3");
66 comboCmd = new ComboBox(addCmdGroupBox->NewRow(), "Select command");
67 // Fill the ComboBox
68 for (auto &command : commandsAvailable) {
69 comboCmd->AddItem(command);
70 }
71 // comboCmd->AddItem("WAYPOINT");
72 // comboCmd->AddItem("TAKEOFF");
73 // comboCmd->AddItem("LAND");
74 // comboCmd->AddItem("RETURN");
75 // comboCmd->AddItem("JUMP");
76 param1Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param1",
77 -90, 90, 0.5, 1, 3);
78 param2Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param2",
79 -90, 90, 0.5, 1, 3);
80 param3Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param3",
81 -90, 90, 0.5, 1, 3);
82 btnAddMissionCmd = new PushButton(addCmdGroupBox->NewRow(), "Add mission cmd");
83 btnDelMissionCmd = new PushButton(addCmdGroupBox->LastRowLastCol(), "Del mission cmd");
84 btnSendMission = new PushButton(addCmdGroupBox->LastRowLastCol(), "Send mission");
85
86 // Show wpt group
87 showItemsGroupBox = new GroupBox(settingsTab->NewRow(), "Show mission items");
88 listMissionItems = new ListWidget(showItemsGroupBox->NewRow(), "Mission cmd list");
89
90 // listEntranceWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Entrance wpt");
91 // listExitWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Exit wpt");
92 // btnRemoveMissionWpt = new PushButton(showWptGroupBox->NewRow(), "Remove mission wpt");
93 // btnRemoveEntranceWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove entrance wpt");
94 // btnRemoveExitWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove exit wpt");
95
96 // // Action wpt group
97 // actionWptGroupBox = new GroupBox(settingsTab->NewRow(), "Action");
98 // btnSendWpt = new PushButton(actionWptGroupBox->NewRow(), "Send wpt");
99 // btnClearWpt = new PushButton(actionWptGroupBox->LastRowLastCol(), "Clear wpt");
100 // btnLoop = new PushButton(actionWptGroupBox->LastRowLastCol(), "Loop");
101
102 //TODO IP & PORT from config.h file
103 sendSocket = new Socket((Thread *)this, "send socket", "127.0.0.1:5000");
104}
105
106GuiInterface::~GuiInterface() {
107}
108
109void GuiInterface::Run() {
110 Thread::Info("Debug: enter MavPlanner acquisition loop\n");
111
112 if (getFrameworkManager()->ErrorOccured()) {
113 SafeStop();
114 Thread::Err("An error occurred, we don't launch the Run loop.\n");
115 }
116
117 while (!ToBeStopped()) {
118 // TODO : time from config.h
119 Thread::SleepMS(500);
120 // Buttons to control GUI
121 if (btnAddMissionCmd->Clicked()) {
122 //TODO
123 listMissionItems->AddItem(MissionCmdGet());
124 }
125 if (btnDelMissionCmd->Clicked()) {
126 listMissionItems->RemoveItem();
127 }
128 // Buttons to send commands
129 if (btnStartMission->Clicked()) {
130 MissionStart();
131 }
132 if (btnStopMission->Clicked()) {
133 MissionStop();
134 }
135 if (btnResumeMission->Clicked()) {
136 MissionResume();
137 }
138 if (btnSendMission->Clicked()) {
139 MissionSend();
140 }
141 }
142}
143
144std::string GuiInterface::MissionCmdGet() {
145 std::ostringstream stringStream;
146 stringStream.precision(1);
147 stringStream << fixed;
148 stringStream << commandsAvailable[comboCmd->CurrentIndex()] << "|" << param1Field->Value() << "|" << param2Field->Value() << "|" << param3Field->Value();
149 return stringStream.str();
150}
Note: See TracBrowser for help on using the repository browser.