Discussion - Running ros2_control on a real robot (Making a Mobile Robot Pt 13)

Hi Josh, Thanks for a great series. I got pretty much stuck on getting it all to work on a real robot. I’m running Humble on Ubuntu 22.04. Since ROS-Serial has been replaced by MicroRos I went that route.

Here’s my setup:
Ubuntu 22.04 on a virtual machine (some issues along the way as you mentioned but all sorted)
Completed diff drive robot with RPi4 (Ubuntu 22.04), Arduino Due (MicroRos), L298N motor driver.

I can control the robot with Twist messages and I can publish odometry from the Arduino. The problem is getting it to work with ros2_control and specifically implementing a hardware interface.

The way I understand it is that diffdrive_arduino won’t work in this scenario because it relies on ROS-Serial. I did try to use ros2_control_demos to solve the problem but did not succeed.

So my question is:
Can diffdrive_arduino work in this setup?
If so, how do I get that to work?
If diffdrive_arduino can’t work, what are my options?

The MicroRos and ros2_control combo seems pretty new and I can find very little about it. I’ve been working on this for a few weeks now but I’m not getting any further.

Yeah so the confusion here (and it’s not just you, others have had the same issue) is that diffdrive_arduino does NOT use rosserial (or micro-ROS for that matter).

rosserial is a method for sending ROS messages over a serial line (to an Arduino or similar). And now with micro-ROS those kinds of problems can be solved differently.

Whereas diffdrive_arduino isn’t sending ROS messages at all, it is making a pure serial connection to software on the other end, speaking a (very simple) custom protocol. So you shouldn’t have rosserial or micro-ROS running on the Arduino, it doesn’t know anything about ROS, just some simple motor control serial commands. diffdrive_arduino is doing all the translation from ROS to serial.

If you really want to use micro-ROS on the Arduino, it probably makes sense to skip ros2_control completely. And that is a perfectly acceptable setup - just not what I’ve done in my tutorials. In that case you’ll probably want to have the Arduino receiving a Twist and handling all the diff-drive calculations (which it seems you are doing), rather than implenting it on the ROS side.

I hope that clears things up, if not please ask further questions!

Thanks for the super quick reply Josh, that clears it all up. I’m going to stick with your route so that I can follow your track in coming videos. I’m going back to the motor control video to implement RosArduinoBridge and then implement diffdrive_arduino. Plenty of time to play around with MicroRos etc later.

1 Like

Hi, I’m having a problem getting my pi to locate the ros2 control package using ‘sudo apt install’. It just cannot find it. I’ve updated and upgraded, following the instructions here: Ubuntu (binary) — ROS 2 Documentation: Humble documentation

Any idea what’s going wrong? I’m surprised I can’t get the system to locate it. Is there a workaround? Thanks for any help!

@JoshNewans sir . I was able to run the robot in real time but unable to run in the rviz i.e the robot was not moving in the rviz
I have tried to change frames but no result , is there any solution I was using ros2 humble and 22.04

Hey Jon, this should be fixed with the latest humble update, so if you try an apt update and then go again hopefully it will be there. Let me know if you have further troubles.

Hi,

Thanks for the great tutorial. I followed everything correctly till Ros2 Controller. My setup is a 4 wheel robot instead of 2 wheels. I have used differential drive and setup wheel count as 2. Everything worked perfectly until I added diffdrive_arduino package. I have modified the package to take in four wheels as input. However the issues are:

  1. When I try driving, all the wheels are reversed. I modified the diffdrive package to take inverted inputs (- for all vel1, vel2, vel3 and vel4). This seems to fix and motors driving correctly
  2. Teleop twist keyboard can be used to control the robot only if linear and angular velocity is set to 0.4xxx. Anything more than 5 or less than 3 does not move the wheels at all.
  3. Not all motors rotate at the same speed.

So, my questions are:

  1. Can I use the previous serial_motor_demo library to complete SLAM setup?
  2. Any ideas why the robot is not responding to twist correctly?

Hi Praveen!

There are a bunch of places that wheel reversing can occur, depending on your hardware. Getting the wrong pins on the driver in, the driver out, the controller, the wrong axis direction in URDF, etc. It sounds like what you’ve done there is probably not the “correct” solution, but if it works, it works :slight_smile:

That’s very odd. To start with diagnosing I’ll need more detail on your motors/controllers/drivers etc. (which might also help us with problem 1). Depending on how things are being mapped it’s not unusual for there to be a lower limit that it won’t turn below, but an upper limit is strange.

This is unfortunate, but not too surprising. Again, we’ll need more details on how you have things hooked up but this is where the PID controller comes into play (which if you’re following the tutorials will be external to ROS/Pi stuff, in an Arduino or some other dedicated controller). The quality control of the motors will be a factor, but the PID controller should be able to be tuned to get the motors performing fairly similarly. If you don’t have a PID controller and are running in open loop, that might also be the cause of problem 2.

Sort of. You could modify it to accept a Twist and have differential drive control, but you’d be better off fixing the other issues instead and things should just work.

Yeah, by the sound of things it’s worth stepping through the details of your setup and making sure the low-level motor control is working before touching the ROS-level stuff. If it’s broken then no amount of ROS tweaking will fix things!

So please post some more details about your hardware and how it’s wired up (you can upload pictures to imgur and embed them here) and we’ll see what we can figure out :slight_smile:

[INFO] [launch]: All log files can be found below /home/system/.ros/log/2023-03-21-14-56-32-932971-mapperbot-5148
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught exception when trying to load file of format [py]: name ‘Command’ is not defined

Is there an import I’m missing?

There most certainly was :slight_smile:
from launch.substitutions import Command