Does gazebo_ros2_control need to be sourced/built/linked after installation via apt?

Anywhere I search I can see that gazebo_ros2_control can be installed in the Humble distribution with Ubuntu 22 with just an apt command. My problem is that ros2 seems to not be finding the plugin.

[gazebo-3] [Err] [Model.cc:1160] Exception occured in the Load function of plugin with name[gazebo_ros2_control] and filename[libgazebo_ros2_control.so]. This plugin will not run.
For example in here it is mentioned:

A Gazebo plugin is added with this lines in the URDF:

  <plugin filename="plugin_name.so" name="some_name" >
    plugin args...
  </plugin>
However you will need to export the plugins path to advertise Gazebo where to find custom plugins. Take a look at this tutorial, you whould be able to follow it until the end, where you will find how to export and launch the plugin.

I am wondering, maybe I need to source /usr/share/gazebo/ or gazebo-11 for that matter. I tried with some repositories that are instantly triable. Same error. I actually thought of using the universal robots repo, which installs in the workspace the different ros2-control, gazebo-ros2-control.

ls ../workspaces/ur_gazebo/src/
gazebo_ros2_control       moveit_msgs
learm_ros2                ros2_control
learm_ros2_description    ros2_controllers
learm_ros2_moveit_config  Universal_Robots_ROS2_Gazebo_Simulation
moveit2                   ur_description
But I am getting the same. I got at some point a message to "override" paths.

My main question is: After installing gazebo_ros2_control, does ANYTHING ELSE need to be done? Adding to a CMakesList.txt, or to package.xml, setup.py? I read in here that it might be related to GAZEBO_MODEL_PATH. Something related to rosdep maybe?

Code:

import os
from launch_ros.actions import Node
from launch import LaunchDescription
from launch.substitutions import Command
from launch.actions import ExecuteProcess
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():

    
    #robot_model = 'm1013'

    xacro_file = get_package_share_directory('learm_ros2') + '/urdf/learm-gazebo.urdf.xacro'

    
    # Robot State Publisher 
    robot_state_publisher = Node(package    ='robot_state_publisher',
                                 executable ='robot_state_publisher',
                                 name       ='robot_state_publisher',
                                 output     ='both',
                                 parameters =[{'robot_description': Command(['xacro', ' ', xacro_file])           
                                }])


    # Spawn the robot in Gazebo
    spawn_entity_robot = Node(package     ='gazebo_ros', 
                              executable  ='spawn_entity.py', 
                              arguments   = ['-entity', 'learm_ros2', '-topic', 'robot_description'],
                              output      ='screen')

    # Gazebo   
    world_file_name = 'table_world.world'
    world = os.path.join(get_package_share_directory('learm_ros2'), 'worlds', world_file_name)
    gazebo_node = ExecuteProcess(cmd=['gazebo', '--verbose', world,'-s', 'libgazebo_ros_factory.so'], output='screen')


    # These are not working....
    
    # load_joint_state_broadcaster = ExecuteProcess(
    #                                   cmd=['ros2', 'control', 'load_controller', '--set-state', 'start','joint_state_broadcaster'],
    #                                   output='screen')

    
    # load_joint_trajectory_controller = ExecuteProcess( 
    #                                   cmd=['ros2', 'control', 'load_controller', '--set-state', 'start', 'joint_trajectory_controller'], 
    #                                   output='screen')


    return LaunchDescription([robot_state_publisher, spawn_entity_robot, gazebo_node,   ])
Complete log:

ros2 launch learm_ros2 my_gazebo_controller.launch.py 
[INFO] [launch]: All log files can be found below /home/mk/.ros/log/2024-04-11-09-15-23-807156-mk-5577
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [5579]
[INFO] [spawn_entity.py-2]: process started with pid [5581]
[INFO] [gazebo-3]: process started with pid [5583]
[robot_state_publisher-1] [INFO] [1712819724.075684381] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1712819724.075815637] [robot_state_publisher]: got segment finger_left_link
[robot_state_publisher-1] [INFO] [1712819724.075825642] [robot_state_publisher]: got segment finger_right_link
[robot_state_publisher-1] [INFO] [1712819724.075831179] [robot_state_publisher]: got segment forearm_link
[robot_state_publisher-1] [INFO] [1712819724.075835984] [robot_state_publisher]: got segment grip_left_link
[robot_state_publisher-1] [INFO] [1712819724.075840953] [robot_state_publisher]: got segment grip_right_link
[robot_state_publisher-1] [INFO] [1712819724.075845599] [robot_state_publisher]: got segment hand_link
[robot_state_publisher-1] [INFO] [1712819724.075850323] [robot_state_publisher]: got segment humerus_link
[robot_state_publisher-1] [INFO] [1712819724.075855091] [robot_state_publisher]: got segment shoulder_link
[robot_state_publisher-1] [INFO] [1712819724.075859804] [robot_state_publisher]: got segment tendon_left_link
[robot_state_publisher-1] [INFO] [1712819724.075864539] [robot_state_publisher]: got segment tendon_right_link
[robot_state_publisher-1] [INFO] [1712819724.075869254] [robot_state_publisher]: got segment world
[robot_state_publisher-1] [INFO] [1712819724.075873869] [robot_state_publisher]: got segment wrist_link
[gazebo-3] Gazebo multi-robot simulator, version 11.10.2
[gazebo-3] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-3] Released under the Apache 2 License.
[gazebo-3] http://gazebosim.org
[gazebo-3] 
[spawn_entity.py-2] [INFO] [1712819724.364785269] [spawn_entity]: Spawn Entity started
[spawn_entity.py-2] [INFO] [1712819724.365130349] [spawn_entity]: Loading entity published on topic robot_description
[spawn_entity.py-2] /opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/qos.py:307: UserWarning: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL is deprecated. Use DurabilityPolicy.TRANSIENT_LOCAL instead.
[spawn_entity.py-2]   warnings.warn(
[spawn_entity.py-2] [INFO] [1712819724.366856777] [spawn_entity]: Waiting for entity xml on robot_description
[gazebo-3] Gazebo multi-robot simulator, version 11.10.2
[gazebo-3] Copyright (C) 2012 Open Source Robotics Foundation.
[gazebo-3] Released under the Apache 2 License.
[gazebo-3] http://gazebosim.org
[gazebo-3] 
[spawn_entity.py-2] [INFO] [1712819724.472695945] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30
[spawn_entity.py-2] [INFO] [1712819724.473441392] [spawn_entity]: Waiting for service /spawn_entity
[gazebo-3] [INFO] [1712819724.887534290] [gazebo_ros_node]: ROS was initialized without arguments.
[spawn_entity.py-2] [INFO] [1712819725.229984757] [spawn_entity]: Calling service /spawn_entity
[spawn_entity.py-2] [INFO] [1712819725.546704340] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [learm_ros2]
[INFO] [spawn_entity.py-2]: process has finished cleanly [pid 5581]
[gazebo-3] [Msg] Waiting for master.
[gazebo-3] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-3] [Msg] Publicized address: 192.168.1.49
[gazebo-3] [Msg] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[gazebo-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
[gazebo-3] [INFO] [1712819726.206974140] [gazebo_ros2_control]: Loading gazebo_ros2_control plugin
[gazebo-3] [INFO] [1712819726.208899511] [gazebo_ros2_control]: Starting gazebo_ros2_control plugin in namespace: /
[gazebo-3] [INFO] [1712819726.209095469] [gazebo_ros2_control]: Starting gazebo_ros2_control plugin in ros 2 node: gazebo_ros2_control
[gazebo-3] [INFO] [1712819726.210755756] [gazebo_ros2_control]: connected to service!! robot_state_publisher
[gazebo-3] [INFO] [1712819726.211154584] [gazebo_ros2_control]: Received urdf from param server, parsing...
[gazebo-3] [INFO] [1712819726.211194783] [gazebo_ros2_control]: Loading parameter files /home/mk/ros2_ws/install/learm_ros2_description/share/learm_ros2_description/config/combined_controllers.yaml
[gazebo-3] [INFO] [1712819726.219434473] [gazebo_ros2_control]: Loading joint: shoulder_pan...(#hiding other joints for log)
[gazebo-3] [INFO] [1712819726.221340144] [resource_manager]: Initialize hardware 'GazeboSystem' 
[gazebo-3] [INFO] [1712819726.221351965] [resource_manager]: Successful initialization of hardware 'GazeboSystem'
[gazebo-3] [INFO] [1712819726.221431741] [gazebo_ros2_control]: Loading controller_manager
[gazebo-3] [Msg] Waiting for master.
[gazebo-3] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
[gazebo-3] [Msg] Publicized address: 192.168.1.49
[gazebo-3] [Msg] Loading world file [/home/mk/ros2_ws/install/learm_ros2/share/learm_ros2/worlds/table_world.world]
[gazebo-3] [Err] [Model.cc:1160] Exception occured in the Load function of plugin with name[gazebo_ros2_control] and filename[libgazebo_ros2_control.so]. This plugin will not run.
[gazebo-3] [Err] [Connection.cc:547] Connection[16] Closed during Read
[gazebo-3] [Err] [TransportIface.cc:385] Unable to read from master
[ERROR] [gazebo-3]: process has died [pid 5583, exit code 255, cmd 'gazebo --verbose /home/mk/ros2_ws/install/learm_ros2/share/learm_ros2/worlds/table_world.world -s libgazebo_ros_factory.so'].
[gazebo-3] 
[gazebo-3] 
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[robot_state_publisher-1] [INFO] [1712819751.927358582] [rclcpp]: signal_handler(signum=2)
[INFO] [robot_state_publisher-1]: process has finished cleanly [pid 5579]
controller.yaml:

controller_manager:
  ros__parameters:
    update_rate: 30.0
    use_sim_time: true

    joint_state_controller:
      type: joint_state_controller/JointStateController
      publish_rate: 50.0
    joint_state_broadcaster:
      type: joint_state_broadcaster/JointStateBroadcaster
    arm_controller:
      type: joint_trajectory_controller/JointTrajectoryController

arm_controller:
  ros__parameters:
    publish_rate: 50.0
    base_frame_id: base_link
    command_interfaces:
      - position
    state_interfaces:
      - position
      - velocity
    joints:
      - shoulder_pan
      - shoulder_lift
      - elbow
      - wrist_flex
      - wrist_roll
      - grip_left
And finally my urdf.xacro file that has included <xacro:include filename = "ros2_control.xacro" /> and my ros2_control.xacro: has

<?xml version="1.0" ?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">


<ros2_control name="GazeboSystem" type="system">
  <hardware>
    <plugin>gazebo_ros2_control/GazeboSystem</plugin>
  </hardware>
<joint name="shoulder_pan">
<command_interface name="position">
  <param name="min">-1.57</param>
  <param name="max">1.57</param>
</command_interface>
<command_interface name="velocity">
  <param name="min">-0.5</param>
  <param name="max">0.5</param>
</command_interface>
<command_interface name="effort">
  <param name="min">-1000</param>
  <param name="max">1000</param>
</command_interface>
<state_interface name="position"/>
<state_interface name="velocity"/>
<state_interface name="effort"/>
and all the info relevant to the joints, and at the end:
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">

  <parameters>$(find learm_ros2_description)/config/combined_controllers.yaml</parameters>

</plugin>
EDIT:

I used the same launch.py file as in [cart_example_position.launch.py]4.

Running ros2 launch gazebo_ros2_control_demos cart_example_position.launch.py and ros2 run gazebo_ros2_control_demos example_position works perfectly fine. copying all the contents, creating a new.run.launch.py file and editing

gazebo_ros2_control_demos_path = os.path.join(
        get_package_share_directory('learm_ros2'))

    xacro_file = os.path.join(gazebo_ros2_control_demos_path,
                              'urdf',
                              'learm-gazebo-xacroTurdf.urdf')
Still gives me errors.

[gazebo_ros2_control]: Loading controller_manager
    [ERROR] [gzserver-1]: process has died [pid 23581, exit code -11, cmd 'gzserver -slibgazebo_ros_init.so -slibgazebo_ros_factory.so -slibgazebo_ros_force_system.so'].
    [ros2-5] Could not contact service /controller_manager/load_controller
    [ERROR] [ros2-5]: process has died [pid 23669, exit code 1, cmd 'ros2 control load_controller --set-state active joint_state_broadcaster'].
    [INFO] [ros2-6]: process started with pid [23794]
    [ros2-6] Could not contact service /controller_manager/load_controller
    [ERROR] [ros2-6]: process has died [pid 23794, exit code 1, cmd 'ros2 control load_controller --set-state active joint_trajectory_controller'].
    ^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
    [robot_state_publisher-3] [INFO] [1712843686.506268158] [rclcpp]: signal_handler(signum=2)
    [INFO] [robot_state_publisher-3]: process has finished cleanly [pid 23585]
    [INFO] [gzclient-2]: process has finished cleanly [pid 23583]
So I am currently lost. Editing my controllers.yaml to the yaml file they use, gives me different errors, but as if it managed to connect! So my errors are probably in the controller.yaml or urdf.