Skip to content

5. ROS2

sanket369 edited this page Dec 20, 2023 · 1 revision

Get your Tortoisebot Ready for action

0. Loading Custom Raspberry Pi Image For Tortoisebot on your SD Card

1. Wifi Setup

Setting up your wifi ssid and password in the image file

  1. Insert the SD card into your computer using a card reader.
  2. Navigate to the "writable" folder and then to "/etc/netplan/".
  3. Open the "50-cloud-init.yaml" file in a text editor.
  4. Look for the "wifis" section in the file.
  5. Add the following code under the "wifis" section, replacing "ssid_name" with your WiFi name and "psd" with your WiFi password:
wlan0:
  optional: true
  access-points:
    "ssid_name":
      password: "psd"
  dhcp4: true

TTB IRL TTB IRL

  • Example

TTB IRL

  1. Save the file and exit the text editor.
  2. Safely eject the SD card from your computer and insert it into the robot.
  • The above steps will add your WiFi network credentials to the robot's configuration file, allowing it to connect to your WiFi network.

2. Create ROS 2 Workspace

source /opt/ros/galactic/setup.bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/
colcon build
~/ros2_ws/install/setup.bash

3. Install Dependencies

sudo apt install ros-galactic-joint-state-publisher ros-galactic-robot-state-publisher ros-galactic-cartographer ros-galactic-cartographer-ros ros-galactic-gazebo-plugins ros-galactic-teleop-twist-keyboard  ros-galactic-teleop-twist-joy ros-galactic-xacro ros-galactic-nav2* ros-galactic-urdf 

4. Clone Repository

cd ~/ros2_ws/src
git clone -b ros2-galactic https://github.com/rigbetellabs/tortoisebot.git
cd ~/ros2_ws/
colcon build
source /opt/ros/galactic/setup.bash
source ~/ros2_ws/install/setup.bash

5. Simulation

Get your Tortoisebot running in Simulation!

1. Let's get started by opening up a terminal and entering the world of ROS2!

Type the following command to enter the ROS2:

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash

2. Now, let's have some fun with simulation and sensor data visualization!

Type this command in another terminal:

ros2 launch tortoisebot_bringup bringup.launch.py use_sim_time:=True

Gazebo and Rviz

3. Look at that! You have a Tortoisebot running in Gazebo and Rviz! You can visualize its sensor data too! Now, let's get ready for teleoperation.

Type this command in another terminal:

ros2 run teleop_twist_keyboard teleop_twist_keyboard 

4. Whoop whoop! You are now teleoperating the Tortoisebot!

Gazebo n Rviz Giving a Goal

5. Let's move on to simulation and navigation in exploration mode!

Type this command in another terminal:

ros2 launch tortoisebot_bringup autobringup.launch.py use_sim_time:=True exploration:=True

6. Woohoo! The Tortoisebot is exploring the simulated environment autonomously! You can give it a goal to navigate to as well! Check out the following image:

Gazebo n Rviz Giving a Goal

Make your Tortoisebot explore your room!

1. Let's now move on to simulation and SLAM! First, enter the ROS2 world by typing the following command in a new terminal:

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash

2. Now, let's start the Gazebo simulation and SLAM!

Type this command in another terminal:

ros2 launch tortoisebot_bringup autobringup.launch.py use_sim_time:=True exploration:=True

3. Whoa! The Tortoisebot is now mapping the environment! You can teleoperate it to map the environment even better!

Exploration Sim Rviz and Gazebo

4. Let's save the map now! Type this command in another terminal:

ros2 run nav2_map_server map_saver_cli -f /path_to_map/name_of_map_file.yaml

You'll be able to see something similar to this on your terminal:

kartik@kartik:~/Desktop/rigbetel_labs/tortoisebot_ws$ ros2 run nav2_map_server map_saver_cli -f /home/kartik/Desktop/rigbetel_labs/tortoisebot_ws/src/tortoisebot/tortoisebot_bringup/maps/room2.yaml
[INFO] [1680187250.898838998] [map_saver]: 
  map_saver lifecycle node launched. 
  Waiting on external lifecycle transitions to activate
  See https://design.ros2.org/articles/node_lifecycle.html for more information.
[INFO] [1680187250.898933015] [map_saver]: Creating
[INFO] [1680187250.899004279] [map_saver]: Saving map from 'map' topic to '/home/kartik/Desktop/rigbetel_labs/tortoisebot_ws/src/tortoisebot/tortoisebot_bringup/maps/room2.yaml' file

5. And voila! You have saved the map!

6. Lastly, when you are done having fun, close everything!

Remember:

Every time you open a new terminal, enter the ROS2 world and workspace again by typing:

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash

That's it! Have fun exploring and mapping with the Tortoisebot!

6. Real Robot

Here's a guide to help you connect with your real robot and have some fun exploring its capabilities.

  • Connect to your robot

The first step is to obtain the IP address of your robot. Don't worry, it's not as complicated as it sounds. Check out the picture below for a step-by-step guide on how to obtain the IP address.

https://github.com/rigbetellabs/tortoisebot_docs/blob/master/imgs/tortoiseBot_setup/001.jpeg

Once you have the IP address, use the command below to connect with your real robot on your PC terminal:

  • Password: raspberry

Real Robot Sensors Data Visualization

1. Power up the world of ROS2 on your robot by entering the following in your robot terminal 1

galactic

2. Launch all the sensors and actuators on your robot using the following launch command

ros2 launch tortoisebot_bringup bringup.launch.py use_sim_time:=False

TTB IRL

And voila! Your tortoisebot is up and running! Now let's command the robot to move using our PC!

3. Open a new terminal on the PC and fire up the ROS2 using the following command:

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash

4. Now let's teleoperate the tortoisebot.

Enter the following command on the PC terminal:

ros2 run teleop_twist_keyboard teleop_twist_keyboard
or
ros2 run tortoisebot_control teleop_twist_keyboard

And now you can see your tortoisebot move as you wish!

You can also visualize what your robot sees using the following steps:

5. Open another terminal on the PC and source the ROS2 on it

6. To visualize the sensor data, enter the following:

ros2 launch tortoisebot_description rviz.launch.py 

Robot IRL VIZ

Running the Tortoisebot in Exploration Mode

1. Open Robot Terminal 1 using ssh and again fire up the ROS2

galactic

2. Launch the following command to run the tortoisebot in exploration mode!

ros2 launch tortoisebot_bringup autobringup.launch.py use_sim_time:=False exploration:=True

The tortoisebot has now started mapping the environment! You can visualize it and follow this:

3. Open a PC terminal and source the ROS2 and your workspace

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash

4. To visualize the data:

ros2 launch tortoisebot_description rviz.launch.py 

TTB View Sensor Data

Whoa! The Tortoisebot is now mapping the environment! You can now teleoperate it to map the environment, or something even cooler! Try providing a goal to your Tortoisebot using the 'Nav2 Goal' button on the Rviz screen to see your robot move autonomously!

Time to save your MAP!

5. Open a new terminal on your robot using ssh and source the ROS2:

galactic

6. Save the map of your room with this!

ros2 run nav2_map_server map_saver_cli -f /path_to_map/name_of_map_file.yaml

7. Close everything ( from the robot terminal and pc terminal)

8. Opening your map the next time you launch your robot

ros2 launch tortoisebot_bringup autobringup.launch.py use_sim_time:=False exploration:=False map:=/home/../map_file_name.yaml
  • Note: Make sure the tortoisebot is placed at approximately the same position as when it was while starting the mapping

9. Visualize the robot on your PC using your PC terminal:

source /opt/ros/galactic/setup.bash
source <your workspace directory>/install/local_setup.bash
ros2 launch tortoisebot_description rviz.launch.py 

*** If using multiple robots set separate Domain Id for each robot using the below command for separate control ***

export ROS_DOMAIN_ID=0

Cheers!! You are now a Tortoisebot Expert!

Clone this wiki locally