Figure 1 - The Ping-ponger robot which can shoot the balls
- Ozeki Ping-ponger: Ozeki Ping-ponger build instructions
- Ozeki 10 installed: Installed Ozeki 10 Robot OS
- Lego connection installed: Installed Lego bluetooth connection
- SNAP basics: Basic knowlege of the Snap programming language
- Some table tennis balls
Lecture video - How you can play pingpong with the robot
Get to know how to rotate the wheels synchronized!
This lecture is about how synchronization works. The first kind of synchronization is the mechanical synchronization. On the Ping-ponger there is 4 (2-2) wheels placed on 2 axles. The table tennis balls are enclosed by the 2-2 wheels. It is needed to start and rotate the two axles at the same time and with the same speed. For the next tasks, the 'two motors for two axles' conception is not ideal, because these motors are not enough precise in timings. The solution is that you can do mechanical synchronization with using gears. As you can see on Figure 2 below, there are many gears on the bottom of the Ping-ponger. There is only one motor which is connected with the gears and the gears are connected with another axles and gears. Thus when the motor rotates, the two axles will rotate simultaneously, so they can shoot the table tennis balls if they are rotating fast enough.
Figure 2 - The gears and axles
Create a program which make software synchronization based on 'dispense then shoot' logic!
The conception is to make a software synchronization based on the following logic: first the robot dispenses a table tennis ball and then throws it. So this task is based on doing things one after another with correct timing. The task is to dispense and throw a ball when the 'space' key on your keyboard is pressed. So let's start with a 'when space key pressed' block. Then you should start motor A using the 'Start motor A at 100%' block. The next block should be a 'Rotate B by 120° at 60%'. It will rotate an 1/3 circle on it. Because the sticks on the dispenser contraption close 120 degrees with each other, rotating 120 degrees will cause the same position. But with 60% motor speed, it has a short time to fall down while the motor is rotating. Then use 'Stop motor A' to stop motor A. So motor A will rotate while (and a bit more) motor B is rotating. These cause the ball to fall down and then it will be shot out. The complete program can bee seen on Figure 3.
Figure 3 - Dispensing then throwing
Create a new program which dispenses at random time!
In this task you need to rotate motor B at random time. To do this, start with a 'when green flag clicked' block. Then attach a 'wait [secs] secs' block to it. Put a 'pick random [from] to [until]' block found in Operators category into its 'secs' field. It will return a random number between the given values. Enter number 1 for its 'from' field and number 3 for 'until', so you will get a random number between 1 and 3 on every start. So this will rotate motor B after 1-3 seconds passed based on the random number. Insert a 'Rotate B by 120° at 60%' block after the 'wait' for rotating motor B. Look at Figure 4 for help.
Figure 4 - Dispensing a ball randomly
Upgrade the program to dispense using broadcast messages!
The essene of this program is to use broadcast message. Broadcasting is a form of communication when one sender sends a message to many receivers. In SNAP, you can make code which runs parallel using the broadcasting blocks. Put away the 'when green flag clicked' block and change it to 'when I receive [message]' block. It can sense a message from a broadcasting block and then execute the attached blocks. Insert a 'broadcast [message] and wait' block to the 'when green flag clicked' block you have put away (as you can see on Figure 5). Select 'new' option in the list in the 'broadcast' block and create a new message called 'rotate'. Select this name in the 'when I receive' block too.
Figure 5 - The broadcasting blocks
Upgrade the program to repeat the dispensing until the space key is pressed!
In the previous task you have made a program which rotates motor B after pressing the green flag button and then waits for the receiver blocks to be executed. To rotate the dispenser contraption more and not once randomly, you will need a loop. The goal is to repeat the random rotating until pressing the 'space' key. Put a 'repeat until [condition]' block after the 'when green flag clicked' block and place the 'broadcast' block into it. Then insert a 'key space pressed?' block as its condition and select the 'space' option as can be ssen on Figure 6.
Figure 6 - Dispensing more balls with a loop
Shoot the balls instantly when they are dispensed!
Now you have reached that the robot dispenses the table tennis balls at random times when you start the program. Now the only thing you have to do is throwing out the balls. You can reach this by continously rotating motor A which will rotate very fast and when a ball comes, it will be shot out. Insert a 'Start motor A at 100%' block after the 'when green flag clicked' block. So when you start the program, the wheels will be rotating continously. After the 'repeat' loop put a 'Stop motor A' block to stop the motor when you press the 'space' key on your keyboard (Figure 7).
Figure 7 - Throwing away the dispensed balls
Figure 8 - Program codes that can dispense and shoot table tennis balls
Download the programs
The programs are capable to dispense and shoot balls.
It is easier to do the steps if you have the program in front of you:
Download the SNAP program codes
- Drive your robot along a square
- Learn to use keyboard events
- Move your Lego robot from the keyboard
- Learn to use the gamepad
- Use a gamepad to control your Lego robot
- Use sensor input in robot control
- Learn to use states in robot control (Build the safe)
- Robot state control and feedback, using the IR remote controller
- Robot control based on visual input