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

gazebo_ros2_control Plugin Error #42

Open
NoobiesDoobies opened this issue Aug 11, 2024 · 0 comments
Open

gazebo_ros2_control Plugin Error #42

NoobiesDoobies opened this issue Aug 11, 2024 · 0 comments

Comments

@NoobiesDoobies
Copy link

NoobiesDoobies commented Aug 11, 2024

Hi, I'm using Ubuntu 22.04 with ros-humble and gazebo-classic. When I use gazebo_ros2_control/GazeboSystem plugin for my ros2_control framework, I get this error:

[ros2_control_node-2] what(): According to the loaded plugin descriptions the class gazebo_ros2_control/GazeboSystem with base class type hardware_interface::SystemInterface does not exist. Declared types are diffbot_control/DiffBotSystemHardware fake_components/GenericSystem mock_components/GenericSystem test_hardware_components/TestSystemCommandModes test_hardware_components/TestTwoJointSystem

When I launch it using my own ros2_control plugin, it works. I made my own plugin (The diffbot_control/DiffBotSystemHardware) by following one of Josh's tutorials (here is my ros2_control hardware interface plugin). It is based on the HardwareInterface::SystemInterface class. However, gazebo_ros2_control seems to not use the same class (?)

This is my control urdf:

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

  <xacro:macro name="diffbot_ros2_control" params="name prefix use_mock_hardware">

    <ros2_control name="${name}" type="system">
      <xacro:unless value="${use_mock_hardware}">
        <hardware>
          <plugin>diffbot_control/DiffBotSystemHardware</plugin>
          <param name="example_param_hw_start_duration_sec">0</param>
          <param name="example_param_hw_stop_duration_sec">3.0</param>
          <param name="left_wheel_name">left_wheel_joint</param>
          <param name="right_wheel_name">right_wheel_joint</param>
          <param name="imu_name">mpu_6050</param>
          <param name="loop_rate">30</param>

          <!-- First Arduino for motor command and encoder reading -->
          <param name="device_motor_bridge">
            /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_557393239373515181E1-if00</param>
          <!-- Second Arduino for IMU reading -->
          <param name="device_imu_bridge">
            /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_75735353338351E050A1-if00</param>

          <!-- <param name="device">/dev/ttyACM0</param> -->
          <param name="baud_rate">57600</param>
          <param name="timeout_ms">1000</param>
          <param name="enc_counts_per_rev">425</param>
          <param name="imu_calib_timeout_ms">100000</param>
          <param name="pid_p">10</param>
          <param name="pid_d">0</param>
          <param name="pid_i">5</param>
          <param name="pid_o">0</param>

        </hardware>
      </xacro:unless>
      <xacro:if value="${use_mock_hardware}">
        <hardware>
          <plugin>gazebo_ros2_control/GazeboSystem</plugin>
        </hardware>
      </xacro:if>
      <joint name="${prefix}left_wheel_joint">
        <command_interface name="velocity" />
        <state_interface name="position" />
        <state_interface name="velocity" />
      </joint>
      <joint name="${prefix}right_wheel_joint">
        <command_interface name="velocity" />
        <state_interface name="position" />
        <state_interface name="velocity" />
      </joint>

    </ros2_control>

    <xacro:if value="${use_mock_hardware}">
      <plugin filename="ign_ros2_control-system" name="ign_ros2_control::IgnitionROS2ControlPlugin">
        <parameters>$(find slam_bot)/config/diffbot_controllers.yaml</parameters>
      </plugin>
    </xacro:if>

  </xacro:macro>

</robot>

This is my launch file:

import os

from ament_index_python.packages import get_package_share_directory


from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, TimerAction
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, LaunchConfiguration, PythonExpression
from launch.actions import RegisterEventHandler, DeclareLaunchArgument
from launch.event_handlers import OnProcessStart

from launch_ros.actions import Node



def generate_launch_description():
    
    package_name='slam_bot' 

    use_ros2_control = LaunchConfiguration('use_ros2_control')

    use_ros2_control_dec = DeclareLaunchArgument(
        'use_ros2_control',
        default_value='true',
        description='Use ros2 control if true'
    )

    tracker_params_sim = os.path.join(get_package_share_directory(package_name),'config','ball_tracker_params_sim.yaml')
    tracker_params_robot = os.path.join(get_package_share_directory(package_name),'config','ball_tracker_params_robot.yaml')


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

    joystick = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory(package_name),'launch','joystick.launch.py'
                )])
    )


    # twist_mux_params = os.path.join(get_package_share_directory(package_name),'config','twist_mux.yaml')
    # twist_mux = Node(
    #         package="twist_mux",
    #         executable="twist_mux",
    #         parameters=[twist_mux_params],
    #         remappings=[('/cmd_vel_out','/diff_cont/cmd_vel_unstamped')]
    #     )

    


    robot_description = Command(['ros2 param get --hide-type /robot_state_publisher robot_description'])

    controller_params_file = os.path.join(get_package_share_directory(package_name),'config','diffbot_controllers.yaml')

    controller_manager = Node(
        package="controller_manager",
        executable="ros2_control_node",
        parameters=[{'robot_description': robot_description},
                    controller_params_file],
        output="both",
        remappings=[
            ("~/robot_description", "/robot_description"),
        ],
    )

    delayed_controller_manager = TimerAction(period=1.0, actions=[controller_manager])

    diff_drive_spawner = Node(
        package="controller_manager",
        executable="spawner",
        arguments=["diffbot_base_controller"],
    )

    delayed_diff_drive_spawner = RegisterEventHandler(
        event_handler=OnProcessStart(
            target_action=controller_manager,
            on_start=[diff_drive_spawner],
        )
    )

    joint_broad_spawner = Node(
        package="controller_manager",
        executable="spawner",
        arguments=["joint_state_broadcaster"],
    )

    delayed_joint_broad_spawner = RegisterEventHandler(
        event_handler=OnProcessStart(
            target_action=controller_manager,
            on_start=[joint_broad_spawner],
        )
    )
    gazebo_params_file = os.path.join(get_package_share_directory(package_name),'config','gazebo_params.yaml')

    # 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')]),
                    launch_arguments={'extra_gazebo_args': '--ros-args --params-file ' + gazebo_params_file}.items()
             )


    # Launch them all!
    return LaunchDescription([
        use_ros2_control_dec,
        robot_spawner,
        gazebo,
        # joystick,
        # twist_mux,
        delayed_controller_manager,
        delayed_diff_drive_spawner,
        delayed_joint_broad_spawner
    ])

Can anybody help me resolve this issue? I have made sure that the gazebo-ros2-control package is installed by running
sudo apt install ros-humble-gazebo-ros2-control

Thanks !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant