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.
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 https://github.com/fjp/ros-turtle-pong.git
Then build the workspace with
catkin_make and source the new package:
fjp@ubuntu:/home/fjp/catkin_ws$ catkin build
# or use
# 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
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
catkin_ws/src$ catkin create pkg turtle_pong \
-a "Franz Pucher" "firstname.lastname@example.org" \
-m "Franz Pucher" "email@example.com" \
-l "MIT" \
-d "Pong game for ROS turtlesim." \
The game is made up of three nodes:
balla turtle that acts as the ball and contains logic to bounce off walls.
keythe turtles representing the paddles which are controlled with the keyboard to move them up and down.
pongnode that spawns the three turtles and keeps track of the game state.
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.