This video shows the first version of the Pong arcade video game for the Robot Operating System (ROS 1 Noetic) using turtlesim. The post will explain how the turtle_pong package for ROS’ turtlesim was created.

This project is part of the Robocademy Robot Operating System Learning Path by Lentin Joseph.

The source code is hosted on GitHub.


To use the turtle_pong package clone this repository into the src folder of your catkin workspace:

fjp@ubuntu:/home/fjp/catkin_ws/src$ git clone

Then build the workspace with catking-tools or catkin_make and source the new package:

# catkin-tools:
fjp@ubuntu:/home/fjp/catkin_ws$ catkin build
# or use
fjp@ubuntu:/home/fjp/catkin_ws$ catkin_make
# source your workspace using the setup.bash or setup.zsh depening on your shell
fjp@ubuntu:/home/fjp/catkin_ws$ source devel/setup.bash
fjp@ubuntu:/home/fjp/catkin_ws$ source devel/setup.zsh

Finally start roscore, run turtlesim and pong.launch:

rosrun turtlesim turtlesim_node
roslaunch turtle_pong pong.launch

Note that each of the three commands above should be executed from another terminal so that it will run in its own process.

The game can be played with the w/s keys and the up/down arrow keys to control the left and right player (turtle) respectively.

The next sections explain how the package was created and how its working.

Create Empty ROS Package

The first step is to create an empty ROS package and specify the required dependencies. Note, that it is possible to add missing dependencies later on. Inside a ros workspace use the catkin create command from catkin-tools to creat the empty turtle_pong package:

catkin_ws/src$ catkin create pkg turtle_pong \
    -a "Franz Pucher" "" \
    -m "Franz Pucher" "" \
    -l "MIT" \
    -d "Pong game for ROS turtlesim." \
    --catkin-deps roscpp

Class Architecture

The game is made up of three nodes:

  • ball a turtle that acts as the ball and contains logic to bounce off walls.
  • key the turtles representing the paddles which are controlled with the keyboard to move them up and down.
  • pong node that spawns the three turtles and keeps track of the game state.
ROS Computation Graph.

The ball class subscribes to three poses, the ball itself and the two players.

Note: To use class methods as callbacks see the wiki page Tutorials/UsingClassMethodsAsCallbacks.

ROS Computation Graph.