This repository will help you understand how to control a differential drive robot with ros2_control. There are two main packages used to view and control the robot.
The package ign_gazebo_robot_package
is used to visualize the robot in Gazebo and load the controllers to control the robot. The controller diff_drive_base_controller
is used here to control the robot.
The package command_publisher_package
is used to publish commands for the robot to move around. It uses the message type Twist
to send commands. The differential drive robot takes two parameters, the linear position along x axis and angular position along z axis.
The command publishing package uses yaml file to load commands for the robot to move. The parameter goal_names
of type STRING_ARRAY define how many positions has to be passed to the robot. The goal names are then used as parameters to define linear and angular values respectively.
Please find below the versions where the packages have been tested
OS : Ubuntu 20.04
ROS2 : Galactic
Gazebo : Gazebo Edifice
Open terminal and follow the commands mentioned below
mkdir -p dev_ws/src
cd dev_ws/src
Clone the packages of the repository inside the src folder
Make sure to build the package inside dev_ws folder and not inside src folder
colcon build
Source both the underlay and overlay environment
source /opt/ros/galactic/setup.bash
source install/setup.bash
Visualize the robot in Gazebo by running the following command
ros2 launch ign_gazebo_robot_package diff_drive_example.launch.py
You can view a differential drive robot inside Gazebo
Move the robot by running the following command
ros2 launch command_publisher_package cyclic_command_publisher.launch.py
You can also provide your own number of positions inside the dev_ws/src/command_publisher_package/config/cyclic_diff_drive_params.yaml
file. Make sure to build the packages again after editing the yaml file.