For today's class, you'll need the following tools/applications ready and running:
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.
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:
linear.x
direction sets forward velocity and angular.z
sets angular velocity.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
Once you finish, your robot should behave somewhat similar to what is pictured below:
If you and your breakout room finish this coding exercise, please move onto the next exercise.
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.
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.
The relevant ROS topics you'll find useful are:
linear.x
direction sets forward velocity and angular.z
sets angular velocity.ranges
, a list of 360 numbers where each number corresponds to the distance to the closest obstacle from the LiDAR at various angles. Each measurement is 1 degree apart. The first entry in the ranges
list corresponds with what's directly in front of the robot.
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:
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.