Skip to content
Marc Hanheide edited this page Feb 6, 2023 · 22 revisions

Week 2: First steps with ROS Programming

Preparation

Make sure you have fully understood and completed the Week 1 task! All steps to get started with the virtual environment are described in Using the Docker Image, and the steps are also in the Panopto Workshop recording of last week. To start the simulation, see last week's tutorial at first-turtlebot-tutorial.

Mini Tasks of week 2:

Task 1: Make your robot move using the command line:

  1. Run ros2 topic list and consider what you see. Also, try ros2 topic echo /odom and move in simulation using the keyop from last week. What do you see?

  2. use ros2 topic pub to make the robot move! Try to develop the following command using the Tab key for auto-completion (do not directly copy this, as it will not work, make sure you read some of the documentation on ros2 topic commands or search this up yourself!):

    ros2 topic pub /cmd_vel geometry_msgs/Twist
    linear:
      x: 0.0
      y: 0.0
      z: 0.0
    angular:
      x: 0.0
      y: 0.0
      z: 0.5" -r 1 
    

    (You can stop this command by hitting [Ctrl]-C on your keyboard!)

  3. Watch your turtlebot move. Reflect what is happening. Try to make it go around in a circle (with about 0.5m radius) smoothly by modifying the above command.

Task 2: Python programming

  1. Read this tutorial on how to create a publisher in python. Remember that we want to publish a geometry_msgs/Twist to /cmd_vel like we did above!
  2. Time to code our first Python program using ROS: The goal is (again) to have the turtlebot first go around in a circle of about 0.5m radius, this time from the Python program!
    • In the simulation, you just run the simulation as before, and then your code in VS Code or from the command line.
  3. Now consider how you could implement a behaviour that takes the robot forward if there is more than 50cm space in front of it but make it turn to the left, if there isn’t enough space. This requires you to interpret the data from, e.g., the laser scanner and modify the Twist you publish depending on the data in the Laser scan.
  4. Optional: When you have accomplished this, the next challenge for you is to make it go in the shape of a square of 1m length each side.

Task 4 (optional): Upload your source code to github (or another online repository)

Read Git and GitHub

Background that may help you

What to send to the robot?*

A Twist message has two parts that are important:

  • Twist.linear: this has x,y,z components for which you can specify the speed in m/s. Please don't go beyond 0.6

  • Twist.angular: this also has x,y,z components and determines how quick the robot should rotate around one of the axes in radians/s. Please don't go beyond PI. To determine which axis you want to move along and turn around, please have a look at the picture below:

    Turtlebot axes

Red: x, green: y, blue: z

Clone this wiki locally