This ROS 2 package simulates a differential drive robot. It processes velocity commands, converts them into wheel encoder ticks, computes odometry, publishes TF transforms, and visualizes the robotβs path using RViz.
| File | Purpose |
|---|---|
diff_tf.py |
Computes odometry and publishes /odom and /tf using encoder ticks |
twist_to_wheels.py |
Converts velocity commands (/cmd_vel) into left/right encoder ticks |
drive_cmd.py |
Publishes sample velocity commands using geometry_msgs/Twist |
drive_wheels.py |
Subscribes to /cmd_vel and publishes to /lwheel and /rwheel |
trajectory_publisher.py |
Publishes path traced from odometry to /robot_path |
__init__.py |
Required Python init file for the package |
/cmd_velβ Velocity commands (geometry_msgs/Twist)/lwheel&/rwheelβ Wheel encoder ticks (std_msgs/Int64)/odomβ Odometry output (nav_msgs/Odometry)/tf&/tf_staticβ Robot transform frames/robot_pathβ Path generated from odometry (nav_msgs/Path)
Make sure your ROS 2 workspace is sourced and the package is built.
cd ~/ros2_ws
colcon build
source install/setup.bash-
Send velocity commands:
ros2 run diff_drive_bot drive_cmd
-
Convert
cmd_velto wheel encoder ticks:ros2 run diff_drive_bot twist_to_wheels
-
Compute odometry from encoder data:
ros2 run diff_drive_bot diff_tf
-
Publish robot path:
ros2 run diff_drive_bot trajectory_publisher
- ROS 2 (Foxy, Humble, or later)
- Python 3
readcharPython module (for keyboard input indrive_cmd.py)
Install readchar if needed:
pip3 install readcharFull tutorial with URDF modeling and RViz visualization:
π https://github.com/JAnthem9606/ROS-Basics
Developed by Bilal Ahmed (JAnthem9606)
A complete educational ROS 2 robot simulation package.
Launch your URDF in RViz and view real-time TFs and robot path with:
ros2 launch urdf_tutorial display.launch.py model:=urdf/robot.urdf
ros2 run tf2_tools view_frames