Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavlink: only send ATTITUDE/ATTITUDE_QUATERNION msgs on vehicle_attitude update #13184

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/modules/mavlink/mavlink_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,6 @@ class MavlinkStreamAttitude : public MavlinkStream
MavlinkOrbSubscription *_att_sub;
MavlinkOrbSubscription *_angular_velocity_sub;
uint64_t _att_time{0};
uint64_t _angular_velocity_time{0};

/* do not allow top copying this class */
MavlinkStreamAttitude(MavlinkStreamAttitude &) = delete;
Expand All @@ -1200,18 +1199,16 @@ class MavlinkStreamAttitude : public MavlinkStream

bool send(const hrt_abstime t)
{
bool updated = false;
vehicle_attitude_s att;

vehicle_attitude_s att{};
vehicle_angular_velocity_s angular_velocity{};
updated |= _att_sub->update(&_att_time, &att);
updated |= _angular_velocity_sub->update(&_angular_velocity_time, &angular_velocity);
if (_att_sub->update(&_att_time, &att)) {
vehicle_angular_velocity_s angular_velocity{};
_angular_velocity_sub->update(&angular_velocity);

if (updated) {
mavlink_attitude_t msg{};

const matrix::Eulerf euler = matrix::Quatf(att.q);
msg.time_boot_ms = math::max(angular_velocity.timestamp, att.timestamp) / 1000;
msg.time_boot_ms = att.timestamp / 1000;
msg.roll = euler.phi();
msg.pitch = euler.theta();
msg.yaw = euler.psi();
Expand Down Expand Up @@ -1267,7 +1264,6 @@ class MavlinkStreamAttitudeQuaternion : public MavlinkStream
MavlinkOrbSubscription *_att_sub;
MavlinkOrbSubscription *_angular_velocity_sub;
uint64_t _att_time{0};
uint64_t _angular_velocity_time{0};

/* do not allow top copying this class */
MavlinkStreamAttitudeQuaternion(MavlinkStreamAttitudeQuaternion &) = delete;
Expand All @@ -1281,17 +1277,15 @@ class MavlinkStreamAttitudeQuaternion : public MavlinkStream

bool send(const hrt_abstime t)
{
bool updated = false;
vehicle_attitude_s att;

vehicle_attitude_s att{};
vehicle_angular_velocity_s angular_velocity{};
updated |= _att_sub->update(&_att_time, &att);
updated |= _angular_velocity_sub->update(&_angular_velocity_time, &angular_velocity);
if (_att_sub->update(&_att_time, &att)) {
vehicle_angular_velocity_s angular_velocity{};
_angular_velocity_sub->update(&angular_velocity);

if (updated) {
mavlink_attitude_quaternion_t msg{};

msg.time_boot_ms = math::max(angular_velocity.timestamp, att.timestamp) / 1000;
msg.time_boot_ms = att.timestamp / 1000;
msg.q1 = att.q[0];
msg.q2 = att.q[1];
msg.q3 = att.q[2];
Expand Down