LARS
LARS (Light Augmented Reality System) is an open-source framework for light-based interaction and real-time tracking in multi-robot experiments. Inspired by ARK, LARS extends the augmented reality paradigm to robotic collectives by projecting dynamic visual cues and environments onto the arena, enabling new experimental possibilities for collective robotics research, education, and outreach. LARS features integrated tracking, light projection, and modular experiment control with a user-friendly Qt GUI.
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1#ifndef MAINWINDOW_H
2#define MAINWINDOW_H
3
10
11#include <QMainWindow>
12#include <opencv2/core/core.hpp>
13#include <opencv2/highgui/highgui.hpp>
14#include <opencv2/imgproc/imgproc.hpp>
15#include <opencv2/opencv.hpp>
16#include <opencv2/video.hpp>
17//#include <opencv2/videoio.hpp>
18#include <opencv2/imgcodecs.hpp>
19//#include <opencv2/tracking.hpp>
20#include <iostream>
21#include <fstream>
22
23#include <QTimer>
24#include <QMouseEvent>
25#include <QRubberBand>
26#include <QFileDialog>
27#include <QDebug>
28
29//#include <QElapsedTimer>
30#include <QThread>
31
32#include <stdio.h>
33#include <stdlib.h>
34
35#include "etc/publicvars.h"
36#include "qcustomplot.h"
37
38//#include <stdexcept>
39
40//#include "savevid_thread.h"
41#include "savevidthread.h"
42
43#include "tracker/robottracker.h"
44#include "Kilobot/kilobotoverheadcontroller.h"
45//#include "Kilobot/kilobotexperiment.h"
46//#include "Kilobot/kilobotcalibrate.h"
47
48#include "arenaWindow.h"
49#include "ui/renderarea.h"
50#include "ui/worldmodel.h"
51
52#include "envbrain.h"
53
54typedef struct
55{
56 QRect BoundingRect;
57 int id;
59
60
61#define PAGE_SIZE 128
62#define PACKET_HEADER 0x55
63#define PACKET_SIZE PAGE_SIZE+4
64
65enum {
66 PACKET_STOP,
67 PACKET_LEDTOGGLE,
68 PACKET_FORWARDMSG,
69 PACKET_FORWARDRAWMSG,
70 PACKET_BOOTPAGE
71};
72
73typedef enum {
74 NORMAL = 0,
75 GPS,
76 SPECIAL = 0x80,
77 BOOT = 0x80,
78 BOOTPGM_PAGE,
79 BOOTPGM_SIZE,
80 RESET,
81 SLEEP,
82 WAKEUP,
83 CHARGE,
84 VOLTAGE,
85 RUN,
86 READUID,
87 CALIB
88} message_type_t;
89
90
91enum {
92 CALIB_SAVE,
93 CALIB_UID,
94 CALIB_TURN_LEFT,
95 CALIB_TURN_RIGHT,
96 CALIB_STRAIGHT
97};
98
99#pragma pack(1)
100typedef struct __attribute__((__packed__)) {
101 uint8_t mode;
102 uint16_t uid;
103 uint8_t turn_left;
104 uint8_t turn_right;
105 uint8_t straight_left;
106 uint8_t straight_right;
107 uint16_t unused;
108} calibmsg_t;
109
110
111namespace Ui {
112class MainWindow;
113}
114
120class MainWindow : public QMainWindow
121{
122 Q_OBJECT
123
124public:
129 explicit MainWindow(QWidget *parent = 0);
133 ~MainWindow();
134
135 WorldModel wm;
136
137private slots:
138
139 void logToFile(QVector<Kilobot *> kiloVec);
140 void logToFile(QVector<QPoint> posVec);
141 void logToFile_PosLED(QVector<Kilobot *> kiloVec);
142
143 void on_capturing_button_clicked();
144
145 void convertInt2HexStr(int input, std::string &output);
146
147 void showImage(cv::Mat frame);
148
149 void writeSettings();
150
151 void readSettings();
152
153 void myDebug(QString string);
154
155 void getKilos(QVector<Kilobot *> kiloVec);
156
157 void getDrawnCircles(QVector <drawnCircle> circsToDraw);
158
159 void drawOverlay(Mat &frame);
160
161 void drawKilobots(Mat &frame);
162
163 void drawHeatMapOnGUI(Mat &frame);
164
165 void findMarkerRect();
166
169 void calibrateKilobot();
170
171 void calibUID(int);
172 void calibLeft(int);
173 void calibRight(int);
174 void calibStraight(int);
175 void calibSave();
176 void calibStop();
178
179 void on_fromVid_rButton_clicked();
180
181 void on_fromCam_rButton_clicked();
182
183 void rot90(cv::Mat &matImage, int rotflag);
184
185 //-------Mouse Functions---------
186 // bool eventFilter(QObject *obj, QEvent *event);
187
188 void mousePressEvent(QMouseEvent *event) override;
189
190 void mouseMoveEvent(QMouseEvent *event) override;
191
192 void mouseReleaseEvent(QMouseEvent *event) override;
193
194 bool isValidPlaceForSelect(int x, int y);
195
196 // ...
197
198 void on_open_set_button_clicked();
199
200 void on_Rotate_ComboBox_activated(const QString &arg1);
201
202 void on_saveVid_button_clicked();
203
204 void uiInitialization();
205
206 void plotData(QCustomPlot *customPlot, double value);
207
208 void initializePlot(QCustomPlot *customPlot);
209
210 void resetHeatMap();
211
214 // -------------------------------------------------------------------------------------------
215 // GUI Functions
216
217 void update_wmMarkers();
218
219 void on_debug_CheckBox_clicked();
220
221// void on_save_var_button_clicked();
222
223// void on_load_var_button_clicked();
224
225 void SendKeyBoardData(int key);
226
227 void keyPressEvent(QKeyEvent *key) override;
228
229// void on_JoyStick_button_pressed();
230
231 void on_ArenaWindow_button_clicked();
232
233 void updateColors();
234
235 void updateColors(QString colorString);
236
237 void updateSliders();
238
239 void on_userRed_pushButton_clicked();
240
241 void on_userBlue_pushButton_clicked();
242
243 void on_fullScreen_pushButton_clicked();
244
245 void on_fitRect_pushButton_clicked();
246
247 void on_fromImage_pushButton_clicked();
248
249
250 void on_saveSetting_pushButton_clicked();
251
252 void on_loadSetting_pushButton_clicked();
253
254 void on_startTracking_pushButton_clicked();
255
256 void update_startTracking_pushBotton();
257
258 void on_detectKilobots_pushButton_clicked();
259
260
261 void on_crop_pushButton_clicked();
262
263 void on_detectMarker_pushButton_clicked();
264
265 void on_markerWidth_Slider_sliderMoved(int position);
266
267 void on_debug_tracker_stateChanged(int arg1);
268
269 void on_maxDispl_slider_sliderMoved(int position);
270
271 void on_EFWL_slider_sliderMoved(int position);
272
273// void on_nullRob_pushButton_clicked();
274
275 void on_robRendRad_slider_sliderMoved(int position);
276
277 void on_smoothnessFact_slider_sliderMoved(int position);
278
279 void on_imageExpField_pushButton_clicked(bool checked);
280
281 void on_initPoints_pushButton_clicked(bool checked);
282
283 void on_resetTrace_pushButton_clicked();
284
285
286
287
288 void on_drawTrace_CheckBox_stateChanged(int arg1);
289
290 void on_shuffleImageExpField_pushButton_clicked();
291
292 void on_drawBoundary_CheckBox_stateChanged(int arg1);
293
294 void on_drawHeatMap_CheckBox_clicked();
295
296 void on_drawColCircles_CheckBox_clicked(bool checked);
297
298
299 // for kilobot calibration
300// void transmitKiloState(kilobot_message);
301
302 void on_seaBlue_pushButton_clicked();
303
304 void on_drawRobCircles_CheckBox_clicked(bool checked);
305
306 void on_ohc_set_prog_clicked();
307
308 void on_writeLog_button_clicked(bool checked);
309
310 void on_env2_rButton_clicked(bool checked);
311
312 void on_env1_rButton_clicked(bool checked);
313
314 void on_openImageField_pushButton_clicked();
315
316 void on_env3_rButton_clicked();
317
318 void on_env4_rButton_clicked();
319
320 void on_gradientExpField_pushButton_clicked();
321
322 void on_noiseTiles_slider_valueChanged(int value);
323
324 void on_noiseFreq_slider_valueChanged(int value);
325
326 void on_noiseStrength_slider_valueChanged(int value);
327
328 void on_draw_network_stateChanged(int arg1);
329
330 void on_sliderRandom0_valueChanged(int value);
331
332 void on_noise_radioButton_clicked(bool checked);
333
334 void on_draw_centroid_stateChanged(int arg1);
335
336 void on_draw_voronoii_stateChanged(int arg1);
337
338 void on_draw_bots_colors_stateChanged(int arg1);
339
340 void on_sliderRandom1_valueChanged(int value);
341
342 void on_draw_spatial_netw_stateChanged(int arg1);
343
344 void on_drawBall_stateChanged(int arg1);
346
347private:
348 Ui::MainWindow *ui;
349
350 publicVars *publicVar;
351
352 ArenaWindow *arenaWindow, *arenaWindow2;
353
354 EnvBrain *envBrain;
355
356 QList<QScreen*> screensList;
357
358 QColor bg_color;
359
360 KilobotTracker kbtracker;
362
363 CalibWindow *calib;
364 SerialConnection *serial_conn;
365
366 saveVidThread *sRawVidThrd, *sProcVidThrd;
367
368 QGraphicsScene *scene;
369
370
371 // Store the rect and id of aruco markers
372 QList<detectedMarker> detectedMarkersList;
373 QList<QPoint> detectedMarkerCenterList;
374
375 QPoint mapPoint(QPoint P, QVector2D scale, QVector2D bias);
376 QPoint mapPoint(QPoint P, Matx33f lambda);
377 QPoint mapPoint(QPoint P, Matx33f rvec, Point3f tvec);
378 cv::Mat mapA2C, mapC2A = cv::Mat::ones(3,3, CV_8UC3);
379
380
381 QFile log_file;
382 QTextStream log_stream;
383
384 //-------------------------
385 bool DebugAv, boolDebug = true, FilterAv;
386
387 int prevKeyBoard;
388
389 bool firstPointSelectedIsValid;
390 bool tl_set, br_set, paused;
391 bool boolSaveVideoFile = false;
392 bool capturingBool = false;
393
394 double FPS;
395 double rotIndex;
396 QElapsedTimer elapsedTimer;
397 QPoint origin;
398 QRubberBand *rubberBand;
399 QPoint mouseBias;
400 QRect cropQRect;
401 bool cropRectDefined = false;
402
403 QString srcStr;
404 QTimer *timer, *joyStick_Timer;
405 cv::Rect cropRect;
406 QSize procQSize, GUIQSize, fullCapSize;
407 cv::Size capSize, procSize;
408 int ui_trigID_zero = 3;
409
410 // For cropping
411 QPoint TLInGUI, TLInFit, TLInCap;
412 QSize sizeInGUI, sizeInFit, sizeInCap;
413
414 QVector <drawnCircle> circlsToDraw;
415 QVector <Kilobot *> kiloVector;
416 QVector<QPoint> kiloPosVec;
417 QList<Vec3f> detectedCircles;
418
419 cv::Mat currentFrame, heatMapOnFrame;
420
421 // Traces
422 int listInd = 0, nList = 1000;
423
424
425signals:
426 void QImageProcReady(QImage image);
427 void imageProcReady(cv::Mat image);
428 void imageRawReceived(cv::Mat image);
429 void clicked(const QString &text);
430 void broadcastMessage(kilobot_broadcast msg);
431 void sendKiloMessage(kilobot_message msg);
432 void kilobotPosVecReady(QVector<QPoint> posVec);
433
434};
435
436#endif // MAINWINDOW_H
Definition arenaWindow.h:32
Definition calibrate.h:8
Environment logic and utility class for the robot arena.
Definition envbrain.h:25
Definition kilobotoverheadcontroller.h:21
The KilobotTracker class.
Definition kilobottracker_copy.h:163
MainWindow(QWidget *parent=0)
Constructs the main application window.
Definition mainwindow.cpp:13
~MainWindow()
Destructor for MainWindow.
Definition mainwindow.cpp:102
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition qcustomplot.h:3754
Definition serialconn.h:12
Definition worldmodel.h:41
Definition publicvars.h:8
Definition savevidthread.h:12
Declaration of EnvBrain, environment logic module for LARS.
Definition mainwindow.h:55
Definition kilobot.h:31
Definition kilobot.h:25