Discussion - Ros2_Control Overview & Simulation (Making a Mobile Robot Pt 12)

Try:

ros2 run controller_manager spawner -h

ros2 run controller_manager spawner diff_cont

No .py

Hi Josh,

@Josh: As many have said, much thanks for your great tutorials on ROS!

Iā€™m building a robot based on your Articubot robot using 2 motors and a (ultrasound) sonar sensor (HCSR04). I am able to control the motors and drive around. But Iā€™m stuck on how to correctly integrate the sonar sensor into ROS.

Iā€™ve integrated the sonar sensor in joshnewans/ros_arduino_bridge example exposing distance information via the serial interface (via a ā€œhā€ command, the distance as reported by the sonar sensor is returned)

Now Iā€™m trying to create a hardware interface that publishes this sonar distance information in a ROS Topic sensor_msg/Range message. I followed the tutorial ā€˜12. Solving the problem EVERY robot has (with ros2_control)ā€™ and concluded that I need to create another State Interface (see https://articulatedrobotics.xyz/media/assets/posts/mobile-robot/12-ros2-control/controllers.png)

I tried to update joshnewans/diffdrive_arduino example to publishing the sensor_msg/Range message in diffdrive_arduino.cpp. But I am unable to do this since I cannot access ROS publish functions. Also reading further on the concepts of ROS, it seems not the correct way to do since diffdrive_arduino is for controlling the diff drive motors and NOT exposing a sonar sensor.

Then I tried to create another node that reads the serial information and publishes the Range message. But then I have the problem that you cannot use 1 serial interface by 2 nodes that each run as separate process.

So my question is:
How do you create 2 controllers exposing 2 hardware_interfaces (System & Sensor) that uses the same serial interface? Is there a way to share 1 serial inteface between ROS nodes?

Regards,

Huub

Hi Josh,
At first, your tutorials are helping in a great course for my career and thanks for your tutorials.

I am trying to understand this ros2_control thing. but I am having the following issue when I am trying to load the controllers. btw I am using ros2-humble distro.

nisat@nt:~/mangobee_robot$ ros2 run controller_manager spawner diff_cont
[INFO] [1706769460.539068927] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[INFO] [1706769462.551452191] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[INFO] [1706769464.564305671] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[INFO] [1706769466.575603025] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[ERROR] [1706769468.585726734] [spawner_diff_cont]: Controller manager not available
[ros2run]: Process exited with failure 1

my_controllers.yaml file as follows:

controller_manager:
  ros__parameters:
    update_rate: 30
    use_sim_time: true

    diff_cont:
      type: diff_drive_controller/DiffDriveController
    
    joint_broad:
      type: joint_state_broadcaster/JointStateBroadcaster

diff_cont:
  ros__parameters:

    publish_rate: 100.0 
    base_frame_id: base_link

    left_wheel_names: ['left_wheel_joint']
    right_wheel_names: ['right_wheel_joint']
    wheel_separation: 0.35
    wheel_radius: 0.05

    use_stamped_vel: false

ros2_control.xacro file as follows,

<?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="left_wheel_joint">
            <command_interface name="velocity">
                <param name="min">-10</param>
                <param name="max">10</param>
            </command_interface>
            <state_interface name="position" />
            <state_interface name="velocity" />
        </joint>

        <joint name="right_wheel_joint">
            <command_interface name="velocity">
                <param name="min">-10</param>
                <param name="max">10</param>
            </command_interface>
            <state_interface name="velocity" />
            <state_interface name="position" />
        </joint>

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

    </ros2_control>

</robot>

Please help me solve this issue.

Thank you
Nisath

I am using ros2 iron and have ā€œContorller manager not availableā€ errors. To make sure its not something I did, I downloaded articubot_one and it has the same issue.

First i fixed the .py issue to get this far:

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

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

Now when I enter
ros2 launch articubot_one launch_sim.launch.py world:=./src/my_bot/worlds/obstacles.world

Looks like I get two errors:

[ERROR] [gzserver-4]: process has died [pid 35946, exit code 255, cmd 'gzserver ./src/my_bot/worlds/obstacles.world -slibgazebo_ros_init.so -slibgazebo_ros_factory.so -slibgazebo_ros_force_system.so --ros-args --params-file /home/willi/shared/dev_ws/install/articubot_one/share/articubot_one/config/gazebo_params.yaml'].

Either the result or the real problem is the following:

[spawn_entity.py-4] [INFO] [1706795144.454419682] [spawn_entity]: Waiting for entity xml on robot_description
[spawn_entity.py-4] [INFO] [1706795144.465585204] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30
[spawn_entity.py-4] [INFO] [1706795144.465941557] [spawn_entity]: Waiting for service /spawn_entity
[spawner-6] [INFO] [1706795146.204682358] [spawner_joint_broad]: Waiting for '/controller_manager' node to exist
[spawner-5] [INFO] [1706795146.405621127] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[spawner-6] [INFO] [1706795148.218729921] [spawner_joint_broad]: Waiting for '/controller_manager' node to exist
[spawner-5] [INFO] [1706795148.418687173] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[spawner-6] [INFO] [1706795150.234781109] [spawner_joint_broad]: Waiting for '/controller_manager' node to exist
[spawner-5] [INFO] [1706795150.429329085] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[spawner-6] [INFO] [1706795152.248062370] [spawner_joint_broad]: Waiting for '/controller_manager' node to exist
[spawner-5] [INFO] [1706795152.447229883] [spawner_diff_cont]: Waiting for '/controller_manager' node to exist
[spawner-6] [ERROR] [1706795154.261474129] [spawner_joint_broad]: Controller manager not available
[spawner-5] [ERROR] [1706795154.459666959] [spawner_diff_cont]: Controller manager not available
[ERROR] [spawner-6]: process has died [pid 34051, exit code 1, cmd '/opt/ros/iron/lib/controller_manager/spawner joint_broad --ros-args'].
[ERROR] [spawner-5]: process has died [pid 34042, exit code 1, cmd '/opt/ros/iron/lib/controller_manager/spawner diff_cont --ros-args'].
[spawn_entity.py-4] [ERROR] [1706795174.516724938] [spawn_entity]: Service %s/spawn_entity unavailable. Was Gazebo started with GazeboRosFactory?
[spawn_entity.py-4] [ERROR] [1706795174.517468743] [spawn_entity]: Spawn service failed. Exiting.

help

Soā€¦ I couldnā€™t get past this error smurffin the innernut yielded notta. I then blew my package away and downloaded joshes to the same resultā€¦ I then download an unrelated Ros2 to package from some other unrelated github and YIKES SAME sameā€¦ Then I completely removed ros2-iron and installed ros2-humble and now everything is fine. It all works as specified. There is some issue/change in iron

Hi Ziad, I am facing the same issue. Did you find the solution?

how would you solve this issue please explain clearly

you can solve this issues, how would you solve this issue please explain clearly

Hi @JoshNewans
Thank you so much for the hardwork.
I have been following and developing a physical robot as well.
I am facing an issue that:
When I shifted to ros2 control, the robot is driving in the opposite direction (in the Gazebo simulation), but when I was working with Gazebo diff_drive, it was running perfectly fine. Can anyone please guide me? I have been struggling with this for 2 days now.
I checked your response to another similar question, so I have similarly used the axis orientations for the wheels, it works good with joint_state_publisher and when working with gazebo_diff_drive, but when I use ros2 control, the wheels rotate inversely.

Can you please shed some light?
Thank you so much!
Thank you