Controlling each motor of ROSbot XL Individually

Hi,

I would like to implement a planning algorithm on ROSbot XL, since it has omnidirectional wheels, and I was wondering if we have access to the speed of the motors individually. If so, what topic should we publish the commands to for each motor? Thank you so much!

Hello @Nariman,

You can control individual wheels directly, but safety functions make unrestricted use difficult. The feature you’re looking for is available via the /_motors_cmd topic. You can publish messages to this topic using the following command:

ros2 topic pub /_motors_cmd std_msgs/msg/Float32MultiArray "layout:
  dim: []
  data_offset: 0
  data: [0.0, 0.0, 0.0, 0.0]" -r 50

The data field represents the angular velocity for each wheel in rad/s, in the following order: Rear Right (RR), Rear Left (RL), Front Right (FR), Front Left (FL).

Important Notes

When you launch the ROS driver, either the diff_drive_controller or mecanum_controller will start by default (you can enable the mecanum_controller by adding the mecanum:=true flag in compose.yaml). Both controllers will send zero values by default if no commands are received on cmd_vel, which effectively stops the robot if the connection is lost. This could cause any data you send via the topic to be overridden by the zero values from the controller. To avoid this:

  1. You can run the microros service by itself, without the rosbot_ros service (use docker compose up microros). However, this will cause other topics to disappear.

  2. You can disable the controller, but this will require modifying the code in the repository at: GitHub - husarion/rosbot_xl_ros: ROS 2 packages for ROSbot XL.

  3. Alternatively, you can create your own controller. You can use this as a reference: husarion_controllers/mecanum_drive_controller at main · husarion/husarion_controllers · GitHub.

This functionality is provided by the lowest-layer driver and is included in the microros service, which you can run independently.

Hi,

thank you so much for your complete answer! It definitely helps a lot. I will try to do as you said. I was wondering only about the part we will need to edit in the code at the repository to stop overwriting on the controller we are developing/disabling the default controller for the robot. Thank you!

Hello @Nariman,

  1. There is no ready-made python code example for your purposes.

  2. As for modifications, it’s hard for me to say what you should do because I don’t know what exactly you want to achieve.

    a) If yo u are not satisfied with the operation of mecanum_controller, it would be best to edit it as you wish or fine-tune its parameters. From the controller level you have access to hardware interfaces.

    b) If you want to disable sending 0, you should probably just comment this line rosbot_hardware_interfaces/src/rosbot_system.cpp at main · husarion/rosbot_hardware_interfaces · GitHub and rebuild the package. However, I haven’t tested this thoroughly.

Hi @RafalGorecki,

Thank you so much! I will try 2. b and post the results here as well!

Hi,

as promised, I checked publishing on /_motors_cmd and what I realized is that if the frequency of publishing on this node is high enough, it can overwrite the other node that is trying to stop the motors. Of course, it is a lazy approach but it works! In the future, I will try rebuilding the source file with that modification and running the robot with it and see if we get any improvements. Thank you!

1 Like