-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHMIArq.cpp
370 lines (294 loc) · 8.14 KB
/
HMIArq.cpp
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
/*
* HMIArq.cpp
*
* Created on: 16 abr. 2017
* Author: Sergio
*/
#include "HMIArq.h"
HMIArq::HMIArq(Autopilot* Pilot){
// TODO Auto-generated constructor stub
MyPilot = Pilot;
}
HMIArq::~HMIArq() {
// TODO Auto-generated destructor stub
}
void HMIArq::Request_PIDgain(s_PIDgain & PIDgain) {
MyPilot->Request_PIDgain(PIDgain);
}
void HMIArq::Request_instParam(s_instParam & instParam) {
MyPilot->Request_instParam(instParam);
}
void HMIArq::Request_APinfo(s_APinfo & APinfo) {
APinfo.CTS.Towf_00(MyPilot->getTargetBearing());
APinfo.HDM.Towf_00(MyPilot->getCurrentHeading());
APinfo.deadband=MyPilot->dbt.getDeadband();
APinfo.mode=MyPilot->getCurrentMode();
APinfo.rudder=MyPilot->getTargetRudder();
APinfo.trim.Towf_00(MyPilot->dbt.getTrim());
}
void HMIArq::Request_IMUcal(s_IMUcal & IMUcal) {
if (MyPilot->getIMUcheck()==CHECK_ONGOING) {
IMUcal.IMUcalstatus = 'C';
} else {
switch (MyPilot->getIMUstatus()) {
case CAL_NOT_STARTED:
case CAL_START:
IMUcal.IMUcalstatus = '-'; break;
case CAL_INPROGRESS:
IMUcal.IMUcalstatus = 'O'; break;
case CAL_RESULT_RECALIBRATED:
IMUcal.IMUcalstatus = 'R'; break;
case CAL_RESULT_NOT_CALIBRATED:
IMUcal.IMUcalstatus = 'N'; break;
}
}
MyPilot->getCheckSGAM(IMUcal.SYSstatus, IMUcal.GYROstatus, IMUcal.ACCELstatus, IMUcal.MAGNstatus);
MyPilot->getCheckXYZ(IMUcal.X,IMUcal.Y,IMUcal.Z);
return;
}
void HMIArq::Request_FBKcal(s_FBKcal & FBKcal) {
MyPilot->getFBKcalStatus(FBKcal.cal_minFeedback, FBKcal.cal_maxFeedback);
return;
}
void HMIArq::Change_PID(s_PIDgain_flag change, s_gain gain) {
// if change.K* is true, take value from argument k*. If false, getK*() retrieves current value
float Kp = (change.Kp ? gain.Kp.float_00() : MyPilot->PID::GetKp());
float Ki = (change.Ki ? gain.Ki.float_00() : MyPilot->PID::GetKi());
float Kd = (change.Kd ? gain.Kd.float_00() : MyPilot->PID::GetKd());
MyPilot->SetTunings (Kp, Ki, Kd);
MyPilot->buzzer_Beep();
}
void HMIArq::Change_PID_rel (s_PIDgain_flag change, e_operation op, float value ){
float Kp=MyPilot->PID::GetKp();
float Ki=MyPilot->PID::GetKi();
float Kd=MyPilot->PID::GetKd();
if (change.Kp) operation (op, Kp, value);
if (change.Ki) operation (op, Ki, value);
if (change.Kd) operation (op, Kd, value);
MyPilot->SetTunings (Kp, Ki, Kd);
MyPilot->buzzer_Beep();
}
void HMIArq::operation (e_operation op, float &K, float value) {
switch (op) {
case OP_ADD:
K+=value;
break;
case OP_DEC:
K-=value;
break;
case OP_MULT:
K*=value;
break;
case OP_DIV:
K/=value;
break;
}
}
void HMIArq::setDBConf (type_DBConfig status) {
MyPilot->setDBConf (status);
MyPilot->buzzer_Beep();
}
void HMIArq::nextDBConf () {
MyPilot->nextDBConf ();
MyPilot->buzzer_Beep();
}
bool HMIArq::Change_instParam (s_instParam instParam) {
return MyPilot->Change_instParam (instParam);
MyPilot->buzzer_Beep();
}
void HMIArq::Apply_PIDrecom(){
if (MyPilot->CopyToPIDAutoTune()) {
MyPilot->buzzer_Beep();
MyPilot->setCurrentMode(STAND_BY);
} else {
DEBUG_print ("!PID recommendation not available\n");
}
}
void HMIArq::ResetPID(){
MyPilot->ResetTunings();
MyPilot->buzzer_Beep();
}
void HMIArq::Start_Stop(e_start_stop type){
MyPilot->Start_Stop(type);
MyPilot->buzzer_Beep();
}
void HMIArq::Start_Stop_wind(void){
MyPilot->Start_Stop_wind();
MyPilot->buzzer_Beep();
}
void HMIArq::Enter_Exit_FBK_Calib() {
MyPilot->Enter_Exit_FBK_Calib();
MyPilot->buzzer_Beep();
}
void HMIArq::Start_Cancel_AutotunePID() {
MyPilot->Start_Cancel_AutotunePID();
MyPilot->buzzer_Beep();
}
void HMIArq::Inc_Rudder_1(){
MyPilot->changeRudder(+RATE_1);
MyPilot->buzzer_Beep();
}
void HMIArq::Inc_Rudder_10(){
MyPilot->changeRudder(+RATE_10);
MyPilot->buzzer_Beep();
}
void HMIArq::Dec_Rudder_1(){
MyPilot->changeRudder(-RATE_1);
MyPilot->buzzer_Beep();
}
void HMIArq::Dec_Rudder_10(){
MyPilot->changeRudder(-RATE_10);
MyPilot->buzzer_Beep();
}
void HMIArq::Stop_Rudder(){
MyPilot->setTargetRudder(MyPilot->getCurrentRudder());//TODO: Should be restricted in ActuatorManager and public in MacuaAutopilot
}
void HMIArq::Inc_Course_1(){
MyPilot->setTargetBearing(MyPilot->getTargetBearing()+1);
MyPilot->buzzer_Beep();
}
void HMIArq::Inc_Course_10(){
MyPilot->setTargetBearing(MyPilot->getTargetBearing()+10);
MyPilot->buzzer_Beep();
}
void HMIArq::Dec_Course_1(){
MyPilot->setTargetBearing(MyPilot->getTargetBearing()-1);
MyPilot->buzzer_Beep();
}
void HMIArq::Dec_Course_10(){
MyPilot->setTargetBearing(MyPilot->getTargetBearing()-10);
MyPilot->buzzer_Beep();
}
void HMIArq::Set_NewCourse(float newCourse){
MyPilot->setTargetBearing(newCourse);
MyPilot->buzzer_Beep();
}
void HMIArq::Set_NextCourse(float nextCourse){
MyPilot->setNextCourse (nextCourse);
MyPilot->buzzer_Beep();
}
void HMIArq::Set_NextCourse_delta(int delta){
Set_NextCourse (MyPilot->getNextCourse() + delta);
}
void HMIArq::Set_Tacking(int delta){
Set_NextCourse (MyPilot->getCurrentHeading() + delta);
}
void HMIArq::Set_NewDeltaCourse(float newDCourse){
MyPilot->setTargetBearing(MyPilot->getTargetBearing()+newDCourse);
MyPilot->buzzer_Beep();
}
void HMIArq::Set_Headalign(){
//MyPilot->setHeadingDev(MyPilot->getTargetBearing() - MyPilot->getCurrentHeading() + MyPilot->getHeadingDev());
MyPilot->setHeadingDev(MyPilot->getNextCourse() - MyPilot->getCurrentHeading() + MyPilot->getHeadingDev());
MyPilot->buzzer_Beep();
}
// External Compass mode functions
void HMIArq::received_HDM( s_HDM HDM) {
MyPilot->HDMreceived(HDM);
}
// Wing mode functions
void HMIArq::received_VWR( s_VWR VWR) {
MyPilot->VWRreceived(VWR);
}
// Track mode functions
void HMIArq::received_APB( s_APB APB) {
MyPilot->APBreceived(APB);
}
void HMIArq::Accept_Next(void) {
// Accept WPnext
if (MyPilot->activateWPnext()) {
MyPilot->setCurrentMode(TRACK_MODE);
} else {
MyPilot->setTargetBearing(MyPilot->getNextCourse());
}
MyPilot->buzzer_Beep();
}
//Calibration functions
void HMIArq::Start_Cal(char sensor){
MyPilot->Start_Cal(sensor);
MyPilot->buzzer_Beep();
}
void HMIArq::Cal_NextSensor(void){
MyPilot->Cal_NextSensor();
MyPilot->buzzer_Beep();
}
void HMIArq::Cancel_Cal(){
MyPilot->Cancel_Cal();
}
void HMIArq::Save_Cal(){
MyPilot->EEsave_Calib();
MyPilot->buzzer_Beep();
}
void HMIArq::Save_instParam(){
MyPilot->EEsave_instParam();
MyPilot->buzzer_Beep();
}
void HMIArq::Save_PIDgain(){
MyPilot->EEsave_PIDgain();
MyPilot->buzzer_Beep();
}
void HMIArq::Save_HCParam(){
MyPilot->EEsave_HCParam();
MyPilot->buzzer_Beep();
}
void HMIArq::Load_calibrate_py(s_calibrate_py calibrate_py){
MyPilot->Load_calibrate_py(calibrate_py);
MyPilot->buzzer_Beep();
}
// Check if request has timeout, end request and return true.
// if not return false.
bool HMIArq::updateRequestTimeout() {
if ((_requestStatus==WAITING_USER_ANSWER) && ((millis()-_requestTime)>MAX_USER_ANSWER_TIME)) {
_requestStatus = NO_USER_REQUEST;
return true;
}
return false;
}
// Polls for user request status.
//If not launched, it LAUNCHES NEW REQUEST!
// If launched and answered, returns answer and RESET REQUEST!
// If launched and not answered, returns status
e_requestStatus HMIArq::userRequest (void) {
switch (_requestStatus) {
case NO_USER_REQUEST:
_requestStatus = WAITING_USER_ANSWER;
break;
case USER_ACCEPTED:
_requestStatus = NO_USER_REQUEST;
return USER_ACCEPTED;
break;
case USER_REJECTED:
_requestStatus = NO_USER_REQUEST;
return USER_REJECTED;
break;
case WAITING_USER_ANSWER:
return WAITING_USER_ANSWER;
break;
}
return _requestStatus;
}
// Registers user answer to request (if there is an active request).
// Arguments:
// true --> USER_ACCEPTED
// false--> USER_REJECTED
// Return: request status
e_requestStatus HMIArq::userRequestAnswer (bool answer) {
if (_requestStatus==WAITING_USER_ANSWER) {
_requestStatus = (answer? USER_ACCEPTED: USER_REJECTED);
}
switch (_requestStatus) {
case USER_ACCEPTED:
//DEBUG_print( "User accepted\n" );
break;
case USER_REJECTED:
//DEBUG_print( "User rejected\n" );
break;
default:
//DEBUG_print( "Other\n" );
break;
}
return _requestStatus;
}
e_requestStatus HMIArq::getRequestStatus () {
return _requestStatus;
}