A ros 2 simulated robot(ROS 2)
Fisrt step in building the differential-drive robot:
In the src directory of your workspace , make a folder called "robot" and clone the repo in it.
cd src
mkdir robot
cd robot
git clone https://github.com/Daviesss/Ros-2-simulated-robot..git
If you build the workspace and you see some errors pop up .You should upgrade pytest to a version that is 6.2 or higher. Use the following command
pip install --upgrade pytest
Then build the workspace again:
colcon build
Launch the Node:
ros2 launch <name_of_package> robot.launch.py
The joint state publisher node must be launched/be active when launching the robot in rviz2.
ros2 run joint_state_publisher_gui joint_state_publisher_gui
Open Rviz2:
ros2 run rviz2 rviz2
Set the fixed frame to "base_link".
The centre of the robot which is the "base_link".
Plugins used in simulation of the robot can be gotten from: https://classic.gazebosim.org/tutorials?tut=ros_gzplugins
STEPS TO TAKE TO GET THE ROBOT UP AND READY:
- Launch the robot_state_publisher in simulation mode.
- Launch Gazebo.
- Spawn the robot into Gazebo.
Set the sim time to true,we dealing with simulation.So our the boolean has to be true.
ros2 launch robot show.robot.launch.py use_sim_time:=true
Start up Gazebo empty world:
ros2 launch gazebo_ros gazebo.launch.py
To spawn the robot into gazebo, launch the file called show.robot.launch.py (Note: launch files in ROS 2 are python scripts/files)
Command:
ros2 launch robot show.robot.launch.py
Check if the topics are available.This list all topics which are available:
ros2 topic list
Now,we can drive the robot around once we use the teleop_twist_keyboard node to publish to the "/cmd_vel" topic that the robot subscribes to.
ros2 run teleop_twist_keyboard teleop_twist_keyboard
You can give colour to the robot,by adding colour to the .xacro file.Video decription below,while using the teleop_twist_keyboard to drive the robot.
We can also write a python script that publish certain velocity to make the robot move and also perform some basic task. Create a ROS 2 package called drive_robot ,its dependecies on rclpy,the package should be created in the src directory of your workspace.
cd src
ros2 pkg create drive_robot --build-type ament_python --dependencies rclpy
Run the node in the pasckage to make the robot drive forward, in linear of x.
ros2 run drive_robot velocity_drive
ros2 launch robot show.robot.launch.py world:='path to where you saved your Gazebo world'
You can check the TF2 TREE:
ros2 run rqt_tf_tree rqt_tf_tree
ros2 launch robot show.robot.launch.py world:="path to the .world file"
Mine is:
ros2 launch robot show.robot.launch.py world:=/home/magnum/simuate_ws/src/robot/worlds/new.world
Run the slam_toolbox node.
ros2 launch robot online_async.launch.py
Screencast.from.03-09-2023.11.21.33.AM.webm
Localization:
ros2 launch robot localization.launch.py map:=/home/magnum/simuate_ws/src/robot/maps/offline.yaml use_sim_time:=true
But if you want to use the localization mode (AMCL) you have to specify the path in which your map.yaml file is located and pass it into map:=""
- ros2 launch robot localization.launch.py map:="" use_sim_time:=true
Navigation Mode(NAV2 stack)
ros2 launch robot nav.launch.py use_sim_time:=true map_subscribe_transient_local:true