Lab 2: Get Moving with C++

This lab serves as an introduction to rostopic, catkin_make, ROS nodes, and a simple polygon trace motion.


Download Lab Skeleton Zip File

Introduction

In the previous lab you were able to control your iRobot remotely with several keyboard keys. Now you will be progressing towards autonomous motion. In this lab you will be programming your iRobot to move in a polygon trace motion. We have provided starter code which will get your robot moving in a square.

Preliminaries

Using the instructions from the Getting Started lab, connect to the create base and launch the iRobot driver. The teleop keyboard will not be needed for this lab.

Introduction to topics and rostopic

The rostopic command-line tool displays information about ROS topics. Currently, it can display a list of active topics, the publishers and subscribers of a specific topic, the publishing rate of a topic, the bandwidth of a topic, and messages published to a topic. The display of messages is configurable to output in a plotting-friendly format.

This should change the velocity of the robot. This shows an alternative way to control the robot directly without using a node.

Publisher

ROS’s fundamental capability includes easy communication among distinct programs. One of the ways to communicate in ROS is using publisher. In this lab, we will be using publisher to communicate with the iRobots.

* If a program has an ongoing stream of data to share, it uses publisher to send out the data.

The publisher, like the word indicates, publishes messages to carry out certain tasks. In this lab, we require to publish the commands in order to control the iRobot. You will be manipulating the speeds of the robot and setting the correct values and publish the message, so that the iRobot can accept the message and move.

ROS nodes in C++

A node in ROS is an executable that uses ROS to communicate to other nodes. A node is nothing more than an executable file within ROS packages.

We have provided a sample ROS C++ node that publishes velocity commands in order to move in a square. This publishes the same topics from part B above. First download the zip file and extract into your catkin workspace. Run:

$ catkin_make 

Catkin make was introduced last lab. Before you can run your program, you need to run one more command. If you look in your current directory you should now have a ‘build’ and ‘devel’ folder. Inside the ‘devel’ folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment.

$ source devel/setup.bash

Now you are ready to run your program. In order to run your nodes through ROS follow the command:

$ rosrun lab2_pkg_name lab2_node_name

Note: The code written was written on just one iCreate. Each robot may be calibrated slightly differently, so if your robot does not make a perfect square, do not be alarmed, this will not affect your ability to complete the challenge. How have we done this? Possibly, we wrote a code that went straight and turned 90 degrees, and then copied and pasted it four times within a single function. Take a look at the goRobotGo function in iRobot.h, using this code, change the velocity code and timing to move the robot in different patterns (circle, triangle, hexagon).