Skip to content

Commit 160cd7f

Browse files
committed
populate Fix2 with PX4 heading fields
1 parent 123fb59 commit 160cd7f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

AP_Periph/sensor_gps.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,23 @@ void AP_Periph_DroneCAN::can_gps_update(void)
147147
float vc3 = sq(sacc);
148148
pkt.covariance.data[3] = pkt.covariance.data[4] = pkt.covariance.data[5] = vc3;
149149
}
150+
151+
#if defined(HAL_PERIPH_ENABLE_GPS) && GPS_MOVING_BASELINE
152+
// PX4 relies on the ecef_position_velocity field for heading, heading offset and heading accuracy,
153+
// since there is no support for RelPosHeading as of 1.14 stable
154+
float yaw;
155+
float yaw_accuracy;
156+
uint32_t curr_timestamp;
157+
static float last_timestamp = 0;
158+
159+
if (gps.gps_yaw_deg(yaw, yaw_accuracy, curr_timestamp) && curr_timestamp != last_timestamp){
160+
pkt.ecef_position_velocity.len = 1;
161+
pkt.ecef_position_velocity.data[0].velocity_xyz[0] = wrap_PI(yaw * DEG_TO_RAD);
162+
pkt.ecef_position_velocity.data[0].velocity_xyz[1] = 0; // Offset already compensated for.
163+
pkt.ecef_position_velocity.data[0].velocity_xyz[2] = yaw_accuracy * DEG_TO_RAD;
164+
}
165+
last_timestamp = curr_timestamp;
166+
#endif
150167

151168
fix2_pub.broadcast(pkt);
152169
}

0 commit comments

Comments
 (0)