This repo provides a basic publisher and subscriber example in ROS2 along with a turtlebot3 which navigates to set waypoints. The pub/sub package has a talker node which publishes a message and a listener node which subscribes and listens to the message.
The turtlebot waypoint simulation uses a script to launch a gazebo instance with turtlebot world and another script to launch nav2, rviz2 and an AMCL node which initializes the turtlebot's position. With a navigator script which uses the CommanderAPI of navigation2, a node is created which sends navigation goals to the rviz2.
-
Install ROS2 humble from the ROS2 installation guide.
-
Install Gazebo sim from the Gazebo installation guide.
-
Install Navigation2 binaries from the Nav2 installation guide.
-
Install VCS Tool from here
-
Install colcon build tool from here
After installing all the pre-requisites, source the ROS2 setup.bash file to load all the binaries and libraries
source /opt/ros/humble/setup.bashCreate your workspace
mkdir -p ~/ros_ws/src
cd ~/ros_wsCopy your repo files in the workspace, here turtlebot3.repos to build the turtlebot3 into your workspace.
vcs import src < turtlebot3.reposThen build and source your workspace using
colcon build
source install/setup.bashYour turtlebot is now setup as a package in your workspace.
You can create your own package using the command below, make sure you are in your src folder before creating a package.
cd src/
ros2 pkg create --build-type ament_python <package-name> --dependencies rclpyNow you can develop your own package as you wish.
Make sure you have installed all the dependencies and sourced the ROS2 setup file, now clone the repo and cd into it.
git clone https://github.com/Rohan-SSS/ros2_ws
cd ros_wsBuild the packages and source the workspace
colcon build --symlink-install
source install/setup.bashIf you see a warning after building or a stderror, you can ignore it.
Open 2 terminals and cd into the ros_ws, also source the install/setup.bash and run the following command in a terminal to start the talker or publisher node.
ros2 run hello_ros2 talker and in the other terminal run the following command to start the listener or subsrciber node.
ros2 run hello_ros2 listenerOpen 3 terminals and cd into the ros_ws, also source the install/setup.bash and run the following command in a terminal to start the turtlebot and world in gazebo.
ros2 launch turtlebot3_sim turtlebot3_world.launch.py and in another terminal run the following command to start rviz2 which also start the nav2 and an AMCL node.
ros2 launch turtlebot3_sim nav2.launch.pyAfter both the gazebo and rviz2 successfully starts, now in another terminal run the following command to create a Node which sends goals or waypoints to the navigation stack.
ros2 run turtlebot3_sim nav_to_pose Now the turtlebot would be navigating the set waypoints.