Assignment 1

Autonomous Robotic Systems / Assignment 1

The Objective of this assignment is for you to become familiar with the Robot Operating System(ROS) software, which you will be using in future assignments to program various algorithms for robots.

Before you can start this assignment you have to complete the following steps

  1. Make sure you installed ROS and configured your workspace according to the installation instructions.
  2. Follow all the beginner level tutorials from step 2 onward, to get yourself familiar with the ROS system.

In this assignment we will work with a simulated robot equipped with a laser range finder which scans it environment in a horizontal plane for obstacles. In addition to the standard ROS core packages you will use the 2D robot simulator called Stage. Stage simulates a population of mobile robots, sensors and objects in a two-dimensional bitmapped environment. Stage provides fairly simple, computationally cheap models of lots of devices rather than attempting to emulate any device with great fidelity.

We are going to create a random walk algorithm for a robot to drive through the Swarmlab without driving into obstacles.

The end effect of the assignment should be that the robot moves forward until it reaches an obstacle, than it rotates in place for a random amount of time and then moves forward again, etc.

We start with creating a simple ROS node called random_walk.

cd ~/catkin_ws/src
catkin_create_pkg random_walk roscpp geometry_msgs sensor_msgs
cd random_walk

Create a directory called /world and unpack These files in there. The files are the actual map which is used in stage, visualization of the robot and the physical robot and world description.

In a new terminal start the ROS core


Start Stage in the previous terminal (make sure you are located in /random_walk folder)

rosrun stage_ros stageros world/

In the view menu of Stage you can enable the ‘Data’ option to see the sensor data of the robot. You can move your robot by clicking in stage and dragging it to another position.

Now, to be able to use some of the robot functionality go ahead and download teleoperation package for a simulated Turtlebot. Note that compilation of the teleoperation package requires joy package to be installed, this can be done through a standard package manager. In case you have any problems with the downloaded package, check the official “Turtlebot” project on Git and download the package from there. Unzip it in the ~/catkin/src folder. Finally build the source code by typing:

cd ~/catkin_ws

With the package in place start teleoperation in a new terminal.

rosrun turtlebot_teleop turtlebot_teleop_key ~cmd_vel:=/cmd_vel

In case you receive a “not executable” message from the rosrun, make sure to add executable mode to the suggested file.

If you select the teleoperation terminal, you can use your keyboard to give your robot commands to drive it around.

To control the robot with our newly created node we prepared some example code. Download the example-code file and copy it to the /src directory of your random_walk package.

You need to add your source code to the make list of the compiler. To do so open your CMakeLists.txt file and make sure that under “Declare a c++ executable” you have a link to your source code:

add_executable(random_walk src/random_walk.cpp)

and that you link against catkin libraries:


Build the code as mentioned above with catkin_make and run the code in another terminal

rosrun random_walk random_walk

You should start seeing range values being printed in the terminal, along with some timestamps. If you now move the robot with the keyboard or mouse, you will notice that the range value’s change according to the presence of obstacles.

Your task is now to take the example code and adapt it in the given places to implement a simple random walk algorithm as described above. You are free to extend the random walk algorithm to a more sophisticated one if you like.

Automated Startup method

You can also automate the startup of the needed nodes by using a launch file, when using a launch file you don’t need to start the roscore, this will be automatically done, furthermore the nodes that you specified will be started. To make a launch file, you create a file named random_walk.launch in your random_walk package and paste the next code in it.

  <node name="stageros" pkg="stage_ros" type="stageros" args="$(find random_walk)/world/" respawn="false" output="screen" />
  <node name="random_walk" pkg="random_walk" type="random_walk" output="screen" />

Start your program now with

roslaunch random_walk random_walk.launch