Fisrt step in building the differential-drive ZED mobile cleaning robot:
Create your ros2 workspace (You can use any name for your workspace, but follow naming rules.)
mkdir ros_ws
cd ros_ws
Create your src folder
mkdir src
In the src directory of your workspace clone the repo in it to work with robot pkg.
cd src
git clone https://github.com/Oyefusi-Samuel/ZED-mobile-cleaning-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
Source the workspace
source install/setup.bash
STEPS TO TAKE TO GET THE ROBOT UP AND READY:
-
Lauch the robot in an empty world
-
Visualize in Rviz .
-
check the TF2 TREE
Launch the Node: (To visualize the robot in an empty gazebo world)
ros2 launch robot show.robot.launch.py use_sim_time:=true
Launch the rviz Node: (To visualize the robot joint, tf)
ros2 launch robot display.launch.py
You can check the TF2 TREE:
ros2 run rqt_tf_tree rqt_tf_tree
The centre of the robot is the "base_link".
https://classic.gazebosim.org/tutorials?tut=ros_gzplugins
To spawn the robot into gazebo, launch the file called show.robot.launch.py, ensure you save the custom designed gazebo world into the world directory in the src folder (Note: launch files in ROS 2 are python scripts/files)
ros2 launch robot show.robot.launch.py world:="path to the .world file"
Mine is:
ros2 launch robot show.robot.launch.py world:='/home/sam/zed_robot/src/robot/worlds/cafeworld'
ros2 launch robot show.robot.launch.py world:='/home/sam/zed_robot/src/robot/worlds/outside.world'
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 robot description .xacro file.
Run the slam_toolbox node.
ros2 launch ros2_mapping online_async_launch.py
Open rviz to visualize SLAM (add laserscan, mapp tf, robotmodel) topics
rviz2
Now,we can drive the robot around using the teleop_twist_keyboard node to map the world.
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Save your map using the ros2 map server node
ros2 run nav2_map_server map_saver_cli -f /path/to/save/map_name # Saves the current map to the specified path and file name
mine was
ros2 run nav2_map_server map_saver_cli -f /home/sam/zed_robot/src/ros2_mapping/map/map_2 # Saves the current map to the specified path and file name
ff.webm
Run the AMCL node.
ros2 launch ros2_mapping amcl.launch.py
Open rviz to visualize SLAM (add Particlecloud, laserscan, mapp tf, robotmodel) topics, 2d pose estimate, you should see the particle cloud.
rviz2
Now,we can drive the robot around using the teleop_twist_keyboard node to visualize the particle cloud around.
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Localization:
ros2 launch ros2_mapping localization.launch.py
Navigation Mode(NAV2 stack)
ros2 launch ros2_mapping navigation.py # set 2d pose estimate of the robot to begin navigation
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
Install required dependecies
sudo apt install ros-<ros2_distro>-ros-ign-gazebo
sudo apt install ros-humble-ros-ign-gazebo # my current ros distro is humble, you can change to fit your ros version (foxy, jazzy)
sudo apt install ros-humble-ros-gz-bridge
sudo apt install ros-humble-ign-ros2-control
sudo apt install ros-humble-twist-mux
sudo apt install ros-humble-twist-stamper
sudo apt install ros-humble-ros2-control
sudo apt install ros-humble-ros2-controllers
If you are using ros 2 humble distro , just replace <ros2_distro> with humble . So it will be :
sudo apt install ros-humble-ros-gz