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

[Bug]: Building plugins might be incompatible with ros2_control #125

Closed
1 task done
yaymalaga opened this issue Jun 4, 2024 · 8 comments
Closed
1 task done

[Bug]: Building plugins might be incompatible with ros2_control #125

yaymalaga opened this issue Jun 4, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@yaymalaga
Copy link

yaymalaga commented Jun 4, 2024

Before proceeding, is there an existing issue or discussion for this?

OS and version

Ubuntu 22.04.3

Open-RMF installation type

Binaries

Other Open-RMF installation methods

No response

Open-RMF version or commit hash

humble-release

ROS distribution

Humble

ROS installation type

Docker

Other ROS installation methods

No response

Package or library, if applicable

No response

Description of the bug

I'm trying to integrate the building plugins into a rosbot simulation, specifically the door and lift ones, however the simulation just panics on start even though the plugin itself seems to load just fine as shown below. Given the logs, it seems the plugins are colliding somehow with ros2_control.

yaymalaga@2ffa44ce70ae:~$ ros2 launch rosbot_xl_gazebo simulation.launch.py 
[INFO] [launch]: All log files can be found below /home/yaymalaga/.ros/log/2024-06-04-13-09-40-377468-2ffa44ce70ae-13140
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [ruby $(which ign) gazebo-1]: process started with pid [13152]
[INFO] [parameter_bridge-2]: process started with pid [13154]
[INFO] [create-3]: process started with pid [13157]
[INFO] [robot_state_publisher-4]: process started with pid [13159]
[INFO] [spawner-5]: process started with pid [13161]
[INFO] [ekf_node-6]: process started with pid [13164]
[INFO] [scan_to_scan_filter_chain-7]: process started with pid [13166]
[robot_state_publisher-4] [INFO] [1717499380.640004055] [robot_state_publisher]: got segment antenna_connector_link
[robot_state_publisher-4] [INFO] [1717499380.640094585] [robot_state_publisher]: got segment antenna_link
[robot_state_publisher-4] [INFO] [1717499380.640103568] [robot_state_publisher]: got segment base_link
[robot_state_publisher-4] [INFO] [1717499380.640108527] [robot_state_publisher]: got segment body_link
[robot_state_publisher-4] [INFO] [1717499380.640112974] [robot_state_publisher]: got segment cover_link
[robot_state_publisher-4] [INFO] [1717499380.640117971] [robot_state_publisher]: got segment fl_wheel_link
[robot_state_publisher-4] [INFO] [1717499380.640122529] [robot_state_publisher]: got segment fr_wheel_link
[robot_state_publisher-4] [INFO] [1717499380.640126965] [robot_state_publisher]: got segment imu_link
[robot_state_publisher-4] [INFO] [1717499380.640131361] [robot_state_publisher]: got segment laser
[robot_state_publisher-4] [INFO] [1717499380.640135887] [robot_state_publisher]: got segment rl_wheel_link
[robot_state_publisher-4] [INFO] [1717499380.640140622] [robot_state_publisher]: got segment rr_wheel_link
[robot_state_publisher-4] [INFO] [1717499380.640144901] [robot_state_publisher]: got segment slamtec_rplidar_s1_link
[create-3] [INFO] [1717499380.651684348] [ros_gz_sim]: Requesting list of world names.
[parameter_bridge-2] [INFO] [1717499380.664846292] [ign_bridge]: Creating GZ->ROS Bridge: [/clock (ignition.msgs.Clock) -> /clock (rosgraph_msgs/msg/Clock)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.665335032] [ign_bridge]: Creating GZ->ROS Bridge: [/scan (ignition.msgs.LaserScan) -> /scan (sensor_msgs/msg/LaserScan)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.666606278] [ign_bridge]: Creating GZ->ROS Bridge: [/velodyne_points/points (ignition.msgs.PointCloudPacked) -> /velodyne_points/points (sensor_msgs/msg/PointCloud2)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.666990954] [ign_bridge]: Creating GZ->ROS Bridge: [/camera/color/camera_info (ignition.msgs.CameraInfo) -> /camera/color/camera_info (sensor_msgs/msg/CameraInfo)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.667373001] [ign_bridge]: Creating GZ->ROS Bridge: [/camera/color/image_raw (ignition.msgs.Image) -> /camera/color/image_raw (sensor_msgs/msg/Image)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.667688410] [ign_bridge]: Creating GZ->ROS Bridge: [/camera/camera_info (ignition.msgs.CameraInfo) -> /camera/camera_info (sensor_msgs/msg/CameraInfo)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.667915099] [ign_bridge]: Creating GZ->ROS Bridge: [/camera/depth (ignition.msgs.Image) -> /camera/depth (sensor_msgs/msg/Image)] (Lazy 0)
[parameter_bridge-2] [INFO] [1717499380.668106226] [ign_bridge]: Creating GZ->ROS Bridge: [/camera/depth/points (ignition.msgs.PointCloudPacked) -> /camera/depth/points (sensor_msgs/msg/PointCloud2)] (Lazy 0)
[ruby $(which ign) gazebo-1] Using specified attribute value [ShaftDoor_Lift2_L2_lift2_door] for property [name]
[ruby $(which ign) gazebo-1] [INFO] [1717499380.927296244] [plugin_ShaftDoor_Lift2_L2_lift2_door]: Loading DoorPlugin for [ShaftDoor_Lift2_L2_lift2_door]
[ruby $(which ign) gazebo-1] Using specified attribute value [left_joint] for property [left_joint_name]
[ruby $(which ign) gazebo-1] Using specified attribute value [right_joint] for property [right_joint_name]
[ruby $(which ign) gazebo-1] Using specified attribute value [DoubleSlidingDoor] for property [type]
[ruby $(which ign) gazebo-1] Using specified value [0.3] for property [v_max_door]
[ruby $(which ign) gazebo-1] Using specified value [0.2] for property [a_max_door]
[ruby $(which ign) gazebo-1] Using specified value [0.1] for property [a_nom_door]
[ruby $(which ign) gazebo-1] Using specified value [0.0001] for property [dx_min_door]
[ruby $(which ign) gazebo-1] Using specified value [35] for property [f_max_door]
[ruby $(which ign) gazebo-1] [INFO] [1717499380.928507777] [plugin_ShaftDoor_Lift2_L2_lift2_door]: Finished loading [ShaftDoor_Lift2_L2_lift2_door]
[create-3] [INFO] [1717499381.109047666] [ros_gz_sim]: Waiting messages on topic [robot_description].
[create-3] [INFO] [1717499381.208421968] [ros_gz_sim]: Requested creation of entity.
[create-3] [INFO] [1717499381.208592025] [ros_gz_sim]: OK creation of entity.
[INFO] [create-3]: process has finished cleanly [pid 13157]
[spawner-5] [INFO] [1717499382.790573223] [spawner_joint_state_broadcaster]: Waiting for '/simulation_controller_manager' node to exist
[ruby $(which ign) gazebo-1] Stack trace (most recent call last):
[ruby $(which ign) gazebo-1] #31   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf4030c, in rb_vm_exec
[ruby $(which ign) gazebo-1] #30   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf3ac96, in 
[ruby $(which ign) gazebo-1] #29   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf37fc5, in 
[ruby $(which ign) gazebo-1] #28   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf35c34, in 
[ruby $(which ign) gazebo-1] #27   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fede81a1e, in 
[ruby $(which ign) gazebo-1] #26   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1feddac9ac, in rb_protect
[ruby $(which ign) gazebo-1] #25   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf44c61, in rb_yield
[ruby $(which ign) gazebo-1] #24   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf4030c, in rb_vm_exec
[ruby $(which ign) gazebo-1] #23   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf3ac96, in 
[ruby $(which ign) gazebo-1] #22   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf37fc5, in 
[ruby $(which ign) gazebo-1] #21   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf35c34, in 
[ruby $(which ign) gazebo-1] #20   Object "/usr/lib/x86_64-linux-gnu/ruby/3.0.0/fiddle.so", at 0x7f1fed70f44b, in 
[ruby $(which ign) gazebo-1] #19   Object "/lib/x86_64-linux-gnu/libruby-3.0.so.3.0", at 0x7f1fedf03088, in rb_nogvl
[ruby $(which ign) gazebo-1] #18   Object "/usr/lib/x86_64-linux-gnu/ruby/3.0.0/fiddle.so", at 0x7f1fed70ed6b, in 
[ruby $(which ign) gazebo-1] #17   Object "/lib/x86_64-linux-gnu/libffi.so.8", at 0x7f1fed6e3492, in 
[ruby $(which ign) gazebo-1] #16   Object "/lib/x86_64-linux-gnu/libffi.so.8", at 0x7f1fed6e6e2d, in 
[ruby $(which ign) gazebo-1] #15   Object "/usr/lib/x86_64-linux-gnu/libignition-gazebo6-ign.so.6.16.0", at 0x7f1fed662e20, in runServer
[ruby $(which ign) gazebo-1] #14   Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe904fad9, in 
[ruby $(which ign) gazebo-1] #13   Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9060d3a, in ignition::gazebo::v6::SimulationRunner::Run(unsigned long)
[ruby $(which ign) gazebo-1] #12   Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe90605cd, in ignition::gazebo::v6::SimulationRunner::Step(ignition::gazebo::v6::UpdateInfo const&)
[ruby $(which ign) gazebo-1] #11   Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9057549, in ignition::gazebo::v6::SimulationRunner::UpdateSystems()
[ruby $(which ign) gazebo-1] #10   Object "/usr/lib/x86_64-linux-gnu/ign-gazebo-6/plugins/libignition-gazebo-user-commands-system.so", at 0x7f1fd967b7b8, in ignition::gazebo::v6::systems::UserCommands::PreUpdate(ignition::gazebo::v6::UpdateInfo const&, ignition::gazebo::v6::EntityComponentManager&)
[ruby $(which ign) gazebo-1] #9    Object "/usr/lib/x86_64-linux-gnu/ign-gazebo-6/plugins/libignition-gazebo-user-commands-system.so", at 0x7f1fd96805fc, in ignition::gazebo::v6::systems::CreateCommand::Execute()
[ruby $(which ign) gazebo-1] #8    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9022d7f, in ignition::gazebo::v6::SdfEntityCreator::CreateEntities(sdf::v12::Model const*)
[ruby $(which ign) gazebo-1] #7    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9033275, in void ignition::gazebo::v6::EventManager::Emit<ignition::common::EventT<void (unsigned long, std::vector<sdf::v12::Plugin, std::allocator<sdf::v12::Plugin> >), ignition::gazebo::v6::events::LoadPluginsTag>, unsigned long const&, std::vector<sdf::v12::Plugin, std::allocator<sdf::v12::Plugin> > const&>(unsigned long const&, std::vector<sdf::v12::Plugin, std::allocator<sdf::v12::Plugin> > const&)
[ruby $(which ign) gazebo-1] #6    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9057788, in ignition::gazebo::v6::SimulationRunner::LoadPlugins(unsigned long, std::vector<sdf::v12::Plugin, std::allocator<sdf::v12::Plugin> > const&)
[ruby $(which ign) gazebo-1] #5    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9072265, in ignition::gazebo::v6::SystemManager::LoadPlugin(unsigned long, sdf::v12::Plugin const&)
[ruby $(which ign) gazebo-1] #4    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9071f66, in ignition::gazebo::v6::SystemManager::AddSystem(ignition::plugin::TemplatePluginPtr<ignition::plugin::SpecializedPlugin<ignition::gazebo::v6::System, ignition::gazebo::v6::ISystemConfigure, ignition::gazebo::v6::ISystemPreUpdate, ignition::gazebo::v6::ISystemUpdate, ignition::gazebo::v6::ISystemPostUpdate> > const&, unsigned long, std::shared_ptr<sdf::v12::Element const>)
[ruby $(which ign) gazebo-1] #3    Object "/lib/x86_64-linux-gnu/libignition-gazebo6.so.6", at 0x7f1fe9071900, in ignition::gazebo::v6::SystemManager::AddSystemImpl(ignition::gazebo::v6::SystemInternal, std::shared_ptr<sdf::v12::Element const>)
[ruby $(which ign) gazebo-1] #2    Object "/ros2_ws/install/ign_ros2_control/lib/libign_ros2_control-system.so", at 0x7f1f9eb2b1a6, in ign_ros2_control::IgnitionROS2ControlPlugin::Configure(unsigned long const&, std::shared_ptr<sdf::v12::Element const> const&, ignition::gazebo::v6::EntityComponentManager&, ignition::gazebo::v6::EventManager&)
[ruby $(which ign) gazebo-1] #1    Object "/opt/ros/humble/lib/librclcpp.so", at 0x7f1fe18f1e65, in rclcpp::Executor::add_node(std::shared_ptr<rclcpp::Node>, bool)
[ruby $(which ign) gazebo-1] #0    Object "/opt/ros/humble/lib/librclcpp.so", at 0x7f1fe1907f04, in rclcpp::Node::get_node_base_interface()
[ruby $(which ign) gazebo-1] Segmentation fault (Address not mapped to object [0x18])

Steps to reproduce the bug

For the bug report, I'm using the following docker image provided by Husarion: husarion/rosbot-xl-gazebo:humble.

I started a container with the root user so I could install rmf: apt-get update && apt-get install ros-humble-rmf-dev. Then, I modified the default world (/ros2_ws/install/husarion_office_gz/share/husarion_office_gz/worlds/husarion_world.sdf) to include a door model together with its plugin as shown below (extracted from the rmf hote_ign demo):

<model name="ShaftDoor_Lift2_L2_lift2_door">
  <pose>16.982458687729547 -22.82088370217165 8.0 0 0 0.0</pose>
  <link name="right_door">
    <pose>0.425 0 1.25 0 0 0</pose>
    <visual name="right_door_visual">
      <geometry>
        <box>
          <size>0.85 0.03 2.5</size>
        </box>
      </geometry>
      <material>
        <ambient>0.5 0.5 0.5 1</ambient>
        <diffuse>0.7 0.7 0.7 1</diffuse>
        <specular>0.6 0.6 0.6 1</specular>
        <emissive>0.1 0.1 0.1 1</emissive>
      </material>
    </visual>
    <collision name="right_door_collision">
      <geometry>
        <box>
          <size>0.85 0.03 2.5</size>
        </box>
      </geometry>
      <surface>
        <contact>
          <collide_bitmask>0x02</collide_bitmask>
        </contact>
      </surface>
    </collision>
  </link>
  <joint name="right_joint" type="prismatic">
    <parent>world</parent>
    <child>right_door</child>
    <axis>
      <xyz>1 0 0</xyz>
      <limit>
        <lower>0</lower>
        <upper>0.85</upper>
      </limit>
    </axis>
  </joint>
  <link name="left_door">
    <pose>-0.425 0 1.25 0 0 0</pose>
    <visual name="left_door_visual">
      <geometry>
        <box>
          <size>0.85 0.03 2.5</size>
        </box>
      </geometry>
      <material>
        <ambient>0.5 0.5 0.5 1</ambient>
        <diffuse>0.7 0.7 0.7 1</diffuse>
        <specular>0.6 0.6 0.6 1</specular>
        <emissive>0.1 0.1 0.1 1</emissive>
      </material>
    </visual>
    <collision name="left_door_collision">
      <geometry>
        <box>
          <size>0.85 0.03 2.5</size>
        </box>
      </geometry>
      <surface>
        <contact>
          <collide_bitmask>0x02</collide_bitmask>
        </contact>
      </surface>
    </collision>
  </link>
  <joint name="left_joint" type="prismatic">
    <parent>world</parent>
    <child>left_door</child>
    <axis>
      <xyz>1 0 0</xyz>
      <limit>
        <lower>-0.85</lower>
        <upper>0</upper>
      </limit>
    </axis>
  </joint>
  <link name="ramp">
    <pose>0 0 -0.025 0 0 0</pose>
    <visual name="ramp_visual">
      <geometry>
        <box>
          <size>1.7 0.1 0.05</size>
        </box>
      </geometry>
      <material>
        <ambient>0.5 0.5 0.5 1</ambient>
        <diffuse>0.7 0.7 0.7 1</diffuse>
        <specular>0.6 0.6 0.6 1</specular>
        <emissive>0.1 0.1 0.1 1</emissive>
      </material>
    </visual>
    <collision name="ramp_collision">
      <geometry>
        <box>
          <size>1.7 0.1 0.05</size>
        </box>
      </geometry>
      <surface>
        <contact>
          <collide_bitmask>0x02</collide_bitmask>
        </contact>
      </surface>
    </collision>
  </link>
  <joint name="ramp_joint" type="fixed">
    <parent>world</parent>
    <child>ramp</child>
  </joint>
  <plugin name="door" filename="libdoor.so">
    <v_max_door>0.3</v_max_door>
    <a_max_door>0.2</a_max_door>
    <a_nom_door>0.1</a_nom_door>
    <dx_min_door>0.0001</dx_min_door>
    <f_max_door>35.0</f_max_door>
    <door left_joint_name="left_joint" name="ShaftDoor_Lift2_L2_lift2_door" right_joint_name="right_joint" type="DoubleSlidingDoor" />
  </plugin>
</model>

Finally, I exported the gazebo plugin dir and launched the simulation using:

export GZ_SIM_SYSTEM_PLUGIN_PATH=$GZ_SIM_SYSTEM_PLUGIN_PATH:/opt/ros/humble/lib/rmf_building_sim_gz_plugins:/opt/ros/humble/lib/rmf_robot_sim_gz_plugins

ros2 launch rosbot_xl_gazebo simulation.launch.py 

If you just comment out the plugin part of the sdf, the simulation loads just fine, so the model is not the issue.

Just to reiterate, I'm not planning to integrate rmf into the simulation, but just to make use of the door and lift plugins as they are pretty handy to do some multi-floor testing.

Expected behavior

The simulation runs just fine and I can control the door and the robot without issues.

Actual behavior

The simulation simply panics.

Additional information or screenshots

No response

@yaymalaga yaymalaga added the bug Something isn't working label Jun 4, 2024
@yaymalaga yaymalaga changed the title [Bug]: [Bug]: Building plugins might be incompatible with ros2_control Jun 4, 2024
@luca-della-vedova
Copy link
Member

Hello!

I admit not having tried anything like this before, on a first glance though, the door that you inserted is a lift shaft door, did you try to insert just a normal door as well?

@yaymalaga
Copy link
Author

yaymalaga commented Jun 5, 2024

I have also tried with the SwingDoor model below and still having the exactly same crash as before. Without the plugin part, the door renders just fine as expected.

<model name="L1_door4">
  <pose>19.549120677562087 -11.10939551168469 0.0 0 0 -0.009497018345977264</pose>
  <link name="right">
    <pose>0 0 1.11 0 0 0</pose>
    <visual name="right_visual">
      <geometry>
        <box>
          <size>1.5905993122484277 0.03 2.2</size>
        </box>
      </geometry>
      <material>
        <ambient>0.5 0.25 0 0.6</ambient>
        <diffuse>0.5 0.25 0 0.6</diffuse>
        <pbr>
          <metal>
            <metalness>0.0</metalness>
          </metal>
        </pbr>
      </material>
    </visual>
    <collision name="right_collision">
      <geometry>
        <box>
          <size>1.5905993122484277 0.03 2.2</size>
        </box>
      </geometry>
      <surface>
        <contact>
          <collide_bitmask>0x02</collide_bitmask>
        </contact>
      </surface>
    </collision>
    <inertial>
      <mass>50.0</mass>
      <inertia>
        <ixx>20.17041666666667</ixx>
        <iyy>30.70835905052155</iyy>
        <izz>10.545442383854882</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="right_joint" type="revolute">
    <parent>world</parent>
    <child>right</child>
    <axis>
      <xyz>0 0 1</xyz>
      <limit>
        <lower>0</lower>
        <upper>1.57</upper>
      </limit>
    </axis>
    <pose>0.8002996561242138 0 0 0 0 0</pose>
  </joint>
  <plugin name="door" filename="libdoor.so">
    <v_max_door>0.5</v_max_door>
    <a_max_door>0.3</a_max_door>
    <a_nom_door>0.15</a_nom_door>
    <dx_min_door>0.01</dx_min_door>
    <f_max_door>500.0</f_max_door>
    <door name="L1_door4" type="SwingDoor" left_joint_name="empty_joint" right_joint_name="right_joint" />
  </plugin>
</model>

@luca-della-vedova
Copy link
Member

I looked at the husarion world (I'm assuming this?) Something that strikes me is that there is no physics system, we do need physics to simulate doors. You can look at the empty world template that we use to add on all the RMF models here. I'd suggest at least adding the world systems such as Physics and SceneBroadcaster and see if that helps

@yaymalaga
Copy link
Author

I have taken a look to the template and added to my sdf the following below, however it still crashes with the same log.

<plugin
    filename="libgz-sim-physics-system.so"
    name="gz::sim::systems::Physics">
</plugin>
<plugin
    filename="libgz-sim-user-commands-system.so"
    name="gz::sim::systems::UserCommands">
</plugin>
<plugin
    filename="libgz-sim-scene-broadcaster-system.so"
    name="gz::sim::systems::SceneBroadcaster">
</plugin>

I have also tested spawning the robot directly into the hotel_ign map, but it only works when the door/lift plugins are not enabled, otherwise it crashes too.

@yaymalaga
Copy link
Author

yaymalaga commented Jun 6, 2024

I continued debugging this stuff and have some interesting insights!

First, instead of using the provided docker image, I started from a humble-desktop-full one and did the manual installation of the rosbot-xl workspace (https://github.com/husarion/rosbot_xl_ros), which seems to be more up-to-date. Now the simulation doesn't crash, but libign_ros2_control still fails to configure the robot.

After some testing, it turned out that when the door plugin is added, the controller manager is not setting up the ROS parameters from the config file. Thus, I checked out the libign_ros2_control code and the interesting bit is that it is setting the arguments when initializing the ROS context.

// ...... some parameters parsing .....
if (!rclcpp::ok()) {
  rclcpp::init(static_cast<int>(argv.size()), argv.data());
}

Now, both rmf_building_plugins and libign_ros2_control are defined as ignition::gazebo::System plugins and therefore they seems to share the same context. As the door plugin is part of the world definition, it gets to load first and create the rclcpp context, so when the robot is spawned the arguments can't be set or you would get a rclcpp::ContextAlreadyInitialized error.

It seems this is a known "edge-case" as I found the following discussion regarding a similar issue while developing a new plugin: https://robotics.stackexchange.com/questions/110448/multiple-plugins-with-ros2-node-in-gazebo-simulation.

TLDR: This issue is simply not directly related to open-rmf, so feel free to close the bug report, but thanks for your quick reponse anyway :)

@luca-della-vedova
Copy link
Member

luca-della-vedova commented Jun 7, 2024 via email

@yaymalaga
Copy link
Author

yaymalaga commented Jun 10, 2024

Right now the gazebo world is loaded first, then the robot urdf is created on runtime using xacro with the launch file parameters, and spawned using ros_gz_sim's create node together with the ros_gz_bridge's parameter_bridge node.

So in this case, the easiest workaround was to print the generated urdf, take all the ros2_control parameters from there, and hard-code it into the floor plugin code:

    int argv_count = 7;
    const char* argv[argv_count] = {
        "--ros-args",
        "--params-file",
        "/home/yaymalaga/rosbot_ws/install/rosbot_xl_controller/share/rosbot_xl_controller/config/diff_drive_controller.yaml",
        "--remap",
        "rosbot_xl_base_controller/cmd_vel_unstamped:=cmd_vel",
        "--remap",
        "/tf:=tf"};
    std::string name;
    auto door_ele = sdf->GetElementImpl("door");
    get_sdf_attribute_required<std::string>(door_ele, "name", name);
    if (!rclcpp::ok())
      rclcpp::init(argv_count, argv);

Of course, this is not an ideal solution as we need to know these arguments in advance. I agree adding the argv parsing to these plugins could improve the situation a bit, so just modifying the world would be enough instead of recompiling.

That aside, I think the real issue lies in the ign_ros2_control, which has several issues opened talking about this matter, specially ros-controls/gz_ros2_control#166.

@luca-della-vedova
Copy link
Member

Interesting, fair enough, I'll close this but let me know if you plan to explore the argv parsing in rmf_simulation stragety!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants