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.
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" "email@example.com" \ -m "Franz Pucher" "firstname.lastname@example.org" \ -l "MIT" \ -d "Pong game for ROS turtlesim." \ --catkin-deps roscpp
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.