Skip to content

AP_RangeFinder: support multiple MAVLink rangefinders via RNGFNDn_ADDR - #33982

Open
tridge wants to merge 2 commits into
ArduPilot:masterfrom
tridge:pr-mavlink-rangefinder-id
Open

AP_RangeFinder: support multiple MAVLink rangefinders via RNGFNDn_ADDR#33982
tridge wants to merge 2 commits into
ArduPilot:masterfrom
tridge:pr-mavlink-rangefinder-id

Conversation

@tridge

@tridge tridge commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Allow multiple MAVLink rangefinders by using RNGFNDn_ADDR to select which DISTANCE_SENSOR message id each backend accepts.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

The existing Copter RangeFinder autotest is extended to configure two MAVLink
backends with RNGFND1_ADDR=1 and RNGFND2_ADDR=2, feed DISTANCE_SENSOR
messages with each id in turn, and check that the reported distance shows up on
the matching backend only.

Description

Previously the MAVLink rangefinder backend filtered incoming DISTANCE_SENSOR
messages on orientation only, so two MAVLink rangefinders with the same
orientation could not be distinguished and both backends consumed every message.

This adds an id filter based on the existing RNGFNDn_ADDR parameter:

  • RNGFNDn_ADDR of 0 keeps the old behaviour and accepts any DISTANCE_SENSOR id
  • a non-zero RNGFNDn_ADDR only accepts messages whose id field matches

The ADDR parameter documentation is updated to describe the MAVLink use.

@peterbarker peterbarker left a comment

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.

Code changes LGTM.

Approved after the test is fixed.

I'd actually prefer a completely new test for this functionality rather than shoving it into the existing test - but I'm not going to insist.

Comment thread Tools/autotest/arducopter.py Outdated
Comment on lines +12428 to +12432
self.context_stop_collecting("DISTANCE_SENSOR")
self.set_parameters({
"RNGFND1_ADDR": 0,
"RNGFND2_TYPE": 0,
})

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
self.context_stop_collecting("DISTANCE_SENSOR")
self.set_parameters({
"RNGFND1_ADDR": 0,
"RNGFND2_TYPE": 0,
})
self.context_pop()

Comment on lines -12370 to +12375
self.set_parameter("RNGFND1_TYPE", 10)
self.set_parameters({
"RNGFND1_TYPE": 10,
"RNGFND1_ADDR": 1,
"RNGFND2_TYPE": 10,
"RNGFND2_ADDR": 2,
})

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
self.set_parameter("RNGFND1_TYPE", 10)
self.set_parameters({
"RNGFND1_TYPE": 10,
"RNGFND1_ADDR": 1,
"RNGFND2_TYPE": 10,
"RNGFND2_ADDR": 2,
})
# we are interacting with the autopilot, reduce chance of
# hitting timeouts on supplied data:
self.context_set_speedup(1)
self.set_parameter("RNGFND1_TYPE", 10)
self.context_push()
self.set_parameters({
"RNGFND1_ADDR": 1,
"RNGFND2_TYPE": 10,
"RNGFND2_ADDR": 2,
})

"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?!

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

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)

# 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

@tridge
tridge force-pushed the pr-mavlink-rangefinder-id branch from f571626 to 0a08fd2 Compare August 9, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants