Skip to content

Commit ad14796

Browse files
committed
mavlink: GLOBAL_POSITION_INT send without lat/lon availability
- the altitude and velocity portions of this message are still relevant without GPS lat/lon
1 parent 9d97148 commit ad14796

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

src/modules/mavlink/mavlink_messages.cpp

+36-17
Original file line numberDiff line numberDiff line change
@@ -2424,52 +2424,71 @@ class MavlinkStreamGlobalPositionInt : public MavlinkStream
24242424

24252425
bool send(const hrt_abstime t) override
24262426
{
2427-
vehicle_global_position_s gpos;
24282427
vehicle_local_position_s lpos;
24292428

2430-
if (_gpos_sub.update(&gpos) && _lpos_sub.update(&lpos)) {
2431-
2429+
if (_lpos_sub.update(&lpos)) {
24322430
mavlink_global_position_int_t msg{};
24332431

2432+
// time_boot_ms: Timestamp (time since system boot) in ms.
2433+
msg.time_boot_ms = lpos.timestamp / 1000;
2434+
2435+
// alt: Altitude (MSL) in mm.
24342436
if (lpos.z_valid && lpos.z_global) {
2435-
msg.alt = (-lpos.z + lpos.ref_alt) * 1000.0f;
2437+
msg.alt = (-lpos.z + lpos.ref_alt) * 1000.f;
24362438

24372439
} else {
24382440
// fall back to baro altitude
24392441
vehicle_air_data_s air_data{};
2440-
_air_data_sub.copy(&air_data);
24412442

2442-
if (air_data.timestamp > 0) {
2443-
msg.alt = air_data.baro_alt_meter * 1000.0f;
2443+
if (_air_data_sub.copy(&air_data) && (hrt_elapsed_time(&air_data.timestamp) < 10_s)) {
2444+
msg.alt = air_data.baro_alt_meter * 1000.f;
24442445
}
24452446
}
24462447

2448+
// relative_alt: Altitude above ground in mm
24472449
home_position_s home{};
24482450
_home_sub.copy(&home);
24492451

24502452
if ((home.timestamp > 0) && home.valid_alt) {
24512453
if (lpos.z_valid) {
2452-
msg.relative_alt = -(lpos.z - home.z) * 1000.0f;
2454+
msg.relative_alt = -(lpos.z - home.z) * 1000.f;
24532455

24542456
} else {
2455-
msg.relative_alt = msg.alt - (home.alt * 1000.0f);
2457+
msg.relative_alt = msg.alt - (home.alt * 1000.f);
24562458
}
24572459

24582460
} else {
24592461
if (lpos.z_valid) {
2460-
msg.relative_alt = -lpos.z * 1000.0f;
2462+
msg.relative_alt = -lpos.z * 1000.f;
24612463
}
24622464
}
24632465

2464-
msg.time_boot_ms = gpos.timestamp / 1000;
2465-
msg.lat = gpos.lat * 1e7;
2466-
msg.lon = gpos.lon * 1e7;
2466+
// lat, lon: Latitude, Longitude in degE7
2467+
vehicle_global_position_s gpos{};
24672468

2468-
msg.vx = lpos.vx * 100.0f;
2469-
msg.vy = lpos.vy * 100.0f;
2470-
msg.vz = lpos.vz * 100.0f;
2469+
if (_gpos_sub.copy(&gpos) && (hrt_elapsed_time(&gpos.timestamp) < 10_s)) {
2470+
msg.lat = gpos.lat * 1e7;
2471+
msg.lon = gpos.lon * 1e7;
2472+
}
2473+
2474+
// vx, vy: Ground X, Y Speed (Latitude, positive north) in cm/s
2475+
if (lpos.v_xy_valid) {
2476+
msg.vx = lpos.vx * 100.f;
2477+
msg.vy = lpos.vy * 100.f;
2478+
}
24712479

2472-
msg.hdg = math::degrees(wrap_2pi(lpos.yaw)) * 100.0f;
2480+
// vz: Ground Z Speed (Altitude, positive down) in cm/s
2481+
if (lpos.v_z_valid) {
2482+
msg.vz = lpos.vz * 100.f;
2483+
}
2484+
2485+
// hdg: Vehicle heading (yaw angle) in cdeg, 0.0..359.99 degrees. If unknown, set to: UINT16_MAX
2486+
if (PX4_ISFINITE(lpos.yaw)) {
2487+
msg.hdg = math::degrees(wrap_2pi(lpos.yaw)) * 100.f;
2488+
2489+
} else {
2490+
msg.hdg = UINT16_MAX;
2491+
}
24732492

24742493
mavlink_msg_global_position_int_send_struct(_mavlink->get_channel(), &msg);
24752494

0 commit comments

Comments
 (0)