5. Gameplay

Share for us

After dressing the Rollbot with pretty covers, let’s start the most exciting journey: games!

With the basic operation of the Arduino IDE and the circuit theory of the car previously, you should already have a general understanding of the robot car. Next, let’s move on to the specific applications and the corresponding actions of the robot. Note that when we download the APP for the robot, we need to turn off the power of the Bluetooth module if it has been powered. Otherwise we are not able to download the APP.

In subsequent operations, you need to know some basic buttons on the main board:

Power switch: Switch on and off the robot; after switching on, the OLED screen and LEDs on the board will light up. When it’s off, the whole robot will be shut down.

Start button: To start the program, especially in the line following function.

Reset button (S1): To reset the master board.

Bluetooth switch: Switch on and the Bluetooth will be enabled on the board.

Bluetooth status LED (D7): When the Bluetooth is open and enabled, it’ll start to blink; after it’s connected to another Bluetooth device like an Android mobile, the LED will keep constant lighting.  

Bluetooth reset button (S2): To reset the Bluetooth.

Open the Rollbot folder downloaded and unzipped previously in Chapter 3 Software Operation. You can see the following folders inside:

Inside Arduino Code, there are three folders for the specific robot in a certain color and type. 

We just take the red one as an example in the following part. You can program your Rollbot correspondingly in the same way.

5.1 Singing

The Rollbot can sing with the buzzer onside via programming. Please see 7.1 Singing with buzzer for detailed explanation of the code. After reading the explanations, you can modify the music as you like.

1)     Find RollbotMusic.ino under Rollbot\Arduino Code\Rollbot\Red Rollbot\RollbotMusic, double click to open it. You can also open the file by clicking File -> Open in Arduino.

2)     Click Tools -> Board, select Arduino/Genuino Uno

and then, click Tools -> Port , select COM7(depending on your actual situation).

3)   Click the Compile button to compile the code, click Upload to upload the code to the board (or directly, skip Compile).

4)   Wait for a moment until the following information appears at the bottom of the window, which indicates it is uploaded successfully.

5)   Remove the USB cable, switch on the power. The buzzer of the car will sing. Certainly, you can play the music by programming, and the specific music theory and the related code will be explained in the Chapter 7.1.

5.2 Display the Sensor Signal Intensity on OLED

This experiment is to display the collected sensor data on the OLED screen. Here it is just applied for simple display. Later in the line following experiment, we will use the intensity to control the direction of the car.

1)  Find RollbotOLED.ino under Rollbot\Arduino Code\Rollbot\Red Rollbot\RollbotOLED, open it and upload to the Rollbot.

2)  Remove the USB cable, switch on the power. Put the test card under the sensor module of the robot. Press the start button for more than 2 seconds to enter the debugging mode. You will see that on the OLED screen, there are five bars simulating the signal intensity of the 5 detectors. Now put the first and second detectors from the left over the black stripe. So the 1 and 2 bars show the strongest signal, as shown in the figure below:

5.3 Motor Testing 

This experiment is to test whether the motor wiring is right or not. There can be 4 situations: the wiring of both motors is normal; both motors are wired inversely; the left one is normal but the right one is wired inversely; and the right one is good while the left one is wired inversely. We will introduce how to distinguish the cases then.

First, find MotorTest.ino under Rollbot\Arduino Code\MotorTest and upload to the Rollbot and observe the car.

NOTE: Please remember Speed_Dir since it will be useful in the programs related to the motors later.

1)  If the robot goes forward, it indicates all motors are wired normally. There is no need to modify the value of the variable Speed_Dirin the program since it’s by default.

2)  If the robot goes backward, it means that both motors are wired inversely. You need to change the variable value 0 of Speed_Dirinto 1 to run the program normally. 

3)  If the robot rotates clockwise (always towards its right side), it indicates the left motor is wired normally while the right one is done reversely. You need to change the value 0 of Speed_Dir into 2

4)    If the robot spins anti-clockwise (always towards its left side), it indicates the right motor is wired normally while the left one is reverse. Change the value 0 of Speed_Dir to 3

5.4 Line Following

This experiment is to let the robot goes forward along the black line. OLED displays the signal strength that 1, 5 sensor received. When the robot turns left, the yellow LED on the left lights. The yellow LED on the right lights when the robot turns right. No LED lights when the robot goes straight.

5.4.1 Magic Forest

1)    Open RollbotFollower1.ino under Rollbot\Arduino Code\Rollbot\Red Rollbot\ RollbotFollower1

Note: You need to modify the value of Speed_Dir according to the test in 5.3. It’s 0 by default. Then upload the RollbotFollower1.ino to the Rollbot.

2)    Take out the map and put it on a smooth surface like a table. Turn on the robot and place it with the middle detector over the black line on the map. Press the start button for more than 2 seconds. The robot will test the reference value of the black line automatically. Just wait patiently till it backs to the initial position after swaying a bit. This process is to test the sampling value of the black line. Then the robot will move along the line.

3)    You will see the robot goes following the black line on the map. When the robot swings to the left relatively from the black line, the robot will turn towards the right to correct its direction and the LED on the left will keep blinking until it’s back on track; when the middle detector is right over the middle of the black line, the robot goes forward straightly; when it deviates to the right, it will turn left to correct and the LED on the right will blink. See the figure below.

4)  If you have mastered the line-following program, you can try modifying the PD parameters to learn more the principle of line-following. You can do this through the Android APP Rollman (find the Rollman.apk under Rollbot\APK and install it on the mobile). After test, the debugging process is as follows: Set the PD to 0 and increase P slowly. When the robot starts wiggling side to side, increase the D value slowly to make the motion of the robot flat. So the PD adjustment is done successfully.

5.4.2 DIY Map

On a blank paper, you can draw a map you like according to instructions on the guide card. Three patterns are provided and you can also design by yourself. Then use the black tape to paste the map you designed on a flat floor or draw with the black Marker pen.

1)    Open RollbotFollower2.ino under Rollbot\Arduino Code\Rollbot\Red Rollbot\ RollbotFollower2.

Note: You need to modify the value Speed_Dir according to the test in 5.3. It’s 0 by default. Then upload the RollbotFollower2.ino to the Rollbot.

2)    Put the completed map on a smooth surface like a table. Turn on the robot and place it with the middle detector over the black line on the map. Press the start button for more than 2 seconds. The robot will test the reference value of the black line automatically. Just wait patiently till it backs to the initial position after swaying a bit. This process is to test the sampling value of the black line. Then the robot will move along the line.

You can try more possibilities such as using a white chalk to draw maps on a dark smooth surface like the floor, set a gift at the end, and then wait for the Rollbot to discover the mysteries. The program for using chalk to draw the map is not provided in our data package. You can try to change the SignalValue into Sensor.Read_WhiteFlag() to explore.

5.5 Bluetooth App Controls the Robot

This experiment aims to use an Android APP to control the Rollbot. You can also play the dice game (similar to Ludo and Monoply) with the APP (the map is NOT provided in the kit and you have to purchase it).

Bluetooth connection

1)    Turn off the blue tooth switch, open RollbotAPP.ino under Rollbot\Arduino Code\Rollbot\ Red Rollbot\RollbotAPP.

Note: You need to modify the value Speed_Dir according to the test in 5.3. It’s 0 by default. Then upload the RollbotFollower2.ino to the Rollbot.

2)    Turn on the power switch of the robot and the Bluetooth switch. When you turn on the latter, the Bluetooth Status LED will blink.

3)    Install the Rollman app on a mobile phone (for Android only). Find the package rollman.apk in APK in the Rollbot folder.

4)    After installing, you will see the icon , tap to open it. And it will redirect to the Bluetooth interface of the mobile, as shown below:

5)    Now open the Bluetooth of the mobile, hit Scan for devices to find Rollbot XXXXXX to pair. Note: If the pairing fails, you cannot use the APP. Try again then.

6)    After the pairing is done, back to the Rollman page. Hit Select Device and Rollbot XXXXXX, then tap Connect.

7)    If the robot has been connected to the mobile by Bluetooth successfully, the icon Connect in will become Connected. The Bluetooth Status LED in the Rollbot will keep lighting constantly instead of blinking.

Home page – simple control of the robot

Press the start button on the robot, let it in the start state, and then tap the 4 buttons on the page to control the direction of the robot.

5.6 Dice Game

1)    Please refer to the previous part section 6.5 to install the app Rollman

2)    Turn off the Bluetooth switch, open RollbotGame.ino under Rollbot\Arduino Code\Rollbot\ Red Rollbot\RollbotGame. You need to modify the value Speed_Dir according to the test in 5.3. It’s 0 by default. Then upload the RollbotGame.ino to the Rollbot. Turn on the power switch and the Bluetooth switch of the robot. You can see the status LED blink.

3)    Connect the Rollbot with your phone (refer to 6.5 for the pairing). Tap Dice in the lower right corner and enter the game. Press thestart button in the robot for about 2 seconds to set it in the start state. Hit Dice on the phone, and the figure will roll among 1-6 and stop randomly. 

The robot will go for the corresponding steps after receiving the data from the APP via the Bluetooth module on the robot. The steps are counted by the points on the map. You can change the rules of the game by pasting the provided round cards (+2, -3, Restart, and Pause; or even self-making other ones) onto circles beside the points on the map and modify the related code.

This game is suitable for two people. Go play with your friends!

The specific rules are like below (for the map above, so as the default program):

1)    12 points (steps) in total.

2)    Paste the +2 card as a bonus at the second point, so the robot goes forward for another 2 steps without rolling the dice. Set the value of Forward as in the program.

3)    Paste the restart  card to the fifth point, and the robot will return back to the start and turn around again to get ready for the next start. The value of Restart is 5.

4)    Paste the step -3 card to the ninth point, the robot goes backward for 3 steps and turns around. The value of Getback is 9.

Tips:

1)  The rules above apply only to the code we provide. But you can change them and adapt the card position on the map. Remember to modify the parameters for each card in the program and set the cards at the corresponding point on the map.

2)  The robot should stop exactly at the twelfth point to end the game, otherwise it will go backward based on the number you roll in the app.

3)  You’d better not paste the card for turning around (like the resume and -3) at a turning on the map for good performance.

The parameters like Forward, Restartand Getback are for the corresponding +2, restart, and -3 movements in the program. You can change their values for your own rules.

We also offer the program of maze but here no more explanation would be given about it. You can draw a maze map according to the cue card.