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

Main video

Extra video

Main video blog post
Extra video blog post

This is the discussion topic for the video and blog post linked above. Please keep all replies relevant to the content, otherwise create a new topic.

Hi Josh just watched the videos you posted dropped for module number 12. I’m getting really excited as I see all of this coming together. I’ve been collecting the bits and pieces to build my own set up and follow your tutorials.

My question has to do with the physical hardware controller that you used it looks like it’s a gaming controller of some kind. I’m not very familiar as I don’t have a gaming system or play one.

I realize that ultimately I could use most any gaming controller if I wanna just write my own inner face but for the moment I just wanna duplicate what you’ve done and then branch off on my own

Do you have any thoughts or recommendations on a particular one to buy and start with So I can use the exact configuration you are using?

Hey Eric, I’ll be diving deeper into that in 2 videos time, but here’s a few quick points :slight_smile: :

  • I’m using an old wired (USB) Xbox 360 controller
  • There are generally 3 types of controllers: USB wired, Bluetooth, and wireless with a USB dongle
    • Wireless is obviously nicer, and means you can connect to either the robot or a development machine on the network, whereas wired kind of restricts you to the latter
    • I don’t trust Bluetooth reliability, especially on Linux and on the Pi, so I prefer USB-based options, but many people do have success with Bluetooth (PlayStation controllers being a classic for this). It’s also more annoying to re-pair etc.
  • Depending on the controller you may or may not need Linux drivers for it (just as if you were playing a game with it). In my limited experience, USB wired ones usually work with no extra software or issues, wireless/Bluetooth can be trickier.
  • Once the OS sees it as a “joystick” they are all pretty much the same as far as ROS is concerned. We use joy/joy_node to read the raw joystick data from the OS and publish it to /joy.
  • Now that the joystick input is available as a ROS topic we can do whatever we want with it. For our differential drive robot, we use teleop_twist_joy to take those axis/button press measurements from /joy and convert them to a Twist message on /cmd_vel. The axis/button numbering will be different for different controllers, you just have to set the parameters accordingly (e.g. axis 1 is forward/reverse, axis 2 is left/right, button 4 is enable).
  • So with all that being said pretty much any controller/joystick/gamepad will work. I personally just like the ergonomics of the Xbox controllers, and I’ll see if I can get my wireless one (Xbox One S version w/ Bluetooth) going for the video, otherwise I usually just plug the wired one into a laptop and carry it around.
  • In the video I’ll also briefly cover connecting a gamepad to your phone, and then connecting the phone to ROS. For that I’ll be using this Bluetooth phone gamepad, but I’d be hesitant to recommend it as I found the joystick deadzones too jarring.
  • Thanks for prompting me to think about this. I’ve just ordered this one (eBay Australia link) as it seems like it might be a fairly common, cheap one, so hopefully it works ok and I can recommend it in future.

Hope that helps!

Josh, thank you. Helpful information. I just purchased the same controller for $13 USD, so I can test what you are doing. I think it is helpful when you post links to what parts you are using so others can follow-along.


1 Like

Josh, I’ve been thinking about an idea for a future tutorial for you, related to robot control. It’s one I would really like to see.

Once you have the ROS2 Control working with your joystick/game controller, I would like to see you add a control node using an Arduino., LCD shield, a few buttons and potentiometers. This would help us see how your Arduino node would do for I/O, say on a custom portable control pendant. Here’s what I have in mind:

2 buttons - Honk Remote buzzer or flash LED headlights.
3 potentiometers - speed control, throttle (and, ideally, steering, perhaps using a dual pot joystick but I understand that is more involved).

Buzzer - when a bump switch on robot is activated it should trigger this buzzer/light/whatever
LCD - One line for Speed and heading (relative to anything you can grab); One line for angle of something, like the wheels; and One line for distance to object – whatever is in front.

What I am really keen to learn is how you would plan this and do the interface to both broadcast and listen to the appropriate pins/signals.

The concepts you develop here, perhaps with input from the community, would allow us to make custom controllers with bidirectional capabilities.

If you do not have an LCD shield, I would be happy to make a contribution to cover one.

I would really like to see this in a future video.

Thanks for all you do to teach and guide us.


Update: If the above is a task that is better suited for a Raspberry Pi, that is OK. If so, I would like to understand why (e.g. software, IO, libraries, etc. If Raspberry PI, could we use a PICO W with an I2C Shield or something?). This is what I think an excellent concept that people [like me] could run with once they an understanding of how to approach this. Thanks for considering.

Hey Eric, interesting idea!
Are you imagining something like the ones James Bruton has made for his videos?
He’s had a few different ones (at least 3), but the “old one” shown at the start of this video seems to be what you’re describing.

I had not considered it, but that’s not a bad idea, I will give it further thought. I’d probably be leaning toward the Pico W (as you’ve suggested) and programming it with micro-ROS or CircuitPython, but those decisions would mostly be driven by me having never used those platforms before and it seems like a good starter project to get my feet wet.

Yes! I had forgotten about his video. I’ve had the idea in the back of my mind for too many years, but the missing link was the software. You are convincing me that ROS2 is the way to go.

Please do consider the basic proposal in one of your upcoming videos. Happy to help brainstorm.

UPDATE: I just watched the video again. I like his idea of using a touch screen for more virtual buttons. Might be cool someday to touch a map of the room and the robot goes there. Then a PTZ Camera on the robot can beam video back. He uses an Arduino to manage the I/O and send/receive commands via Serial to USB into the Pi, which runs the ROS node. Source code in his github but I think it may be ROS not ROS2.

Hi Josh,

Thanks for share this ros2 control video it is very helpful.
I am getting this error while running “ros2 launch my_bot launch_sim.launch.py”. If you have any suggestions to resolve this issue. kindly pleas share it with me.

[gzserver-2] [ERROR] [1669334236.428722199] [gazebo_ros2_control]: parser error Couldn’t parse params file: ‘–params-file /home/niranjan/dev_ws/install/my_bot/share/my_bot/config/my_control_params.yaml’. Error: Cannot have a value before ros__parameters at line 4, at /tmp/binarydeb/ros-foxy-rcl-yaml-param-parser-1.1.14/src/parse.c:623, at /tmp/binarydeb/ros-foxy-rcl-1.1.14/src/rcl/arguments.c:388


Hi Josh,

I think I am able to resolve this issue. It looks like the my_controls.yml parameter file ros__parameters requires two underscore I had a typo here. After fixing the typo the issue got resolved.


Glad you were able to get it fixed!
And yes that double underscore is an easy mistake to make, I’ve definitely tripped on that before!

1 Like

Hi I have a problem guys, after implementing ros2_control , the robot moves in the opposite direction (forward and backwards) in rviz2… Gazebo is working fine though (except for the publish_rate thingy)… please any ideas on how to solve this?

Hmm, the first thing I’d say would be to step through and make sure you understand your kinematic chain, i.e. which axes are pointing in which direction. I believe I had Z pointing out, i.e. the left wheel is “positive-Z-rotation-forwards” and the right wheel is “positive-z-rotation-backwards”.

The axis of the right wheel joint is then flipped, and you should be able to check this by not running ros2_control and instead using joint_state_publisher to manually control the joint angles. Make sure that a positive joint corresponds to the robot moving forward and vice versa.

Then in ros2_control.xacro and my_controllers.yaml (or whatever you have called them), ensure that left and right are assigned correctly.

Finally, make sure that your fixed frame is odom in RViz.

Let me know how you go!

1 Like

Hello Josh,

After implementing the fix to increase gazebo clock rate, I get the following error message when running gazebo - even though it otherwise seems to be working fine:

[gzserver-2] Error [parser.cc:403] Error parsing XML in file [/home/mhered/dev_ws/install/manolobot_uno/share/manolobot_uno/config/gazebo_params.yaml]: Error document empty.

If appears it is trying to interpret the gazebo_params.yaml file as XML and failing.

I noticed also your comment in the blog post:

On my computer I also get an error printed in the Gazebo terminal which is a bit annoying, I think the Gazebo command line parser is treating the file as an extra SDF to load and failing. We can just ignore it, but if you’ve got a fix then let me know!

Is this the error you refer to?

I got it fixed. it was the kinematic chain problem. Thank you

1 Like

So I’ve been fallowing your tutorial for a project. Thank you BTW. It’s been hard to find Raspberry Pi examples.
Problem is. I ran this part of the tutorial last night and it all seemed to work with exception of a type in my config. The robot started doing flips when set to move forward. Anyways I think I got that solved but now, today when I try to run it the controller manager is not loading… All the sudden it’s just not there any more.
ros2 run controller_manager spawner diff_cont
[INFO] [1679414845.079311127] [spawner_diff_cont]: Waiting for ‘/controller_manager’ node to exist
[INFO] [1679414847.090650840] [spawner_diff_cont]: Waiting for ‘/controller_manager’ node to exist
[INFO] [1679414849.100639643] [spawner_diff_cont]: Waiting for ‘/controller_manager’ node to exist
[INFO] [1679414851.114171358] [spawner_diff_cont]: Waiting for ‘/controller_manager’ node to exist
[ERROR] [1679414853.122073734] [spawner_diff_cont]: Controller manager not available

Why now? Worked last night. I can’t even list interfaces… Same problem.

Okay… Somehow controller manager mysteriously started working.
Thanks to Niranjan_Rao pointing out the underscore issue, that did make a difference.

But now he is back to doing flips instead of moving forward or reverse. I’m sure I’ll figure it out, obviously a config issue.

HI Josh,
Didn’t find any issues until Ros2_control was introduced.

With gazebo_ros2_control my robot moves only forward and backwards, doesn’t respond the angular velocity command and the /odom frame doesn’t show up in the RVIZ fixed frame selection list.

i have tried it on Foxy and humble. the result is the same.

Any ideas how I can fix this.

1 Like

Hi Josh,
Your tutorial is very helpful. and i want to use ros_control to control my robot with ackermann type instead of your diff.
You can make a video tutorial. I sincerely thank

Further into the investigation i have noticed the odom TF has the below error.

Error: TF NAN_INPUT: Ignoring transform for child_frame_id “base_link” from authority “Authority undetectable” because of a nan value in the transform (-nan -nan 0.000000) (-nan -nan -nan -nan)
at line 278 in /tmp/binarydeb/ros-foxy-tf2-0.13.14/src/buffer_core.cpp
Error: TF DENORMALIZED_QUATERNION: Ignoring transform for child_frame_id “base_link” from authority “Authority undetectable” because of an invalid quaternion in the transform (-nan -nan -nan -nan)

@JoshNewans Can you please help me out on what causes this error and how to resolve it. This has practically stopped me in continuing further in to this wonderful tutorial.

I’m having the same problem. Everything works except the angular velocity