Skip to content

Commit c33eee2

Browse files
committed
GCS_MAVLink: add support for GLOBAL_POSITION message
1 parent cc3e334 commit c33eee2

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

libraries/GCS_MAVLink/GCS.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,14 @@ class GCS_MAVLINK
743743
virtual bool try_send_message(enum ap_message id);
744744
virtual void send_global_position_int();
745745

746+
#if AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
747+
void send_global_position();
748+
void send_global_position_primary();
749+
void send_global_position_secondary();
750+
void send_global_position_msg(uint8_t instance, uint8_t flags, const Location &loc);
751+
uint8_t send_global_position_next_to_send;
752+
#endif // AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
753+
746754
// message sending functions:
747755
bool try_send_mission_message(enum ap_message id);
748756
#if AP_MAVLINK_MSG_HWSTATUS_ENABLED

libraries/GCS_MAVLink/GCS_Common.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,9 @@ ap_message GCS_MAVLINK::mavlink_id_to_ap_message_id(const uint32_t mavlink_id) c
11031103
#endif // AP_AHRS_ENABLED
11041104
{ MAVLINK_MSG_ID_VFR_HUD, MSG_VFR_HUD},
11051105
#endif
1106+
#if AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
1107+
{ MAVLINK_MSG_ID_GLOBAL_POSITION_INT, MSG_GLOBAL_POSITION},
1108+
#endif // AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
11061109
#if AP_MAVLINK_MSG_HWSTATUS_ENABLED
11071110
{ MAVLINK_MSG_ID_HWSTATUS, MSG_HWSTATUS},
11081111
#endif // AP_MAVLINK_MSG_HWSTATUS_ENABLED
@@ -6131,6 +6134,70 @@ void GCS_MAVLINK::send_global_position_int()
61316134
#endif // AP_AHRS_ENABLED
61326135
}
61336136

6137+
#if AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
6138+
void GCS_MAVLINK::send_global_position()
6139+
{
6140+
if (send_global_position_next_to_send > 1) {
6141+
send_global_position_next_to_send = 0;
6142+
}
6143+
if (send_global_position_next_to_send == 0) {
6144+
GCS_MAVLINK::send_global_position_primary();
6145+
} else {
6146+
GCS_MAVLINK::send_global_position_secondary();
6147+
}
6148+
send_global_position_next_to_send++;
6149+
}
6150+
6151+
void GCS_MAVLINK::send_global_position_primary()
6152+
{
6153+
const AP_AHRS &ahrs = AP::ahrs();
6154+
6155+
uint8_t flags = 0;
6156+
flags |= GLOBAL_POSITION_PRIMARY;
6157+
6158+
Location loc;
6159+
if (!ahrs.get_location(loc)) {
6160+
flags |= GLOBAL_POSITION_UNHEALTHY;
6161+
}
6162+
6163+
return send_global_position_msg(0, flags, loc);
6164+
}
6165+
6166+
void GCS_MAVLINK::send_global_position_secondary()
6167+
{
6168+
const AP_AHRS &ahrs = AP::ahrs();
6169+
6170+
uint8_t flags = 0;
6171+
6172+
Location loc;
6173+
if (!ahrs.get_secondary_position(loc)) {
6174+
flags |= GLOBAL_POSITION_UNHEALTHY;
6175+
}
6176+
6177+
return send_global_position_msg(0, flags, loc);
6178+
}
6179+
6180+
void GCS_MAVLINK::send_global_position_msg(uint8_t instance, uint8_t flags, const Location &loc)
6181+
{
6182+
mavlink_msg_global_position_send(
6183+
chan,
6184+
0, // instance
6185+
AP_HAL::micros(), // time_usec
6186+
GLOBAL_POSITION_ESTIMATOR, // source
6187+
flags,
6188+
loc.lat, // in deg*1e7
6189+
loc.lng, // in deg*1e7
6190+
loc.alt * 0.01, // AMSL alt in metres
6191+
NaNf, // alt_ellipsoid in m
6192+
NaNf, // standard deviation of horizontal position error
6193+
NaNf // standard deviation of vertical position error
6194+
);
6195+
}
6196+
6197+
6198+
6199+
#endif // AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
6200+
61346201
#if HAL_MOUNT_ENABLED
61356202
void GCS_MAVLINK::send_gimbal_device_attitude_status() const
61366203
{
@@ -6439,6 +6506,13 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id)
64396506
break;
64406507
#endif // AP_AHRS_ENABLED
64416508

6509+
#if AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
6510+
case MSG_GLOBAL_POSITION:
6511+
CHECK_PAYLOAD_SIZE(GLOBAL_POSITION);
6512+
send_global_position();
6513+
break;
6514+
#endif // AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
6515+
64426516
#if AP_RPM_ENABLED
64436517
case MSG_RPM:
64446518
CHECK_PAYLOAD_SIZE(RPM);

libraries/GCS_MAVLink/GCS_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#define HAL_MAVLINK_INTERVALS_FROM_FILES_ENABLED ((AP_FILESYSTEM_FATFS_ENABLED || AP_FILESYSTEM_LITTLEFS_ENABLED || AP_FILESYSTEM_POSIX_ENABLED) && HAL_PROGRAM_SIZE_LIMIT_KB > 1024)
5353
#endif
5454

55+
#ifndef AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
56+
#define AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED AP_AHRS_ENABLED
57+
#endif
58+
5559
#ifndef AP_MAVLINK_MSG_RELAY_STATUS_ENABLED
5660
#define AP_MAVLINK_MSG_RELAY_STATUS_ENABLED HAL_GCS_ENABLED && AP_RELAY_ENABLED
5761
#endif

libraries/GCS_MAVLink/ap_message.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,9 @@ enum ap_message : uint8_t {
115115
#if AP_MAVLINK_MSG_FLIGHT_INFORMATION_ENABLED
116116
MSG_FLIGHT_INFORMATION = 100,
117117
#endif
118+
#if AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
119+
MSG_GLOBAL_POSITION = 101,
120+
#endif // AP_MAVLINK_MSG_GLOBAL_POSITION_ENABLED
121+
118122
MSG_LAST // MSG_LAST must be the last entry in this enum
119123
};

0 commit comments

Comments
 (0)