CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Blimp/GCS_MAVLink_Blimp.cpp
Views: 1798
1
#include "Blimp.h"
2
3
#include "GCS_MAVLink_Blimp.h"
4
#include <AP_RPM/AP_RPM_config.h>
5
#include <AP_OpticalFlow/AP_OpticalFlow_config.h>
6
7
MAV_TYPE GCS_Blimp::frame_type() const
8
{
9
return blimp.get_frame_mav_type();
10
}
11
12
MAV_MODE GCS_MAVLINK_Blimp::base_mode() const
13
{
14
uint8_t _base_mode = MAV_MODE_FLAG_STABILIZE_ENABLED;
15
_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
16
17
// we are armed if we are not initialising
18
if (blimp.motors != nullptr && blimp.motors->armed()) {
19
_base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
20
}
21
22
// indicate we have set a custom mode
23
_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
24
25
return (MAV_MODE)_base_mode;
26
}
27
28
uint32_t GCS_Blimp::custom_mode() const
29
{
30
return (uint32_t)blimp.control_mode;
31
}
32
33
MAV_STATE GCS_MAVLINK_Blimp::vehicle_system_status() const
34
{
35
// set system as critical if any failsafe have triggered
36
if (blimp.any_failsafe_triggered()) {
37
return MAV_STATE_CRITICAL;
38
}
39
40
if (blimp.ap.land_complete) {
41
return MAV_STATE_STANDBY;
42
}
43
if (!blimp.ap.initialised) {
44
return MAV_STATE_BOOT;
45
}
46
47
return MAV_STATE_ACTIVE;
48
}
49
50
51
void GCS_MAVLINK_Blimp::send_position_target_global_int()
52
{
53
Location target;
54
if (!blimp.flightmode->get_wp(target)) {
55
return;
56
}
57
static constexpr uint16_t POSITION_TARGET_TYPEMASK_LAST_BYTE = 0xF000;
58
static constexpr uint16_t TYPE_MASK = POSITION_TARGET_TYPEMASK_VX_IGNORE | POSITION_TARGET_TYPEMASK_VY_IGNORE | POSITION_TARGET_TYPEMASK_VZ_IGNORE |
59
POSITION_TARGET_TYPEMASK_AX_IGNORE | POSITION_TARGET_TYPEMASK_AY_IGNORE | POSITION_TARGET_TYPEMASK_AZ_IGNORE |
60
POSITION_TARGET_TYPEMASK_YAW_IGNORE | POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE | POSITION_TARGET_TYPEMASK_LAST_BYTE;
61
62
mavlink_msg_position_target_global_int_send(
63
chan,
64
AP_HAL::millis(), // time_boot_ms
65
MAV_FRAME_GLOBAL, // targets are always global altitude
66
TYPE_MASK, // ignore everything except the x/y/z components
67
target.lat, // latitude as 1e7
68
target.lng, // longitude as 1e7
69
target.alt * 0.01f, // altitude is sent as a float
70
0.0f, // vx
71
0.0f, // vy
72
0.0f, // vz
73
0.0f, // afx
74
0.0f, // afy
75
0.0f, // afz
76
0.0f, // yaw
77
0.0f); // yaw_rate
78
}
79
80
void GCS_MAVLINK_Blimp::send_nav_controller_output() const
81
{
82
83
}
84
85
float GCS_MAVLINK_Blimp::vfr_hud_airspeed() const
86
{
87
Vector3f airspeed_vec_bf;
88
if (AP::ahrs().airspeed_vector_true(airspeed_vec_bf)) {
89
// we are running the EKF3 wind estimation code which can give
90
// us an airspeed estimate
91
return airspeed_vec_bf.length();
92
}
93
return AP::gps().ground_speed();
94
}
95
96
int16_t GCS_MAVLINK_Blimp::vfr_hud_throttle() const
97
{
98
if (blimp.motors == nullptr) {
99
return 0;
100
}
101
return (int16_t)(blimp.motors->get_throttle() * 100);
102
}
103
104
/*
105
send PID tuning message
106
*/
107
void GCS_MAVLINK_Blimp::send_pid_tuning()
108
{
109
if (blimp.control_mode == Mode::Number::MANUAL || blimp.control_mode == Mode::Number::LAND) {
110
//No PIDs are used in Manual or Land mode.
111
return;
112
}
113
114
static const int8_t axes[] = {
115
PID_SEND::VELX,
116
PID_SEND::VELY,
117
PID_SEND::VELZ,
118
PID_SEND::VELYAW,
119
PID_SEND::POSX,
120
PID_SEND::POSY,
121
PID_SEND::POSZ,
122
PID_SEND::POSYAW
123
};
124
for (uint8_t i=0; i<ARRAY_SIZE(axes); i++) {
125
if (!(blimp.g.gcs_pid_mask & (1<<(axes[i]-1)))) {
126
continue;
127
}
128
if (!HAVE_PAYLOAD_SPACE(chan, PID_TUNING)) {
129
return;
130
}
131
const AP_PIDInfo *pid_info = nullptr;
132
switch (axes[i]) {
133
case PID_SEND::VELX:
134
pid_info = &blimp.pid_vel_xy.get_pid_info_x();
135
break;
136
case PID_SEND::VELY:
137
pid_info = &blimp.pid_vel_xy.get_pid_info_y();
138
break;
139
case PID_SEND::VELZ:
140
pid_info = &blimp.pid_vel_z.get_pid_info();
141
break;
142
case PID_SEND::VELYAW:
143
pid_info = &blimp.pid_vel_yaw.get_pid_info();
144
break;
145
case PID_SEND::POSX:
146
pid_info = &blimp.pid_pos_xy.get_pid_info_x();
147
break;
148
case PID_SEND::POSY:
149
pid_info = &blimp.pid_pos_xy.get_pid_info_y();
150
break;
151
case PID_SEND::POSZ:
152
pid_info = &blimp.pid_pos_z.get_pid_info();
153
break;
154
case PID_SEND::POSYAW:
155
pid_info = &blimp.pid_pos_yaw.get_pid_info();
156
break;
157
default:
158
continue;
159
}
160
if (pid_info != nullptr) {
161
mavlink_msg_pid_tuning_send(chan,
162
axes[i],
163
pid_info->target,
164
pid_info->actual,
165
pid_info->FF,
166
pid_info->P,
167
pid_info->I,
168
pid_info->D,
169
pid_info->slew_rate,
170
pid_info->Dmod);
171
}
172
}
173
}
174
175
uint8_t GCS_MAVLINK_Blimp::sysid_my_gcs() const
176
{
177
return blimp.g.sysid_my_gcs;
178
}
179
bool GCS_MAVLINK_Blimp::sysid_enforce() const
180
{
181
return blimp.g2.sysid_enforce;
182
}
183
184
uint32_t GCS_MAVLINK_Blimp::telem_delay() const
185
{
186
return (uint32_t)(blimp.g.telem_delay);
187
}
188
189
bool GCS_Blimp::vehicle_initialised() const
190
{
191
return blimp.ap.initialised;
192
}
193
194
// try to send a message, return false if it wasn't sent
195
bool GCS_MAVLINK_Blimp::try_send_message(enum ap_message id)
196
{
197
switch (id) {
198
199
case MSG_WIND:
200
CHECK_PAYLOAD_SIZE(WIND);
201
send_wind();
202
break;
203
204
case MSG_SERVO_OUT:
205
case MSG_AOA_SSA:
206
case MSG_LANDING:
207
case MSG_ADSB_VEHICLE:
208
// unused
209
break;
210
211
default:
212
return GCS_MAVLINK::try_send_message(id);
213
}
214
return true;
215
}
216
217
218
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
219
// @Param: RAW_SENS
220
// @DisplayName: Raw sensor stream rate
221
// @Description: Stream rate of RAW_IMU, SCALED_IMU2, SCALED_IMU3, SCALED_PRESSURE, SCALED_PRESSURE2, SCALED_PRESSURE3, AIRSPEED and SENSOR_OFFSETS to ground station
222
// @Units: Hz
223
// @Range: 0 10
224
// @Increment: 1
225
// @RebootRequired: True
226
// @User: Advanced
227
AP_GROUPINFO("RAW_SENS", 0, GCS_MAVLINK_Parameters, streamRates[0], 0),
228
229
// @Param: EXT_STAT
230
// @DisplayName: Extended status stream rate to ground station
231
// @Description: Stream rate of SYS_STATUS, POWER_STATUS, MCU_STATUS, MEMINFO, CURRENT_WAYPOINT, GPS_RAW_INT, GPS_RTK (if available), GPS2_RAW (if available), GPS2_RTK (if available), NAV_CONTROLLER_OUTPUT, and FENCE_STATUS to ground station
232
// @Units: Hz
233
// @Range: 0 10
234
// @Increment: 1
235
// @RebootRequired: True
236
// @User: Advanced
237
AP_GROUPINFO("EXT_STAT", 1, GCS_MAVLINK_Parameters, streamRates[1], 0),
238
239
// @Param: RC_CHAN
240
// @DisplayName: RC Channel stream rate to ground station
241
// @Description: Stream rate of SERVO_OUTPUT_RAW and RC_CHANNELS to ground station
242
// @Units: Hz
243
// @Range: 0 10
244
// @Increment: 1
245
// @RebootRequired: True
246
// @User: Advanced
247
AP_GROUPINFO("RC_CHAN", 2, GCS_MAVLINK_Parameters, streamRates[2], 0),
248
249
// @Param: RAW_CTRL
250
// @DisplayName: Unused
251
// @Description: Unused
252
// @Units: Hz
253
// @Range: 0 10
254
// @Increment: 1
255
// @RebootRequired: True
256
// @User: Advanced
257
AP_GROUPINFO("RAW_CTRL", 3, GCS_MAVLINK_Parameters, streamRates[3], 0),
258
259
// @Param: POSITION
260
// @DisplayName: Position stream rate to ground station
261
// @Description: Stream rate of GLOBAL_POSITION_INT and LOCAL_POSITION_NED to ground station
262
// @Units: Hz
263
// @Range: 0 10
264
// @Increment: 1
265
// @RebootRequired: True
266
// @User: Advanced
267
AP_GROUPINFO("POSITION", 4, GCS_MAVLINK_Parameters, streamRates[4], 0),
268
269
// @Param: EXTRA1
270
// @DisplayName: Extra data type 1 stream rate to ground station
271
// @Description: Stream rate of ATTITUDE, SIMSTATE (SITL only), AHRS2 and PID_TUNING to ground station
272
// @Units: Hz
273
// @Range: 0 10
274
// @Increment: 1
275
// @RebootRequired: True
276
// @User: Advanced
277
AP_GROUPINFO("EXTRA1", 5, GCS_MAVLINK_Parameters, streamRates[5], 0),
278
279
// @Param: EXTRA2
280
// @DisplayName: Extra data type 2 stream rate to ground station
281
// @Description: Stream rate of VFR_HUD to ground station
282
// @Units: Hz
283
// @Range: 0 10
284
// @Increment: 1
285
// @RebootRequired: True
286
// @User: Advanced
287
AP_GROUPINFO("EXTRA2", 6, GCS_MAVLINK_Parameters, streamRates[6], 0),
288
289
// @Param: EXTRA3
290
// @DisplayName: Extra data type 3 stream rate to ground station
291
// @Description: Stream rate of AHRS, SYSTEM_TIME, RANGEFINDER, DISTANCE_SENSOR, GIMBAL_DEVICE_ATTITUDE_STATUS, OPTICAL_FLOW, MAG_CAL_REPORT, MAG_CAL_PROGRESS, EKF_STATUS_REPORT, VIBRATION and RPM to ground station
292
// @Units: Hz
293
// @Range: 0 10
294
// @Increment: 1
295
// @RebootRequired: True
296
// @User: Advanced
297
AP_GROUPINFO("EXTRA3", 7, GCS_MAVLINK_Parameters, streamRates[7], 0),
298
299
// @Param: PARAMS
300
// @DisplayName: Parameter stream rate to ground station
301
// @Description: Stream rate of PARAM_VALUE to ground station
302
// @Units: Hz
303
// @Range: 0 10
304
// @Increment: 1
305
// @RebootRequired: True
306
// @User: Advanced
307
AP_GROUPINFO("PARAMS", 8, GCS_MAVLINK_Parameters, streamRates[8], 0),
308
AP_GROUPEND
309
};
310
311
static const ap_message STREAM_RAW_SENSORS_msgs[] = {
312
MSG_RAW_IMU,
313
MSG_SCALED_IMU2,
314
MSG_SCALED_IMU3,
315
MSG_SCALED_PRESSURE,
316
MSG_SCALED_PRESSURE2,
317
MSG_SCALED_PRESSURE3,
318
#if AP_AIRSPEED_ENABLED
319
MSG_AIRSPEED,
320
#endif
321
};
322
static const ap_message STREAM_EXTENDED_STATUS_msgs[] = {
323
MSG_SYS_STATUS,
324
MSG_POWER_STATUS,
325
#if HAL_WITH_MCU_MONITORING
326
MSG_MCU_STATUS,
327
#endif
328
MSG_MEMINFO,
329
MSG_CURRENT_WAYPOINT, // MISSION_CURRENT
330
#if AP_GPS_GPS_RAW_INT_SENDING_ENABLED
331
MSG_GPS_RAW,
332
#endif
333
#if AP_GPS_GPS_RTK_SENDING_ENABLED
334
MSG_GPS_RTK,
335
#endif
336
#if AP_GPS_GPS2_RAW_SENDING_ENABLED
337
MSG_GPS2_RAW,
338
#endif
339
#if AP_GPS_GPS2_RTK_SENDING_ENABLED
340
MSG_GPS2_RTK,
341
#endif
342
MSG_NAV_CONTROLLER_OUTPUT,
343
#if AP_FENCE_ENABLED
344
MSG_FENCE_STATUS,
345
#endif
346
MSG_POSITION_TARGET_GLOBAL_INT,
347
};
348
static const ap_message STREAM_POSITION_msgs[] = {
349
MSG_LOCATION,
350
MSG_LOCAL_POSITION
351
};
352
static const ap_message STREAM_RC_CHANNELS_msgs[] = {
353
MSG_SERVO_OUTPUT_RAW,
354
MSG_RC_CHANNELS,
355
#if AP_MAVLINK_MSG_RC_CHANNELS_RAW_ENABLED
356
MSG_RC_CHANNELS_RAW, // only sent on a mavlink1 connection
357
#endif
358
};
359
static const ap_message STREAM_EXTRA1_msgs[] = {
360
MSG_ATTITUDE,
361
#if AP_SIM_ENABLED
362
MSG_SIMSTATE,
363
#endif
364
MSG_AHRS2,
365
MSG_PID_TUNING // Up to four PID_TUNING messages are sent, depending on GCS_PID_MASK parameter
366
};
367
static const ap_message STREAM_EXTRA2_msgs[] = {
368
MSG_VFR_HUD
369
};
370
static const ap_message STREAM_EXTRA3_msgs[] = {
371
MSG_AHRS,
372
MSG_SYSTEM_TIME,
373
MSG_WIND,
374
#if AP_RANGEFINDER_ENABLED
375
MSG_RANGEFINDER,
376
#endif
377
MSG_DISTANCE_SENSOR,
378
#if AP_BATTERY_ENABLED
379
MSG_BATTERY_STATUS,
380
#endif
381
#if HAL_MOUNT_ENABLED
382
MSG_GIMBAL_DEVICE_ATTITUDE_STATUS,
383
#endif
384
#if AP_OPTICALFLOW_ENABLED
385
MSG_OPTICAL_FLOW,
386
#endif
387
#if COMPASS_CAL_ENABLED
388
MSG_MAG_CAL_REPORT,
389
MSG_MAG_CAL_PROGRESS,
390
#endif
391
MSG_EKF_STATUS_REPORT,
392
MSG_VIBRATION,
393
#if AP_RPM_ENABLED
394
MSG_RPM,
395
#endif
396
#if HAL_WITH_ESC_TELEM
397
MSG_ESC_TELEMETRY,
398
#endif
399
#if HAL_GENERATOR_ENABLED
400
MSG_GENERATOR_STATUS,
401
#endif
402
};
403
static const ap_message STREAM_PARAMS_msgs[] = {
404
MSG_NEXT_PARAM,
405
MSG_AVAILABLE_MODES
406
};
407
static const ap_message STREAM_ADSB_msgs[] = {
408
MSG_ADSB_VEHICLE,
409
#if AP_AIS_ENABLED
410
MSG_AIS_VESSEL,
411
#endif
412
};
413
414
const struct GCS_MAVLINK::stream_entries GCS_MAVLINK::all_stream_entries[] = {
415
MAV_STREAM_ENTRY(STREAM_RAW_SENSORS),
416
MAV_STREAM_ENTRY(STREAM_EXTENDED_STATUS),
417
MAV_STREAM_ENTRY(STREAM_POSITION),
418
MAV_STREAM_ENTRY(STREAM_RC_CHANNELS),
419
MAV_STREAM_ENTRY(STREAM_EXTRA1),
420
MAV_STREAM_ENTRY(STREAM_EXTRA2),
421
MAV_STREAM_ENTRY(STREAM_EXTRA3),
422
MAV_STREAM_ENTRY(STREAM_ADSB),
423
MAV_STREAM_ENTRY(STREAM_PARAMS),
424
MAV_STREAM_TERMINATOR // must have this at end of stream_entries
425
};
426
427
void GCS_MAVLINK_Blimp::packetReceived(const mavlink_status_t &status,
428
const mavlink_message_t &msg)
429
{
430
GCS_MAVLINK::packetReceived(status, msg);
431
}
432
433
bool GCS_MAVLINK_Blimp::params_ready() const
434
{
435
if (AP_BoardConfig::in_config_error()) {
436
// we may never have parameters "initialised" in this case
437
return true;
438
}
439
// if we have not yet initialised (including allocating the motors
440
// object) we drop this request. That prevents the GCS from getting
441
// a confusing parameter count during bootup
442
return blimp.ap.initialised_params;
443
}
444
445
void GCS_MAVLINK_Blimp::send_banner()
446
{
447
GCS_MAVLINK::send_banner();
448
send_text(MAV_SEVERITY_INFO, "Frame: %s", blimp.get_frame_string());
449
}
450
451
MAV_RESULT GCS_MAVLINK_Blimp::_handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
452
{
453
return GCS_MAVLINK::_handle_command_preflight_calibration(packet, msg);
454
}
455
456
457
MAV_RESULT GCS_MAVLINK_Blimp::handle_command_do_set_roi(const Location &roi_loc)
458
{
459
if (!roi_loc.check_latlng()) {
460
return MAV_RESULT_FAILED;
461
}
462
// blimp.flightmode->auto_yaw.set_roi(roi_loc);
463
return MAV_RESULT_ACCEPTED;
464
}
465
466
MAV_RESULT GCS_MAVLINK_Blimp::handle_command_int_do_reposition(const mavlink_command_int_t &packet)
467
{
468
const bool change_modes = ((int32_t)packet.param2 & MAV_DO_REPOSITION_FLAGS_CHANGE_MODE) == MAV_DO_REPOSITION_FLAGS_CHANGE_MODE;
469
if (!blimp.flightmode->in_guided_mode() && !change_modes) {
470
return MAV_RESULT_DENIED;
471
}
472
473
// sanity check location
474
if (!check_latlng(packet.x, packet.y)) {
475
return MAV_RESULT_DENIED;
476
}
477
478
Location request_location {};
479
if (!location_from_command_t(packet, request_location)) {
480
return MAV_RESULT_DENIED;
481
}
482
483
if (request_location.sanitize(blimp.current_loc)) {
484
// if the location wasn't already sane don't load it
485
return MAV_RESULT_DENIED; // failed as the location is not valid
486
}
487
488
return MAV_RESULT_ACCEPTED;
489
}
490
491
MAV_RESULT GCS_MAVLINK_Blimp::handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
492
{
493
switch (packet.command) {
494
case MAV_CMD_DO_REPOSITION:
495
return handle_command_int_do_reposition(packet);
496
case MAV_CMD_NAV_TAKEOFF:
497
return MAV_RESULT_ACCEPTED;
498
default:
499
return GCS_MAVLINK::handle_command_int_packet(packet, msg);
500
}
501
}
502
503
#if AP_MAVLINK_COMMAND_LONG_ENABLED
504
bool GCS_MAVLINK_Blimp::mav_frame_for_command_long(MAV_FRAME &frame, MAV_CMD packet_command) const
505
{
506
if (packet_command == MAV_CMD_NAV_TAKEOFF) {
507
frame = MAV_FRAME_GLOBAL_RELATIVE_ALT;
508
return true;
509
}
510
return GCS_MAVLINK::mav_frame_for_command_long(frame, packet_command);
511
}
512
#endif
513
514
void GCS_MAVLINK_Blimp::handle_message(const mavlink_message_t &msg)
515
{
516
switch (msg.msgid) {
517
518
case MAVLINK_MSG_ID_TERRAIN_DATA:
519
case MAVLINK_MSG_ID_TERRAIN_CHECK:
520
break;
521
522
default:
523
GCS_MAVLINK::handle_message(msg);
524
break;
525
} // end switch
526
} // end handle mavlink
527
528
529
MAV_RESULT GCS_MAVLINK_Blimp::handle_flight_termination(const mavlink_command_int_t &packet)
530
{
531
MAV_RESULT result = MAV_RESULT_FAILED;
532
if (packet.param1 > 0.5f) {
533
blimp.arming.disarm(AP_Arming::Method::TERMINATION);
534
result = MAV_RESULT_ACCEPTED;
535
}
536
return result;
537
}
538
539
float GCS_MAVLINK_Blimp::vfr_hud_alt() const
540
{
541
if (blimp.g2.dev_options.get() & DevOptionVFR_HUDRelativeAlt) {
542
// compatibility option for older mavlink-aware devices that
543
// assume Blimp returns a relative altitude in VFR_HUD.alt
544
return blimp.current_loc.alt * 0.01f;
545
}
546
return GCS_MAVLINK::vfr_hud_alt();
547
}
548
549
uint64_t GCS_MAVLINK_Blimp::capabilities() const
550
{
551
return (MAV_PROTOCOL_CAPABILITY_MISSION_FLOAT |
552
MAV_PROTOCOL_CAPABILITY_MISSION_INT |
553
MAV_PROTOCOL_CAPABILITY_COMMAND_INT |
554
MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED |
555
MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_GLOBAL_INT |
556
MAV_PROTOCOL_CAPABILITY_FLIGHT_TERMINATION |
557
MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET |
558
GCS_MAVLINK::capabilities());
559
}
560
561
MAV_LANDED_STATE GCS_MAVLINK_Blimp::landed_state() const
562
{
563
if (blimp.ap.land_complete) {
564
return MAV_LANDED_STATE_ON_GROUND;
565
}
566
if (blimp.flightmode->is_landing()) {
567
return MAV_LANDED_STATE_LANDING;
568
}
569
// if (blimp.flightmode->is_taking_off()) {
570
// return MAV_LANDED_STATE_TAKEOFF;
571
// }
572
return MAV_LANDED_STATE_IN_AIR;
573
}
574
575
void GCS_MAVLINK_Blimp::send_wind() const
576
{
577
Vector3f airspeed_vec_bf;
578
if (!AP::ahrs().airspeed_vector_true(airspeed_vec_bf)) {
579
// if we don't have an airspeed estimate then we don't have a
580
// valid wind estimate on blimps
581
return;
582
}
583
const Vector3f wind = AP::ahrs().wind_estimate();
584
mavlink_msg_wind_send(
585
chan,
586
degrees(atan2f(-wind.y, -wind.x)),
587
wind.length(),
588
wind.z);
589
}
590
591
#if HAL_HIGH_LATENCY2_ENABLED
592
uint8_t GCS_MAVLINK_Blimp::high_latency_wind_speed() const
593
{
594
Vector3f airspeed_vec_bf;
595
if (!AP::ahrs().airspeed_vector_true(airspeed_vec_bf)) {
596
// if we don't have an airspeed estimate then we don't have a
597
// valid wind estimate on blimps
598
return 0;
599
}
600
// return units are m/s*5
601
const Vector3f wind = AP::ahrs().wind_estimate();
602
return wind.length() * 5;
603
}
604
605
uint8_t GCS_MAVLINK_Blimp::high_latency_wind_direction() const
606
{
607
Vector3f airspeed_vec_bf;
608
if (!AP::ahrs().airspeed_vector_true(airspeed_vec_bf)) {
609
// if we don't have an airspeed estimate then we don't have a
610
// valid wind estimate on blimps
611
return 0;
612
}
613
const Vector3f wind = AP::ahrs().wind_estimate();
614
// need to convert -180->180 to 0->360/2
615
return wrap_360(degrees(atan2f(-wind.y, -wind.x))) / 2;
616
}
617
#endif // HAL_HIGH_LATENCY2_ENABLED
618
619
// Send the mode with the given index (not mode number!) return the total number of modes
620
// Index starts at 1
621
uint8_t GCS_MAVLINK_Blimp::send_available_mode(uint8_t index) const
622
{
623
const Mode* modes[] {
624
&blimp.mode_land,
625
&blimp.mode_manual,
626
&blimp.mode_velocity,
627
&blimp.mode_loiter,
628
&blimp.mode_rtl,
629
};
630
631
const uint8_t mode_count = ARRAY_SIZE(modes);
632
633
// Convert to zero indexed
634
const uint8_t index_zero = index - 1;
635
if (index_zero >= mode_count) {
636
// Mode does not exist!?
637
return mode_count;
638
}
639
640
// Ask the mode for its name and number
641
const char* name = modes[index_zero]->name();
642
const uint8_t mode_number = (uint8_t)modes[index_zero]->number();
643
644
mavlink_msg_available_modes_send(
645
chan,
646
mode_count,
647
index,
648
MAV_STANDARD_MODE::MAV_STANDARD_MODE_NON_STANDARD,
649
mode_number,
650
0, // MAV_MODE_PROPERTY bitmask
651
name
652
);
653
654
return mode_count;
655
}
656
657