0
$\begingroup$

I am using gazebo_ros2_control to simulate a prismatic joint. ROS distro - iron. Using gazebo Classic 11.

URDF relevant to the prismatic joint-

<!--ELEVATOR CAR-->

<joint name="elevatorCar_joint" type="prismatic">
    <axis xyz="0 0 1"/>
    <limit effort="1000.0" lower="0.0" upper="1" velocity="0.5"/>
    <origin xyz="0 0 0"/>
    <parent link="base_link"/>
    <child link="elevatorCar"/>
</joint>

<link name="elevatorCar">
    <visual>
        <origin xyz="0 0 0.3"/>
        <geometry>
            <box size="1.32 1.1 0.02"/>
        </geometry>
        <material name="white"/>
    </visual>
    <collision>
        <origin xyz="0 0 0.3"/>
        <geometry>
            <box size="1.32 1.1 0.02"/>
        </geometry>
    </collision>
    <xacro:inertial_box mass="100" x="1.32" y="1.1" z="0.02">
        <origin xyz="0 0 0.3" rpy="0 0 0"/>
    </xacro:inertial_box>
</link>

<gazebo reference="elevatorCar">
    <material>Gazebo/Black</material>
</gazebo>

<!-- GAZEBO CONTROL FOR THE ELEVATOR-->
<ros2_control name="GazeboSystem" type="system">
    <hardware>
        <plugin>gazebo_ros2_control/GazeboSystem</plugin>
    </hardware>
    <joint name="elevatorCar_joint">
        <command_interface name="position">
            <param name="min">-10</param>
            <param name="max">10</param>
        </command_interface>
        <state_interface name="position">
            <param name="initial_value">1.0</param>
        </state_interface>
        <state_interface name="velocity"/>
        <state_interface name="effort"/>
    </joint>
</ros2_control>

<gazebo>
    <plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
        <parameters>$(find bot_elevator)/config/elevator_controller.yaml</parameters>
    </plugin>
</gazebo>

yaml file -

controller_manager:
  ros__parameters:
    update_rate: 100  # Hz

    joint_trajectory_controller:
      type: joint_trajectory_controller/JointTrajectoryController

    joint_state_broadcaster:
      type: joint_state_broadcaster/JointStateBroadcaster

joint_trajectory_controller:
  ros__parameters:
    joints:
      - elevatorCar_joint
    interface_name: position
    command_interfaces:
      - position
    state_interfaces:
      - position
      - velocity

Launch file -

import os

from ament_index_python.packages import get_package_share_directory


from launch import LaunchDescription
from launch.actions import ExecuteProcess, IncludeLaunchDescription, RegisterEventHandler
from launch.event_handlers import OnProcessExit
from launch.launch_description_sources import PythonLaunchDescriptionSource

from launch_ros.actions import Node



def generate_launch_description():

    package_name='bot_elevator'

    rsp = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory(package_name),'launch','launch.py'
                )]), launch_arguments={'use_sim_time': 'true'}.items()
    )

    # Include the Gazebo launch file, provided by the gazebo_ros package
    gazebo = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')]),
             )

    # Run the spawner node from the gazebo_ros package. The entity name doesn't really matter if you only have a single robot.
    spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py',
                        arguments=['-topic', 'robot_description',
                                   '-entity', 'my_bot'],
                        output='screen')

    # load_joint_state_controller = ExecuteProcess(
    #     cmd=['ros2', 'control', 'load_controller', '--set-state', 'active',
    #          'joint_state_broadcaster'],
    #     output='screen'
    # )

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

    # Launch them all!
    return LaunchDescription([
        # RegisterEventHandler(
        #     event_handler=OnProcessExit(
        #         target_action=spawn_entity,
        #         on_exit=[load_joint_state_controller],
        #     )
        # ),
        # RegisterEventHandler(
        #     event_handler=OnProcessExit(
        #         target_action=load_joint_state_controller,
        #         on_exit=[load_joint_trajectory_controller],
        #     )
        # ),
        rsp,
        gazebo,
        spawn_entity,
    ])

I tried with and without loading controller. First manually after the world, spawn initiation because it was one of the recommended solution I found online. Then I tried including it in the launch file but both methods did not work. Output of the Launch file with the error -

[ros2-5] Could not contact service /controller_manager/load_controller
[ERROR] [ros2-5]: process has died [pid 5844, exit code 1, cmd 'ros2 control load_controller --set-state active joint_state_broadcaster'].
[INFO] [ros2-6]: process started with pid [5965]
[ros2-6] Could not contact service /controller_manager/load_controller
[ERROR] [ros2-6]: process has died [pid 5965, exit code 1, cmd 'ros2 control load_controller --set-state active joint_trajectory_controller'].
$\endgroup$
2
  • 1
    $\begingroup$ Resolved it. If your package is in your custom workspace, you need to source the files from the gazebo_ros2_control workspace to load the control_manager $\endgroup$ Sep 14, 2023 at 23:07
  • 1
    $\begingroup$ Please post the solution as an actual answer and not in the comments. Also please take the tour to better understand how Stack Exchange works. $\endgroup$ Sep 15, 2023 at 13:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.