Discussion - Writing a ros2_control hardware interface (Making a Mobile Robot Pt 20)

Finally i found the problem and solved. appearently dynamixel functions are expecting integer values instead of double. so i converted them before sending and the code is working on the rpi too.

If anyone has any idea about;

  • Why same function is working with double values in laptop. Is it because of cpu architecture or some kernel differences etc…

  • And why the changes in the urdf didnt affect the way wheels turn.

Hi, same issue here, unfortunately I stuck with this what I found until now refers only sourcing problem but it can’t be my issue. Also it only happens only on the Pi (ROS in docker container) not on my “dev” machine. Have you found the solution? Thanks.

Hi,
I found the problem the ros-humble-control-msgs was missing. Now it looks obvious of course.

1 Like

Hello Josh
Thank you very much for the wonderful videos, they teach beginners how to operate with ROS in an accessible and high-quality way. :v:

I carefully watched all your videos about ROS2_control. Also, I successfully compiled the Hardware Interface according to “Example 2” from the “ros2_control demos” repo.
For now, my robot moves in simulation only (RViz). So, I need to implement reading the current speeds of the robot and setting the target speed through the read() and write() methods.

I already have a driver written specifically for my motor (it is ROS2 package). This driver can successfully connect to the robot via Modbus client, read the traveled distance from the encoders, calculate the current speed of the robot, and set the target velocity speed for each motor.
The main issue is that the driver is written in Python, so I cannot directly combine it with the ROS2_control control manager.

I want to keep that driver without rewriting it to C++. Instead, I would like to modify the read() and write() methods of the Hardware Interface package to transfer velocity and position values through ROS2 topics.

I had a similar type of HW interface when my project was started on ROS1. Unfortunately in the ROS2 hardware interface diffbot_system.cpp file is not an executable item but rather an internal library without the main() function.

I’ve tried to put rclcpp.spin() function into on_init or on_activate methods but has compilation errors (my knowledge of C++ and cMake are not so good).

I would appreciate any ideas or links with some examples to help ROS2_control Hardware Interface exchange values with a publish/subscribe approach.

Hi and appreciate the very useful Video and blog explaining ros2_control and your articubot_one github. I am inspired to use this to adapt and deploy ros2_control expanding to NAV2 functionality, my current ROS 2 humble Desktop/Raspi4 configuration that is a “teleop-only” " Create1 robot based on the original 2010 Turtlebot. AutonomyLabs ( https://github.com/AutonomyLab/create_robot) contains humble packages that launch nodes sumybscribing to /cmd_vel (from a game controller) and publish /odom and urdf robot_description msgs. I added packages that publish RPlidar /scan and rgb image from an Oak-D-Lite. No SLAM or Navigation though. So my plan is to implement ros2_control following your design (with no Gazebo Sim). Seems the place to focus is edits to the Controller Manager by revising “launch_robot.launch.py” and “ros2_control.xacro”. Appreciate your comments/advice as to feasibly and point me to references to simply interface the existing /cmd_vel topic msgs to the ros2_control Diff Drive Controller?

Hello Josh, I am following your tutorial to make robot. I am facing problem with remapping /odom and /cmd_vel topics with diffdrive controller, i have launch diffbot_base_controller with controller_manager spawner .
robot_controller_spawner = Node(
package=“controller_manager”,
executable=“spawner”,
arguments=[“diffbot_base_controller”, “–controller-manager”, “/controller_manager”],
remappings=[
(“/diffbot_base_controller/cmd_vel_unstamped”, “/cmd_vel”),
(“/diffbot_base_controller/odom”, “/odom”),
],
) but topics are not remapping how to solve this issue?

Sorry it’s been a while!
From memory the command interface should be in radians/second.

Hi, apologies for the very late reply!
I can’t remember the context in which I said that, but to get away without encoders you’d need to:

  • Test your motors in open loop under normal load to see how many radians/sec you get for various values from 0 to 255 (remember each motor can be different, in each direction!)
  • Modify the hardware interface so that when it receives the commanded motor velocity, instead of calling the m command it uses the o command, and passes the requested speed through the inverse of the function you just found.

Hi, I’m very new to ros and have a more complicated question:
Is it possible to share one hardware interface between multiple controllers? Because I have a raspi shield that has PCA9685+TB6612.
The first 6 channel of the PCA controlling the tb motor driver, while the next 6 channels of the PCA are used to control servos. As you can see, the PCA is used both for diff drive and for other things. The problem I think about is, when different hardware interfaces try to control the same hardware it will probably end in a mess. The other thing is, when the diff drive controller uses the PCA to control the motor driver, how can a other controller controll the servos at the same time, because they need both to control the same hardware?
So I thought, maybe there is a way to tell ROS2 controll to share the hardware interface between multiple controllers, is this possible?
If not, any ideas or recommendations how to do it other than using other hardware?
Thx in advance
Lanea Lucy

Hi Josh thanks a lot for the videos, They helped me a lot to understand ROS2 and how to build a differential drive bot. I am working on a 4 WD and have been following your tutorials until " [Using ros2_control to drive our robot (off the edge of the bench...)](https://www.youtube.com/watch?v=4VVrTCnxvSw&t=601s)" video. I am facing some trouble after changing to ros2_control, The issue is that my robot is not moving either left or right in gazebo but it seems to move in Rviz as expected. I have searched all the online resources but did not find anything that helps.
here is the link to my repo GitHub - BooraKaushik/autobot
Video of what is happening, IMG_5920.mov - Google Drive
as you can see it is turning fine in rviz but not in gazebo.

I would really appreciate any help.
Thanks,
Kaushik Boora

Did you ever get your 4 wheels to work? If so can I ask what you used for the ros_arduino_bridge?

Does the ros_arduino_bridge that Josh Newans uses work for 4 motors? It would appear to me that it is only designed for 2 motors.

For now I am just working on simulation, but seems like it doesn’t work in the simulation itself

[INFO] [launch]: All log files can be found below /home/umesh/.ros/log/2024-03-20-12-58-36-537694-Mechtronix-13285
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): executed command failed. Command: xacro /home/umesh/mobile_ws/install/mobile_bot/share/mobile_bot/description/robot_urdf.xacro use_ros2_control:=true sim_mode:=true
Captured stderr output: error: substitution args not supported: No module named ‘roslaunch’
when processing file: /home/umesh/mobile_ws/install/mobile_bot/share/mobile_bot/description/robot_urdf.xacro

when I am trying to launch file without using xacro:if statement it works perfectly but after adding that statement and the other code in rsp_launch.py and launch_sim.py , I am getting this error. I checked the code for any syntax error or any other fault but didn’t find any thing unusual. also I am not able to find any absolute reason to this error on Google. i am stuck here pls help. thankyou