mirror of https://github.com/ArduPilot/ardupilot
Rover: report smaller of two sonar distances
This commit is contained in:
parent
ad7e8bd9c4
commit
9eaa764f42
|
@ -418,10 +418,33 @@ static void NOINLINE send_hwstatus(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(
|
||||
chan,
|
||||
sonar.distance_cm() * 0.01,
|
||||
sonar.voltage());
|
||||
distance_cm * 0.01f,
|
||||
voltage);
|
||||
}
|
||||
|
||||
static void NOINLINE send_current_waypoint(mavlink_channel_t chan)
|
||||
|
|
Loading…
Reference in New Issue