Unit 6: unable to load the controller

Hi,

I am currently working on exercise 6.2.1 in ROS2 Control Framework and have made some modifications to the description file (.xacro) and added a configuration file (.yaml). The launch file executes successfully, and the robot appears in the Gazebo simulation window.

However, I am unable to load the controller due to the following error: Could not contact service /controller_manager/load_controller. It seems there might be an issue with the ros2 controller manager service, as it does not appear in the list when I run ros2 service list.

Could this issue be related to the launch file? Should we make additional modifications to it?

Hi @azurechen1203 ,

Without much context, it would be difficult for us to help you with your issue.

Please post your launch, xacro and configuration files as markdown formatted code blocks so your issue can be solved quicker.

With the error that you posted, I am assuming that you have not started the ROS2 control node properly in your launch file.
Did you implement the Joint State Controller (JSC) properly in your config file? Are you starting the JSC properly in your launch file?

Regards,
Girish

Hi @girishkumar.kannan

I am following the instructions provided in the notebook. We were asked to modify the description file and configuration file in the package named rrbot_unit5. After making these changes, the next steps are to execute the command ros2 launch spawn_robot spawn_rrbot.launch.py in Terminal 1 and then load the controller using ros2 control load_controller --set-state start forward_position_controller in Terminal 2. The launch file is located in a different package, spawn_robot, and there are no instructions indicating that we need to modify the launch file so I would assume no further work is required for the launch file?

description file:

<ros2_control name="position_controllers_exercise" type="system">
    <hardware>
      <plugin>gazebo_ros2_control/GazeboSystem</plugin>
    </hardware>

    <joint name="joint1">
      <command_interface name="position">
        <param name="min">-1000</param>
        <param name="max">1000</param>
      </command_interface>
      <state_interface name="position"/>
      <state_interface name="velocity"/>
      <state_interface name="effort"/>
    </joint>

    <joint name="joint2">
      <command_interface name="position">
        <param name="min">-1000</param>
        <param name="max">1000</param>
      </command_interface>
      <state_interface name="position"/>
      <state_interface name="velocity"/>
      <state_interface name="effort"/>
    </joint>

</ros2_control>

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

configuration file:

# Controller manager configuration
controller_manager:
  ros__parameters:
    update_rate: 50  # Hz

    # Declare controller name and type
    forward_position_controller:
      type: position_controllers/JointGroupPositionController
        
    joint_state_broadcaster:
      type: joint_state_broadcaster/JointStateBroadcaster
        
# Controller properties and joints to use
forward_position_controller:
  ros__parameters:
    joints:
      - joint1
      - joint2

launch file:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
import xacro


def generate_launch_description():
    """
    # Gazebo launch
    pkg_gazebo_ros = get_package_share_directory('gazebo_ros')

    # Gazebo world: configure as needed
    pkg_gazebo_world = get_package_share_directory('spawn_rrbot')
    world_relative_path = 'worlds'
    world_filename = 'empty.world'

    gazebo = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(pkg_gazebo_ros, 'launch', 'gazebo.launch.py'),
        )
    )
    """
    # Robot model: configure as needed (for robot_state_publisher & spawn_entity_client.py)
    robot_model_package = "rrbot_unit5"
    robot_model_relative_path = "urdf"
    robot_model_file = "rrbot.xacro"
    robot_name = "rrbot"
    position_x = "0.0"
    position_y = "0.0"
    position_z = "0.0"

    xacro_file = os.path.join(get_package_share_directory(
        robot_model_package), robot_model_relative_path, robot_model_file)

    doc = xacro.parse(open(xacro_file))
    xacro.process_doc(doc)
    robot_description_config = doc.toxml()
    robot_description = {'robot_description': robot_description_config}

    node_robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[robot_description]
    )

    spawn_entity = Node(package='spawn_robot',
                        executable='spawn_entity_client.py',
                        arguments=[robot_model_package,
                                   robot_model_relative_path,
                                   robot_model_file,
                                   robot_name,
                                   position_x,
                                   position_y,
                                   position_z],
                        output='screen')

    

    return LaunchDescription([
        node_robot_state_publisher,
        spawn_entity,

    ])

Hi @azurechen1203 ,

I think you need to launch rrbot_controller_manager.launch.py before executing the
ros2 control load_controller --set-state start forward_position_controller command.

So you will first launch the simulation (if not launched already). Then spawn the robot. Then start the controller manager launch file. Finally you will execute the load controller command.

Please try the above steps and let me know if that worked for you.

Regards,
Girish

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.