Skip to content
Open
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12354,6 +12354,73 @@ def my_message_hook(mav, m):
if len(wanted_distances.keys()) == 0:
break

def MAVLinkRangeFinderIDs(self):
'''test multiple MAVLink rangefinders selected by DISTANCE_SENSOR id'''
self.context_push()
try:
self.set_parameters({
"SERIAL5_PROTOCOL": 1,
"RNGFND1_TYPE": 10,
"RNGFND1_ADDR": 1,
"RNGFND2_TYPE": 10,
"RNGFND2_ADDR": 2,
})
self.reboot_sitl()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?!


# we are interacting with the autopilot, reduce chance of
# hitting timeouts on supplied data:
self.context_set_speedup(1)
Comment on lines +12370 to +12372

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# we are interacting with the autopilot, reduce chance of
# hitting timeouts on supplied data:
self.context_set_speedup(1)

self.context_set_message_rate_hz("DISTANCE_SENSOR", 10)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was leaking into subsequent tests, thus the extra push/pop


self.context_collect("DISTANCE_SENSOR")
input_distances = {
1: 20,
2: 30,
}
for _ in range(10):
for input_id, distance_cm in input_distances.items():
self.mav.mav.distance_sensor_send(
0, # time_boot_ms
10, # min_distance
50, # max_distance
distance_cm, # current_distance
mavutil.mavlink.MAV_DISTANCE_SENSOR_LASER, # type
input_id, # id
mavutil.mavlink.MAV_SENSOR_ROTATION_PITCH_270, # orientation
255 # covariance
)
self.delay_sim_time(0.1, reason="collect rangefinder output")

messages = self.context_collection("DISTANCE_SENSOR")
self.context_stop_collecting("DISTANCE_SENSOR")
if not messages:
raise NotAchievedException("Did not receive DISTANCE_SENSOR output")

output_distances = {
0: input_distances[1],
1: input_distances[2],
}
seen_ids = set()
for message in messages:
if message.id not in output_distances:
raise NotAchievedException(
"Unexpected MAVLink rangefinder backend id %u" % message.id)
distance_cm = output_distances[message.id]
if abs(message.current_distance - distance_cm) > 1:
raise NotAchievedException(
"MAVLink rangefinder distance mismatch "
"(backend=%u want=%u got=%u)" %
(message.id, distance_cm, message.current_distance))
seen_ids.add(message.id)

if seen_ids != set(output_distances.keys()):
raise NotAchievedException(
"Did not receive output from all MAVLink rangefinder backends "
"(want=%s got=%s)" %
(sorted(output_distances.keys()), sorted(seen_ids)))
finally:
self.context_pop()

def fly_rangefinder_mavlink_distance_sensor(self):
self.start_subtest("Test mavlink rangefinder using DISTANCE_SENSOR messages")
self.context_push()
Expand Down Expand Up @@ -15776,6 +15843,7 @@ def tests1e(self):
self.ModeFollow,
self.ModeFollow_with_FOLLOW_TARGET,
self.RangeFinderDrivers,
self.MAVLinkRangeFinderIDs,
self.FlyRangeFinderMAVlink,
self.FlyRangeFinderSITL,
self.RangeFinderDriversMaxAlt_LightwareSerial,
Expand Down
5 changes: 3 additions & 2 deletions libraries/AP_RangeFinder/AP_RangeFinder_MAVLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ void AP_RangeFinder_MAVLink::handle_msg(const mavlink_message_t &msg)
mavlink_distance_sensor_t packet;
mavlink_msg_distance_sensor_decode(&msg, &packet);

// only accept distances for the configured orientation
if (packet.orientation == orientation()) {
// only accept distances for the configured orientation and sensor ID
if (packet.orientation == orientation() &&
(params.address == 0 || params.address == packet.id)) {
state.last_reading_ms = AP_HAL::millis();
distance = packet.current_distance * 0.01;
_max_distance = packet.max_distance * 0.01;
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const AP_Param::GroupInfo AP_RangeFinder_Params::var_info[] = {

// @Param: ADDR
// @DisplayName: Bus address of sensor
// @Description: This sets the bus address of the sensor, where applicable. Used for the I2C and DroneCAN sensors to allow for multiple sensors on different addresses.
// @Description: This sets the bus address of the sensor, where applicable. Used for the I2C and DroneCAN sensors to allow for multiple sensors on different addresses. For MAVLink rangefinders, this sets the DISTANCE_SENSOR message id to accept. A value of zero accepts any id.
// @Range: 0 127
// @Increment: 1
// @User: Standard
Expand Down
Loading