ros-controls / ros2_control

Generic and simple controls framework for ROS 2
https://control.ros.org
Apache License 2.0
469 stars 287 forks source link

Passing data to multiple instances of HardwareInterface from control node #1486

Open tenfoldpaper opened 4 months ago

tenfoldpaper commented 4 months ago

Hi, I've been working on a mujoco integration of the Panda robot arm into ros2-control. So far, I've had some success simulating multiple robots, but only by creating the simulation loop inside the HardwareInterface class itself. While I can control and do things with it, when it comes to combining multiple hardware interfaces together (e.g. the robot arm mounted on a mobile base with its own HardwareInterface class), this structure would require me to write a monolothic HardwareInterface class that combines both of these together.

I've taken a look at the linked mujoco integration repo, and it appears that they are also doing something similar.

From what I can tell, in ros-control, we had a more fine-grained control over how to initialize the Interface classes, as it had a constructor and we could initialize the HardwareInterface-equivalent with an argument to simulate multiple components all sharing the same data source.

Is this a feature that is also available in ros2-control? If so, how do you do this? Apologies in advance for asking something that may be basic, but I could not find any relevant code bases that address this issue.

christophfroehlich commented 4 months ago

Do you need to share data at run-time, or only at loading/initialization of the different components?

destogl commented 4 months ago

@tenfoldpaper maybe implementation of gz_ros2_control is interesting in this regard for you? Can you check it?

tenfoldpaper commented 4 months ago

Do you need to share data at run-time, or only at loading/initialization of the different components?

Sorry for the late reply! I need to share data at run-time. Generally, this should be possible by passing a reference to the mjData and mjModel pointers that get instantiated when loading up the scene using Mujoco. So far I've managed that successfully with member variable classes.

Since data is only accessed in the controller's read and write loops (and read and written in those parts), there shouldn't be major issues, as from what I can tell, the respective HardwareInterfaces' read and write functions are executed serially.

There is a mujoco-ros-control repo for ROS1 I found before that did the whole manual initialization thing, which made this possible. So far, I haven't been able to find a solution to this yet.

tenfoldpaper commented 4 months ago

@tenfoldpaper maybe implementation of gz_ros2_control is interesting in this regard for you? Can you check it?

I'll take a look at it in a couple days and update my comment on this, but thank you for the suggestion!

tenfoldpaper commented 3 months ago

So I went through gz_ros2_control, and it appears that the way it is handling ros2-control is not really transferable to MuJoCo. It seems to work based on Gazebo's Plugin interface, which seems to create instances of ros2-control objects inside the simulation directly.

Since MuJoCo needs to be initialized and executed directly in ros2-control in the main control node, and there is no easy way to create a similar plugin-like interface for it, unfortunately it does not solve the problem.

@christophfroehlich , do you know any way to implement what I asked in the opening post?

christophfroehlich commented 3 months ago

No I don't know a way to pass data between different hardware components. But maybe I don't understand your problem correctly: You will have to use different hardware components anyways, one (set) for your robot, and another one (set) for your simulation. For example, two hardware components for your real hardware (arm + base), but a single monolithic one for mujoco?

saikishor commented 3 months ago

@tenfoldpaper Maybe what you are looking for is a System HardwareComponents, where multiple actuators can coexist and share information.

christophfroehlich commented 3 months ago

@tenfoldpaper Maybe what you are looking for is a System HardwareComponents, where multiple actuators can coexist and share information.

as far as I understood he wants to share data between components which are not known altogether at compile time, but loaded dynamically.