Class Meeting 02: First Turtlebot3 Programming


Today's Class Meeting



What You'll Need for Today's Class


For today's class, you'll need the following tools/applications ready and running:


Coding Exercise #1: Turtlebot3 Spinning in Circles


For this exercise you'll work individually in breakout rooms of ~3 students. You can find the breakout room assignments in this Google spreadsheet. Feel free to collaborate with one another, talk through your code, share your screen in order to help each other out.

Your goal in this exercise is to program your Turtlebot3 to perpetually spin in a circle. Let's first create a new ROS package called class_meeting_02_spin_circles:

$ cd ~/catkin_ws/src/intro_robo
$ catkin_create_pkg class_meeting_02_spin_circles rospy std_msgs geometry_msgs
$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash

Within the class_meeting_02_spin_circles package, create a scripts directory, and within the scripts directory create a new python file called spin_in_circles.py. This is the Python file we'll use to program our robot to spin in circles.

Before going any further, it's helpful to get familiarized with our friend, the Turtlebot3. You can see all of the components of the Turtlebot3 highlighted in the figure below.

Turtlebot3

In order to program the robot to spin in circles, you'll want to be controlling the two motors that are connected to the robot's two wheels. The relevant ROS topic you'll find useful is:

Note: Here are some commands you might find useful: For more info on these commands, and for more handy ROS commands, please check out the ROS Resources page of the course site. Additionally, please utilize Google or your favorite search engine to learn more about these ROS topics and message types (e.g., here's the documentation for the PointStamped message).

To run your code, in one terminal, run:

$ roscore

In a second terminal, run:

$ roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch

Finally, in a third terminal, run your ROS node:

$ rosrun class_meeting_02_spin_circles spin_in_circles.py
Note: Don't forget to run chmod u+x spin_in_circles.py!

Once you finish, your robot should behave somewhat similar to what is pictured below:

Turtlebot3 Spin Circles

If you and your breakout room finish this coding exercise, please move onto the next exercise.


Coding Exercise #2: Turtlebot3 Stopping in Front of a Wall


To get started on this exercise, make sure you have pulled the latest version of the class repository and rebuilt your packages:

$ cd ~/catkin_ws/src/intro_robo
$ git submodule update --init --recursive
$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash      

The package for this exercise is called class_meeting_02_stop_at_wall and you can find its content in ~/catkin_ws/src/intro_robo/class_meeting_02_stop_at_wall.

Next, launch Gazebo with the Turtlebot3 robot. In one terminal, run:

$ roscore

In a second terminal, run:

$ roslaunch class_meeting_02_stop_at_wall turtlebot3_and_wall.launch

In Gazebo, you should see a Turtlebot3 robot some distance apart from a brick wall.

Turtlebot3

Your objective in this exercise is to move the robot forward and stop it just before it would collide with the wall. This will require using the laser scan data from the robot's LiDAR (see robot diagram again, below) to make decisions about how to control the motors driving the two wheels of the robot.

Turtlebot3

The relevant ROS topics you'll find useful are:

Create a scripts directory within the class_meeting_02_stop_at_wall directory and write your python ROS node (e.g., stop_at_wall.py), putting it within the scripts directory. After ensuring that your script is executable (chmod u+x stop_at_wall.py), you can run it with the following command in a third terminal:

$ rosrun class_meeting_02_stop_at_wall stop_at_wall.py

Success looks like what you can see in the following image where the robot is stops just before it would collide with the brick wall:

Turtlebot3 in front of wall
Turtlebot3 moving to wall

If your group finishes both coding exercises #1 and #2, please spend the rest of class time working individually on the Warmup Project. Please don't leave, we will be brining everyone back to the main Zoom room at the end of class.