Browse Source

Rover: report smaller of two sonar distances

master
Andrew Tridgell 12 years ago
parent
commit
9eaa764f42
  1. 27
      APMrover2/GCS_Mavlink.pde

27
APMrover2/GCS_Mavlink.pde

@ -418,10 +418,33 @@ static void NOINLINE send_hwstatus(mavlink_channel_t chan)
static void NOINLINE send_rangefinder(mavlink_channel_t chan) static void NOINLINE send_rangefinder(mavlink_channel_t chan)
{ {
if (!sonar.enabled()) {
// no sonar to report
return;
}
/*
report smaller distance of two sonars if more than one enabled
*/
float distance_cm, voltage;
if (!sonar2.enabled()) {
distance_cm = sonar.distance_cm();
voltage = sonar.voltage();
} else {
float dist1 = sonar.distance_cm();
float dist2 = sonar2.distance_cm();
if (dist1 <= dist2) {
distance_cm = dist1;
voltage = sonar.voltage();
} else {
distance_cm = dist2;
voltage = sonar2.voltage();
}
}
mavlink_msg_rangefinder_send( mavlink_msg_rangefinder_send(
chan, chan,
sonar.distance_cm() * 0.01, distance_cm * 0.01f,
sonar.voltage()); voltage);
} }
static void NOINLINE send_current_waypoint(mavlink_channel_t chan) static void NOINLINE send_current_waypoint(mavlink_channel_t chan)

Loading…
Cancel
Save