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

Rover: cycle through rangefinders when sending WATER_DEPTH #28877

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
78 changes: 78 additions & 0 deletions Rover/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,73 @@ void GCS_MAVLINK_Rover::send_rangefinder() const
distance,
voltage);
}

void GCS_MAVLINK_Rover::send_water_depth()
{
if (!HAVE_PAYLOAD_SPACE(chan, WATER_DEPTH)) {
return;
}

// only send for boats:
if (!rover.is_boat()) {
return;
}

RangeFinder *rangefinder = RangeFinder::get_singleton();

if (rangefinder == nullptr) {
return;
}

// depth can only be measured by a downward-facing rangefinder:
if (!rangefinder->has_orientation(ROTATION_PITCH_270)) {
return;
}

// get position
const AP_AHRS &ahrs = AP::ahrs();
Location loc;
IGNORE_RETURN(ahrs.get_location(loc));

const auto num_sensors = rangefinder->num_sensors();
for (uint8_t i=0; i<num_sensors; i++) {
last_WATER_DEPTH_index += 1;
if (last_WATER_DEPTH_index >= num_sensors) {
last_WATER_DEPTH_index = 0;
}

const AP_RangeFinder_Backend *s = rangefinder->get_backend(last_WATER_DEPTH_index);

if (s == nullptr || s->orientation() != ROTATION_PITCH_270 || !s->has_data()) {
continue;
}

// get temperature
float temp_C;
if (!s->get_temp(temp_C)) {
temp_C = 0.0f;
}

const bool sensor_healthy = (s->status() == RangeFinder::Status::Good);

mavlink_msg_water_depth_send(
chan,
AP_HAL::millis(), // time since system boot TODO: take time of measurement
last_WATER_DEPTH_index, // rangefinder instance
sensor_healthy, // sensor healthy
loc.lat, // latitude of vehicle
loc.lng, // longitude of vehicle
loc.alt * 0.01f, // altitude of vehicle (MSL)
ahrs.get_roll(), // roll in radians
ahrs.get_pitch(), // pitch in radians
ahrs.get_yaw(), // yaw in radians
s->distance(), // distance in meters
temp_C); // temperature in degC

break; // only send one WATER_DEPTH message per loop
}

}
#endif // AP_RANGEFINDER_ENABLED

/*
Expand Down Expand Up @@ -400,6 +467,13 @@ bool GCS_MAVLINK_Rover::try_send_message(enum ap_message id)
}
#endif

#if AP_RANGEFINDER_ENABLED
case MSG_WATER_DEPTH:
CHECK_PAYLOAD_SIZE(WATER_DEPTH);
send_water_depth();
break;
#endif // AP_RANGEFINDER_ENABLED

default:
return GCS_MAVLINK::try_send_message(id);
}
Expand Down Expand Up @@ -589,6 +663,7 @@ static const ap_message STREAM_EXTRA3_msgs[] = {
MSG_WIND,
#if AP_RANGEFINDER_ENABLED
MSG_RANGEFINDER,
MSG_WATER_DEPTH,
#endif
MSG_DISTANCE_SENSOR,
MSG_SYSTEM_TIME,
Expand Down Expand Up @@ -1206,3 +1281,6 @@ uint8_t GCS_MAVLINK_Rover::send_available_mode(uint8_t index) const

return mode_count;
}

#if AP_RANGEFINDER_ENABLED
#endif
7 changes: 7 additions & 0 deletions Rover/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class GCS_MAVLINK_Rover : public GCS_MAVLINK

#if AP_RANGEFINDER_ENABLED
void send_rangefinder() const override;

// send WATER_DEPTH - metres and temperature
void send_water_depth();
// state variable for the last rangefinder we sent a WATER_DEPTH
// message for. We cycle through the rangefinder backends to
// limit the amount of telemetry bandwidth we consume.
uint8_t last_WATER_DEPTH_index;
#endif

#if HAL_HIGH_LATENCY2_ENABLED
Expand Down
4 changes: 0 additions & 4 deletions Rover/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ void Rover::Log_Write_Depth()
(double)(s->distance()),
temp_C);
}
#if AP_RANGEFINDER_ENABLED
// send water depth and temp to ground station
gcs().send_message(MSG_WATER_DEPTH);
#endif
}
#endif

Expand Down
4 changes: 3 additions & 1 deletion Tools/autotest/rover.py
Original file line number Diff line number Diff line change
Expand Up @@ -6121,7 +6121,9 @@ def check_rangefinder(mav, m):
if not self.current_onboard_log_contains_message("DPTH"):
raise NotAchievedException("Expected DPTH log message")

# self.context_pop()
self.progress("Ensuring we get WATER_DEPTH at 12Hz with 2 backends")
self.set_message_rate_hz('WATER_DEPTH', 12)
self.assert_message_rate_hz('WATER_DEPTH', 12)

def EStopAtBoot(self):
'''Ensure EStop prevents arming when asserted at boot time'''
Expand Down
1 change: 0 additions & 1 deletion libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ class GCS_MAVLINK
#if AP_WINCH_ENABLED
virtual void send_winch_status() const {};
#endif
void send_water_depth() const;
int8_t battery_remaining_pct(const uint8_t instance) const;

#if HAL_HIGH_LATENCY2_ENABLED
Expand Down
58 changes: 0 additions & 58 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5966,57 +5966,6 @@ void GCS_MAVLINK::send_generator_status() const
}
#endif

#if AP_RANGEFINDER_ENABLED && APM_BUILD_TYPE(APM_BUILD_Rover)
void GCS_MAVLINK::send_water_depth() const
{
if (!HAVE_PAYLOAD_SPACE(chan, WATER_DEPTH)) {
return;
}

RangeFinder *rangefinder = RangeFinder::get_singleton();

if (rangefinder == nullptr || !rangefinder->has_orientation(ROTATION_PITCH_270)){
return;
}

// get position
const AP_AHRS &ahrs = AP::ahrs();
Location loc;
IGNORE_RETURN(ahrs.get_location(loc));

for (uint8_t i=0; i<rangefinder->num_sensors(); i++) {
const AP_RangeFinder_Backend *s = rangefinder->get_backend(i);

if (s == nullptr || s->orientation() != ROTATION_PITCH_270 || !s->has_data()) {
continue;
}

// get temperature
float temp_C;
if (!s->get_temp(temp_C)) {
temp_C = 0.0f;
}

const bool sensor_healthy = (s->status() == RangeFinder::Status::Good);

mavlink_msg_water_depth_send(
chan,
AP_HAL::millis(), // time since system boot TODO: take time of measurement
i, // rangefinder instance
sensor_healthy, // sensor healthy
loc.lat, // latitude of vehicle
loc.lng, // longitude of vehicle
loc.alt * 0.01f, // altitude of vehicle (MSL)
ahrs.get_roll(), // roll in radians
ahrs.get_pitch(), // pitch in radians
ahrs.get_yaw(), // yaw in radians
s->distance(), // distance in meters
temp_C); // temperature in degC
}

}
#endif // AP_RANGEFINDER_ENABLED && APM_BUILD_TYPE(APM_BUILD_Rover)

#if HAL_ADSB_ENABLED
void GCS_MAVLINK::send_uavionix_adsb_out_status() const
{
Expand Down Expand Up @@ -6547,13 +6496,6 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id)
break;
#endif

#if AP_RANGEFINDER_ENABLED && APM_BUILD_TYPE(APM_BUILD_Rover)
case MSG_WATER_DEPTH:
CHECK_PAYLOAD_SIZE(WATER_DEPTH);
send_water_depth();
break;
#endif

#if HAL_HIGH_LATENCY2_ENABLED
case MSG_HIGH_LATENCY2:
CHECK_PAYLOAD_SIZE(HIGH_LATENCY2);
Expand Down
Loading