Skip to content

Commit fab9874

Browse files
authored
Mavlink: GLOBAL_POSITION for aux positioning (#26307)
* mavlink: add GLOBAL_POSITION message handling - Add handler for incoming GLOBAL_POSITION MAVLink messages - Publish received positions to aux_global_position uORB topic - Update GLOBAL_POSITION stream to use aux_global_position topic * correctly handle multi AGP in mavlink pub * move from GLOBAL_POSITION to GLOBAL_POSITION_SENSOR * mavlink: update submodule to include GLOBAL_POSITION_SENSOR in common.xml
1 parent 726cb2c commit fab9874

File tree

6 files changed

+78
-52
lines changed

6 files changed

+78
-52
lines changed

src/modules/mavlink/mavlink_main.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream)
14361436
configure_stream_local("GIMBAL_DEVICE_ATTITUDE_STATUS", 5.0f);
14371437
configure_stream_local("GIMBAL_DEVICE_SET_ATTITUDE", 5.0f);
14381438
configure_stream_local("GIMBAL_MANAGER_STATUS", 0.5f);
1439-
#if defined(MAVLINK_MSG_ID_GLOBAL_POSITION)
1440-
configure_stream_local("GLOBAL_POSITION", 5.0f);
1441-
#endif
1439+
configure_stream_local("GLOBAL_POSITION_SENSOR", 5.0f);
14421440
configure_stream_local("GLOBAL_POSITION_INT", 5.0f);
14431441
#if defined(MAVLINK_MSG_ID_GNSS_INTEGRITY)
14441442
configure_stream_local("GNSS_INTEGRITY", 1.0f);
@@ -1779,9 +1777,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream)
17791777
configure_stream_local("CURRENT_MODE", 0.5f);
17801778
configure_stream_local("ESTIMATOR_STATUS", 1.0f);
17811779
configure_stream_local("EXTENDED_SYS_STATE", 1.0f);
1782-
#if defined(MAVLINK_MSG_ID_GLOBAL_POSITION)
1783-
configure_stream_local("GLOBAL_POSITION", 10.0f);
1784-
#endif
1780+
configure_stream_local("GLOBAL_POSITION_SENSOR", 10.0f);
17851781
configure_stream_local("GLOBAL_POSITION_INT", 10.0f);
17861782
configure_stream_local("GPS_GLOBAL_ORIGIN", 1.0f);
17871783
#if defined(MAVLINK_MSG_ID_GNSS_INTEGRITY)
@@ -1847,9 +1843,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream)
18471843
configure_stream_local("ESTIMATOR_STATUS", 1.0f);
18481844
configure_stream_local("EXTENDED_SYS_STATE", 0.5f);
18491845
configure_stream_local("GLOBAL_POSITION_INT", 2.0f);
1850-
#if defined(MAVLINK_MSG_ID_GLOBAL_POSITION)
1851-
configure_stream_local("GLOBAL_POSITION", 2.0f);
1852-
#endif
1846+
configure_stream_local("GLOBAL_POSITION_SENSOR", 2.0f);
18531847
configure_stream_local("GPS_GLOBAL_ORIGIN", 1.0f);
18541848
configure_stream_local("GPS2_RAW", 2.0f);
18551849
configure_stream_local("GPS_RAW_INT", 2.0f);

src/modules/mavlink/mavlink_messages.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@
7575
#include "streams/ESTIMATOR_STATUS.hpp"
7676
#include "streams/EXTENDED_SYS_STATE.hpp"
7777
#include "streams/FLIGHT_INFORMATION.hpp"
78-
#if defined(MAVLINK_MSG_ID_GLOBAL_POSITION)
79-
#include "streams/GLOBAL_POSITION.hpp"
80-
#endif //MAVLINK_MSG_ID_GLOBAL_POSITION
78+
#include "streams/GLOBAL_POSITION_SENSOR.hpp"
8179
#include "streams/GLOBAL_POSITION_INT.hpp"
8280
#if defined(MAVLINK_MSG_ID_GNSS_INTEGRITY)
8381
#include "streams/GNSS_INTEGRITY.hpp"
@@ -519,9 +517,9 @@ static const StreamListItem streams_list[] = {
519517
#if defined(CURRENT_MODE_HPP)
520518
create_stream_list_item<MavlinkStreamCurrentMode>(),
521519
#endif // CURRENT_MODE_HPP
522-
#if defined(GLOBAL_POSITION_HPP)
523-
create_stream_list_item<MavlinkStreamGLobalPosition>(),
524-
#endif // GLOBAL_POSITION_HPP
520+
#if defined(GLOBAL_POSITION_SENSOR_HPP)
521+
create_stream_list_item<MavlinkStreamGlobalPositionSensor>(),
522+
#endif // GLOBAL_POSITION_SENSOR_HPP
525523
};
526524

527525
const char *get_stream_name(const uint16_t msg_id)

src/modules/mavlink/mavlink_receiver.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ MavlinkReceiver::handle_message(mavlink_message_t *msg)
213213
handle_message_follow_target(msg);
214214
break;
215215

216+
case MAVLINK_MSG_ID_GLOBAL_POSITION_SENSOR:
217+
handle_message_global_position_sensor(msg);
218+
break;
219+
216220
case MAVLINK_MSG_ID_LANDING_TARGET:
217221
handle_message_landing_target(msg);
218222
break;
@@ -2492,6 +2496,31 @@ MavlinkReceiver::handle_message_hil_gps(mavlink_message_t *msg)
24922496
_sensor_gps_pub.publish(gps);
24932497
}
24942498

2499+
void
2500+
MavlinkReceiver::handle_message_global_position_sensor(mavlink_message_t *msg)
2501+
{
2502+
mavlink_global_position_sensor_t global_pos;
2503+
mavlink_msg_global_position_sensor_decode(msg, &global_pos);
2504+
2505+
aux_global_position_s aux_global_position{};
2506+
const hrt_abstime now = hrt_absolute_time();
2507+
aux_global_position.timestamp = now;
2508+
aux_global_position.timestamp_sample = now;
2509+
2510+
aux_global_position.id = global_pos.id;
2511+
aux_global_position.source = global_pos.source;
2512+
2513+
aux_global_position.lat = global_pos.lat * 1e-7;
2514+
aux_global_position.lon = global_pos.lon * 1e-7;
2515+
aux_global_position.alt = global_pos.alt;
2516+
2517+
aux_global_position.lat_lon_reset_counter = 0;
2518+
aux_global_position.eph = global_pos.eph;
2519+
aux_global_position.epv = global_pos.epv;
2520+
2521+
_aux_global_position_pub.publish(aux_global_position);
2522+
}
2523+
24952524
void
24962525
MavlinkReceiver::handle_message_follow_target(mavlink_message_t *msg)
24972526
{

src/modules/mavlink/mavlink_receiver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#include <uORB/topics/vehicle_rates_setpoint.h>
112112
#include <uORB/topics/vehicle_status.h>
113113
#include <uORB/topics/velocity_limits.h>
114+
#include <uORB/topics/aux_global_position.h>
114115

115116
#if !defined(CONSTRAINED_FLASH)
116117
# include <uORB/topics/debug_array.h>
@@ -208,7 +209,7 @@ class MavlinkReceiver : public ModuleParams
208209
void handle_message_gimbal_manager_set_manual_control(mavlink_message_t *msg);
209210
void handle_message_gimbal_device_information(mavlink_message_t *msg);
210211
void handle_message_gimbal_device_attitude_status(mavlink_message_t *msg);
211-
212+
void handle_message_global_position_sensor(mavlink_message_t *msg);
212213
#if !defined(CONSTRAINED_FLASH)
213214
void handle_message_debug(mavlink_message_t *msg);
214215
void handle_message_debug_float_array(mavlink_message_t *msg);
@@ -329,7 +330,6 @@ class MavlinkReceiver : public ModuleParams
329330
uORB::Publication<vehicle_odometry_s> _mocap_odometry_pub{ORB_ID(vehicle_mocap_odometry)};
330331
uORB::Publication<vehicle_odometry_s> _visual_odometry_pub{ORB_ID(vehicle_visual_odometry)};
331332
uORB::Publication<vehicle_rates_setpoint_s> _rates_sp_pub{ORB_ID(vehicle_rates_setpoint)};
332-
333333
#if !defined(CONSTRAINED_FLASH)
334334
uORB::Publication<debug_array_s> _debug_array_pub {ORB_ID(debug_array)};
335335
uORB::Publication<debug_key_value_s> _debug_key_value_pub{ORB_ID(debug_key_value)};
@@ -339,6 +339,7 @@ class MavlinkReceiver : public ModuleParams
339339

340340
// ORB publications (multi)
341341
uORB::PublicationMulti<distance_sensor_s> _distance_sensor_pub{ORB_ID(distance_sensor)};
342+
uORB::PublicationMulti<aux_global_position_s> _aux_global_position_pub{ORB_ID(aux_global_position)};
342343
uORB::PublicationMulti<gps_inject_data_s> _gps_inject_data_pub{ORB_ID(gps_inject_data)};
343344
uORB::PublicationMulti<input_rc_s> _rc_pub{ORB_ID(input_rc)};
344345
uORB::PublicationMulti<manual_control_setpoint_s> _manual_control_input_pub{ORB_ID(manual_control_input)};

src/modules/mavlink/streams/GLOBAL_POSITION.hpp renamed to src/modules/mavlink/streams/GLOBAL_POSITION_SENSOR.hpp

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,75 +31,79 @@
3131
*
3232
****************************************************************************/
3333

34-
#ifndef GLOBAL_POSITION_HPP
35-
#define GLOBAL_POSITION_HPP
34+
#ifndef GLOBAL_POSITION_SENSOR_HPP
35+
#define GLOBAL_POSITION_SENSOR_HPP
3636

3737
#include <stdint.h>
3838

3939
#include <uORB/topics/aux_global_position.h>
4040

41-
class MavlinkStreamGLobalPosition : public MavlinkStream
41+
class MavlinkStreamGlobalPositionSensor : public MavlinkStream
4242
{
4343
public:
44-
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGLobalPosition(mavlink); }
44+
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGlobalPositionSensor(mavlink); }
4545

46-
static constexpr const char *get_name_static() { return "GLOBAL_POSITION"; }
47-
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_GLOBAL_POSITION; }
46+
static constexpr const char *get_name_static() { return "GLOBAL_POSITION_SENSOR"; }
47+
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_GLOBAL_POSITION_SENSOR; }
4848

4949
const char *get_name() const override { return get_name_static(); }
5050
uint16_t get_id() override { return get_id_static(); }
5151

5252
unsigned get_size() override
5353
{
54-
return _aux_global_position_sub.advertised() ? (MAVLINK_MSG_ID_GLOBAL_POSITION_LEN +
54+
return _aux_global_position_sub.advertised() ? (MAVLINK_MSG_ID_GLOBAL_POSITION_SENSOR_LEN +
5555
MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
5656
}
5757

5858
private:
59-
explicit MavlinkStreamGLobalPosition(Mavlink *mavlink) : MavlinkStream(mavlink) {}
59+
explicit MavlinkStreamGlobalPositionSensor(Mavlink *mavlink) : MavlinkStream(mavlink) {}
6060

61-
uORB::Subscription _aux_global_position_sub{ORB_ID(aux_global_position)};
61+
uORB::SubscriptionMultiArray<aux_global_position_s, 4> _aux_global_position_sub{ORB_ID::aux_global_position};
6262

6363
bool send() override
6464
{
65-
vehicle_global_position_s pos{};
65+
aux_global_position_s pos{};
66+
bool sent = false;
6667

67-
if (_aux_global_position_sub.update(&pos)) {
68-
mavlink_global_position_t msg{};
68+
for (int i = 0; i < _aux_global_position_sub.size(); i++) {
69+
if (_aux_global_position_sub[i].update(&pos)) {
70+
mavlink_global_position_sensor_t msg{};
6971

70-
msg.id = UINT8_C(1);
71-
msg.time_usec = pos.timestamp;
72-
msg.source = GLOBAL_POSITION_UNKNOWN;
73-
msg.flags = 0;
72+
msg.target_system = 0;
73+
msg.target_component = 0;
74+
msg.id = pos.id;
75+
msg.time_usec = pos.timestamp;
76+
msg.source = pos.source;
7477

75-
if (PX4_ISFINITE(pos.lat)) {
76-
msg.lat = static_cast<int32_t>(pos.lat * 1e7);
78+
if (PX4_ISFINITE(pos.lat)) {
79+
msg.lat = static_cast<int32_t>(pos.lat * 1e7);
7780

78-
} else {
79-
msg.lat = INT32_MAX;
80-
}
81+
} else {
82+
msg.lat = INT32_MAX;
83+
}
8184

82-
if (PX4_ISFINITE(pos.lon)) {
83-
msg.lon = static_cast<int32_t>(pos.lon * 1e7);
85+
if (PX4_ISFINITE(pos.lon)) {
86+
msg.lon = static_cast<int32_t>(pos.lon * 1e7);
8487

85-
} else {
86-
msg.lon = INT32_MAX;
87-
}
88+
} else {
89+
msg.lon = INT32_MAX;
90+
}
8891

89-
msg.alt = pos.alt;
90-
msg.alt_ellipsoid = pos.alt_ellipsoid;
92+
msg.alt = pos.alt;
93+
msg.alt_ellipsoid = pos.alt;
9194

92-
msg.eph = pos.eph;
93-
msg.epv = pos.epv;
95+
msg.eph = pos.eph;
96+
msg.epv = pos.epv;
9497

9598

96-
mavlink_msg_global_position_send_struct(_mavlink->get_channel(), &msg);
99+
mavlink_msg_global_position_sensor_send_struct(_mavlink->get_channel(), &msg);
97100

98-
return true;
101+
sent = true;
102+
}
99103
}
100104

101-
return false;
105+
return sent;
102106
}
103107
};
104108

105-
#endif // GLOBAL_POSITION_HPP
109+
#endif // GLOBAL_POSITION_SENSOR_HPP

0 commit comments

Comments
 (0)