Skip to content

Conversation

@srmainwaring
Copy link
Contributor

Ensure rc overrides are applied to the vehicle on the current link, or all vehicles if alllinks is used.

Current behaviour is that the rc override is always applied to the vehicle with the highest link number, regardless of which sysid is active.

Single vehicle behaviour is unchanged.

Example

Start a multi-vehicle session:

sim_vehicle.py --debug -v Rover -f rover --count 3 --auto-sysid --location CMAC --auto-offset-line 90,5 --console --map              

Arm all the vehicles

allinks arm throttle

Ensure vehicle 1 (link 0) is active

vehicle 1

Set the throttle

rc 3 1600

Before this change vehicle 3 will move forward, after this change vehicle 1 will move forward.

Also tested in Gazebo flying two Zephyr's.

chan16 = self.override[:16]
buf = struct.pack('<HHHHHHHHHHHHHHHH', *chan16)
self.sitl_output.write(buf)
self.sitl_outputs[self.master.linknum].write(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it is conflating link numbers and sitl-output-port numbers.

That probably means you could elicit a runtime exception with link add - or simply starting with a different number of links to sitl-rc-outputs.

There isn't a 1:1 correspondence between link numbers and SITL outputs - you could have a connection to the same simulation process on 2 of its mavliunk ports, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Would the combination of sysid, cmpid constitute a unique key for the sitl output? I'll need to maintain a map between a key that can be retrieved from the link and the sitl output in order to assign the correct output in the rc module.

Copy link
Contributor Author

@srmainwaring srmainwaring Nov 24, 2025

Choose a reason for hiding this comment

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

@peterbarker - I've reworked this to use the SITL instance as an index for the sitl_outputs and added logic to determine the active instance in the rc module. The vehicle system and component id's are not discovered at the point sitl_outputs is initialised, so they can't be used as a key.

The approach assumes that the base port numbers for master (5760) and sitl output (5501) are always used.

The lookup in the rc module seems a bit clunky, any suggestions to streamline it are welcome. It should be safe re. runtime exceptions now as if no instance is found, or the instance is not in the dictionary the send_rc method switches to use rc_channels_override_send. This should cover the case where there is a mixture of sim on HW and a SITL instance running (but I have not tested that combination).

- Index sitl_outputs by the sitl instance.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
- Make plural to indicate type is a list.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants