forked from torriem/QtAgOpenGPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformgps.h
528 lines (416 loc) · 13.9 KB
/
formgps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#ifndef FORMGPS_H
#define FORMGPS_H
#include <QMainWindow>
#include <QScopedPointer>
#include <QtQuick/QQuickItem>
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QUdpSocket>
#include <QElapsedTimer>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QSurfaceFormat>
#include <QOpenGLFramebufferObject>
#include <QOpenGLBuffer>
#include "common.h"
#include "vec2.h"
#include "vec3.h"
#include "vec4.h"
#include "cflag.h"
#include "cmodulecomm.h"
#include "cperimeter.h"
#include "ccamera.h"
#include "btnenum.h"
#include "aogsettings.h"
namespace Ui {
class FormGPS;
}
//forward declare classes referred to below, to break circular
//references in the code
class TopLineDisplay;
class CWorldGrid;
class CNMEA;
class CSection;
class CABLine;
class CContour;
class CVehicle;
class CPerimeter;
class CBoundary;
class CRate;
class CYouTurn;
class QOpenGLShaderProgram;
class QQuickView;
class AOGRendererInSG;
class FormGPS : public QMainWindow
{
Q_OBJECT
public:
explicit FormGPS(QWidget *parent = 0);
~FormGPS();
/***********************************************
* Qt-specific things we need to keep track of *
***********************************************/
QLocale locale;
QQuickItem *qml_root;
QSignalMapper *sectionButtonsSignalMapper;
QTimer *tmrWatchdog;
/***************************
* Qt and QML GUI elements *
***************************/
QQuickView *qmlview;
QWidget *qmlcontainer;
AOGRendererInSG *openGLControl;
QObject *btnMinMaxZoom;
QObject *btnPerimeter;
QObject *btnAutoSteer;
QObject *btnFlag;
QObject *btnABLine;
QObject *btnContour;
QObject *btnManualOffOn;
QObject *btnSectionOffAutoOn;
QObject *btnTiltDown;
QObject *btnTiltUp;
QObject *btnZoomIn;
QObject *btnZoomOut;
//menu button and icon palette -- do we need to keep all of these?
QObject *btnMenuDrawer;
QObject *btnSnap;
QObject *btnTripOdometer;
QObject *btnGPSData;
QObject *btnSettings;
QObject *btnJob;
QObject *btnBoundaryMenu;
QObject *btnComm;
QObject *btnUnits;
QObject *btnFileExplorer;
QObject *btnAutoSteerConfig;
//area context menu
QObject *contextArea;
//flag context menu and buttons
QObject *contextFlag;
QObject *btnDeleteFlag;
QObject *btnDeleteAllFlags;
//section buttons
QObject *sectionButton[MAXSECTIONS-1]; //zero based array
QObject *txtDistanceOffABLine;
AOGSettings settings;
//offscreen GL objects:
QSurfaceFormat backSurfaceFormat;
QOpenGLContext backOpenGLContext;
QOffscreenSurface backSurface;
QOpenGLFramebufferObject *backFBO = 0;
/*******************
* from FormGPS.cs *
*******************/
//current directory of field;
QString currentFieldDirectory = "";
QString workingDirectory = "";
QString vehiclefileName = "";
//colors for sections and field background
//uchar redSections, grnSections, bluSections;
//keep these in QSettings
//QColor sectionColor;
//QColor fieldColor;
//uchar redField, grnField, bluField;
//polygon mode for section drawing
bool isDrawPolygons = false;
//for animated submenu
bool isMenuHid = true;
//flag for free drive window to control autosteer
bool isInFreeDriveMode = false;
//Flag stuff
uchar flagColor = 0;
bool leftMouseDownOnOpenGL = false; //mousedown event in opengl window
int flagNumberPicked = 0;
//Is it in 2D or 3D, metric, or imperial, display lightbar, display grid
bool isIn3D = true, isMetric = true, isLightbarOn = true, isGridOn, isSideGuideLines = true;
//bool isPureOn = true; //refer to QtSettings instead
//bool for whether or not a job is active
bool isJobStarted = false, isAreaOnRight = true, isAutoSteerBtnOn = false;
//master Manual and Auto, 3 states possible
btnStates manualBtnState = btnStates::Off;
btnStates autoBtnState = btnStates::Off;
//if we are saving a file
bool isSavingFile = false, isLogNMEA = false;
//Zoom variables
double gridZoom;
double zoomValue = 10;
double triangleResolution = 1.0;
double previousZoom = 25;
// Storage For Our Tractor, implement, background etc Textures
//Texture particleTexture;
GLuint texture[3];
QVector<QOpenGLTexture *> texture1;
//create the scene camera
CCamera camera;
//create world grid
//QScopedPointer <CWorldGrid> worldGrid;
CWorldGrid *worldGrid;
//create instance of a stopwatch for timing of frames and NMEA hz determination
QElapsedTimer swFrame;
QElapsedTimer stopwatch; //general stopwatch for debugging purposes.
//readonly Stopwatch swFrame = new Stopwatch();
//Time to do fix position update and draw routine
double frameTime = 0;
//For field saving in background
int saveCounter = 1;
//used to update the screen status bar etc
int statusUpdateCounter = 1;
//Parsing object of NMEA sentences
//QScopedPointer<CNMEA> pn;
CNMEA *pn =NULL;
//create an array of sections, so far only 8 section + 1 fullWidth Section
//QScopedArrayPointer<CSection> section;
//CSection *section =NULL;
//ABLine Instance
//QScopedPointer<CABLine> ABLine;
CABLine *ABLine =NULL;
//Contour mode Instance
//QScopedPointer<CContour> ct;
CContour *ct =NULL;
//Auto headland instance
CYouTurn *yt = NULL;
//Rate control object
CRate *rc = NULL;
//a brand new vehicle
//QScopedPointer<CVehicle> vehicle;
CVehicle *vehicle =NULL;
//module communication object
CModuleComm mc;
//perimeter object for area calc
CPerimeter periArea;
//boundary instance
CBoundary *boundary;
/*************************
* Position.designer.cs *
*************************/
double toLatitude;
double toLongitude;
//very first fix to setup grid etc
bool isFirstFixPositionSet = false, isGPSPositionInitialized = false;
// autosteer variables for sending serial
//short int guidanceLineDistanceOff, guidanceLineSteerAngle;
//how many fix updates per sec
int fixUpdateHz = 5;
double fixUpdateTime = 0.2;
//for heading or Atan2 as camera
bool isAtanCam = true;
/*
//Current fix positions
double fixEasting = 0.0;
double fixNorthing = 3.0;
double fixZ = 0.0;
*/
Vec2 fix;
/*
double fixHeadingSection = 0.0, fixHeadingTank = 0.0;
Vec2 pivotAxlePos;
Vec2 toolPos;
Vec2 tankPos;
Vec2 hitchPos;*/
Vec2 prevFix;
//headings
//double fixHeading = 0.0;
double fixHeadingCam = 0.0;
//storage for the cos and sin of heading
//double cosSectionHeading = 1.0, sinSectionHeading = 0.0;
//a distance between previous and current fix
double distance = 0.0, userDistance = 0;
//are we still getting valid data from GPS, resets to 0 in NMEA RMC block, watchdog
int recvCounter = 20;
//Everything is so wonky at the start
int startCounter = 0;
//individual points for the flags in a list
QVector<CFlag> flagPts;
bool flagsBufferCurrent = false;
//used to determine NMEA sentence frequency
int timerPn = 1;
double et = 0, hzTime = 0;
/*
double avgSpeed[10];//for average speed
int ringCounter = 0;
*/
//IMU
double rollDistance = 0;
double roll = 0; //, pitch = 0, angVel = 0;
double avgRoll = 0; //, avgPitch = 0, avgAngVel = 0;
int times;
double avgTiltRoll[30];//for tilt
int ringCounterTiltRoll = 0;
//public double[] avgTiltPitch = new double[10];//for pitch
//public int ringCounterTiltPitch = 0;
//public double[] avgAngularVelocity = new double[30];//for angular velocity
//public int ringCounterAngularVelocity = 0;
int totalFixSteps = 10, currentStepFix = 0;
Vec3 vHold;
Vec3 stepFixPts[50];
double distanceCurrentStepFix = 0, fixStepDist=0, minFixStepDist = 0;
bool isFixHolding = false, isFixHoldLoaded = false;
double rollZero = 0, pitchZero = 0;
double rollAngle = 0, pitchAngle = 0;
//step distances and positions for boundary, 6 meters before next point
double boundaryTriggerDistance = 6.0;
Vec2 prevBoundaryPos;
void updateFixPosition(); //process a new position
void calculatePositionHeading(); // compute all headings and fixes
void addBoundaryPoint();
void addSectionContourPathPoints();
void calculateSectionLookAhead(double northing, double easting, double cosHeading, double sinHeading);
void initializeFirstFewGPSPositions();
/************************
* SaveOpen.Designer.cs *
************************/
//moved to CVehicle
//list of the list of patch data individual triangles for field sections
//QVector<QSharedPointer<QVector<QVector3D>>> patchSaveList;
//moved to CContour.
//list of the list of patch data individual triangles for contour tracking
//QVector<QSharedPointer<QVector<Vec4>>> contourSaveList;
/**********************
* OpenGL.Designer.cs *
**********************/
//extracted Near, Far, Right, Left clipping planes of frustum
double frustum[24];
double fovy = 45;
double camDistanceFactor = -2;
int mouseX = 0, mouseY = 0;
int lastWidth=-1, lastHeight=-1;
//data buffer for pixels read from off screen buffer
//uchar grnPixels[80001];
LookAheadPixels lookaheadPixels[80001];
QImage grnPix;
/*
QOpenGLShaderProgram *simpleColorShader = 0;
QOpenGLShaderProgram *texShader = 0;
QOpenGLShaderProgram *interpColorShader = 0;
*/
QOpenGLBuffer skyBuffer;
QOpenGLBuffer flagsBuffer;
/***********************
* UDPComm.designer.cs *
***********************/
private:
QUdpSocket *udpSocket = NULL;
public:
bool isUDPServerOn = false;
void startUDPServer();
void stopUDPServer();
/**********************
* OpenGL.Designer.cs *
**********************/
/*
//Simple wrapper to draw primitives using lists of Vec3 or QVector3Ds
//with a single color.
void glDrawArraysColor(QOpenGLFunctions *gl, QMatrix4x4 mvp,
GLenum operation, QColor &color,
QOpenGLBuffer &vertexBuffer, GLenum glType,
int count,
float pointSize=1.0f);
//Simple wrapper to draw primitives using lists of vec3s or QVector3Ds
//with a color per vertex. Buffer format is 7 floats per vertice:
//x,y,z,r,g,b,a
void glDrawArraysColors(QOpenGLFunctions *gl, QMatrix4x4 mvp,
GLenum operation,
QOpenGLBuffer &vertexBuffer, GLenum glType,
int count,
float pointSize=1.0f);
//Buffer format is 5 floats per vertice:
//x,y,z,texX,texY
void glDrawArraysTexture(QOpenGLFunctions *gl, QMatrix4x4 mvp,
GLenum operation,
QOpenGLBuffer &vertexBuffer, GLenum glType,
int count);
*/
void drawLightBar(double Width, double Height, double offlineDistance, const QMatrix4x4 &modelview, const QMatrix4x4 &projection);
//void calcFrustum(QOpenGLFunctions_2_1 *gl);
//transitioning to OPenGL ES; use our own computed matrices
void calcFrustum(const QMatrix4x4 &mvp);
void setZoom();
void loadGLTextures();
private:
Ui::FormGPS *ui;
TopLineDisplay *tlDisp;
void setupGui();
/**************
* FormGPS.cs *
**************/
public:
QString speedMPH();
QString speedKPH();
void sectionCalcWidths();
void processSectionOnOffRequests();
void scanForNMEA();
/**************************
* SerialComm.Designer.cs *
**************************/
public:
void autoSteerDataOutToPort();
void autoSteerSettingsOutToPort();
void sectionControlOutToPort();
/***********************
* FormGPS.Designer.cs *
***********************/
void manualAllBtnsUpdate();
void manualBtnUpdate(int sectNumber);
void lineUpManualBtns();
// formgps_ui
bool closeAllMenus();
/**************************
* UI/Qt object callbacks *
**************************/
public slots:
/*******************
* from FormGPS.cs *
*******************/
void onGLControl_clicked(const QVariant &event);
void onBtnMinMaxZoom_clicked();
void onBtnPerimeter_clicked();
//void onBtnPerimeter_pressAndHeld();
void onBtnAutoSteer_clicked();
void onBtnFlag_clicked();
void onBtnABLine_clicked();
void onBtnContour_clicked();
void onBtnManualOffOn_clicked();
void onBtnSectionOffAutoOn_clicked();
void onBtnTiltDown_clicked();
void onBtnTiltUp_clicked();
void onBtnZoomIn_clicked();
void onBtnZoomOut_clicked();
void onBtnSnap_clicked();
void onBtnTripOdometer_clicked();
void onBtnGPSData_clicked();
void onBtnSettings_clicked();
void onBtnJob_clicked();
void onBtnBoundaryMenu_clicked();
void onBtnComm_clicked();
void onBtnUnits_clicked();
void onBtnFileExplorer_clicked();
void onBtnAutoSteerConfig_clicked();
void onBtnAreaSide_clicked();
//was btnSection#Man_Click in c#
void onBtnSectionMan_clicked(int sectNumber);
void onBtnRedFlag_clicked();
void onBtnGreenFlag_clicked();
void onBtnYellowFlag_clicked();
void onBtnDeleteFlag_clicked();
void onBtnDeleteAllFlags_clicked();
void tmrWatchdog_timeout();
/***************************
* from OpenGL.Designer.cs *
***************************/
void openGLControl_Draw();
void openGLControl_Initialized();
void openGLControl_Shutdown();
//void openGLControl_Resize();
void openGLControlBack_Draw();
void openGLControlBack_Initialized();
/*
* from UDPComm.Designer.cs
*/
void udpServerReadDatagrams();
/*
* From Position.Designer.cs
*/
void processSectionLookahead(); //called when section lookahead GL stuff is rendered
};
#endif // FORMGPS_H