Have you ever noticed that kids stay in front of the screen longer and longer? Most of the kids contents, educational or entertaining, are delivered through screens these days. This creates a huge burden on kids' vision system, making them susceptible to nearsightedness and the computer vision syndrome. Kids today start wearing glasses at a more alarming early age.
In this project, I want to use one of the on-the-shelf robots (the MoonBot Kit in this case) to deliver educational contents to kids without forcing them to stare at a screen. I choose the quiz content as the main format because it involves back and forth interactions and is more engaging. Here is a video showing the end result.
The MoonBot kit is an educational robotics kit that can be used to build multiple robots. I use the one with a face to program the QuizBot, with obvious reasons. It's the friendlier robot among the three.
Let's see what programmable interaction elements are available with the humanoid MoonBot.
- Vision Sensor - Can detect people and read number cards
- LED Eyes - 12 RGB color LEDs can be programmed individually to display various expressions (more than the C-3PO)
- Two touch sensor ears - for touch based interactions
- Speaker - Plays any mp3 file for a wide variety of voices and questions
- Controller LED - Two RGB status LEDs
- Controller Buzzer - Perfect for card reading confirmation
- 1 head servo - Move head up and down to focus his attention on you.
- 2 arms servo - Move left and right arms up and down to generate gestures to accompany the voice
- Tank base - the left/right tread motor can let MoonBot move around and also dance
Here is the diagram from the MoonBot manual to show different sensors and actuators
My overall plan looks like this:
- Use MoonBot's mp3 speaker to deliver quiz questions to kids
- Use other lighting and movement parts to make the robot as friendly as possible
- Use MoonBot's vision based card recognition to read answers from kids
- Program other logic on MoonBot to shuffle the questions, process the answers and give kids a final score of the quiz
The MoonBot kit comes with a set of recognition cards that can be detected by the MU vision sensor. I will use the number card to represent the 4 choices in the quiz questions. To make it easy to hold, I added a LEGO beam on the back of each card.
We will need to generate quite a few mp3 files for different quiz questions. I did this by using the text to speech functions on the MacOS. Basically this handy functionality allows you to convert any text to sound files which can be used in many different projects.
One thing you need to think is which voice your robot should use. MacOS offers many different voices, male or female, US or British or foreign. After some test, I settled to the "Tom" voice, which sounds loud and clear enough.
The voice you get from MacOS are mostly grown-ups. To make the voice a little cuter I did some post-processing. I use Audacity to increase the voice's pitch and also convert it from m4v to mp3, which is the only format accepted by the MoonBot speaker module.
Here is a list of voices I generated. The MoonBot speaker module uses the first 4 letters of the sound file name to look up that sound. So I organize the text with a 4 letter identifier.
- QUES: Question
- STAR: Hi, I am a quiz robot. Touch my ear to start.
- ANSW: The correct answer is …
- GREA: Great job! You’ve finished this quiz.
- SOFU: This is so fun.
- NEWQ: To start a new quiz, touch both of my ears at the same time.
- SCOR: Your score is
- REST: Touch both of my ears to restart
- YS02:You are right.
- YS03:Good Job.
- Questions: QZ01 – QZ48
- Answers: QA01 – QA48
In addition to questions and answers, these sound resources also includes commonly used terms in running the quiz. The speaker module has a USB-C connector, which can be plug into a computer and a USB drive will show up to hold all the sound files. Note that the speaker module has a limit of 128 mp3 files so you will need to delete all the original sound files on it and copy this set to the module. Copy the sound files somewhere else so you can restore the original sound.
A nice thing about the MoonBot speaker module is that it can be updated independently. This means you can replace the whole questions and answers section without the need to change ANY code.
The software on the MoonBot has three tasks:
- Process different sensor inputs
- Coordinate all the motion and lighting effects
- Run the quiz logic
To better organize the program, I use a simple state transition diagram to show the flow of the quiz
This diagram also correspond to the main loop implementation of the program, which I did in mixly drag-n-drop code like this:
I use a global variable called "state" to keep track the current state of the quiz. In different state, different functions will be called to perform the actions in that state. Any transition from one state to the other according to the state diagram will involve the change of the "state" variable to that state and the return of the current function. After returning, the switch block in the main loop can direct the program to the new state.
Before move on to each state functions, I would like to briefly talk about some detailed design considerations.
- To make the quiz bot present different quiz questions each time, a randomization of questions is introduced. I prepared 48 different quiz questions and the bot will randomly pick 12.
- To prevent the random number generator produce sample number during the quiz, which will cause the robot to repeat the same question, a de-dupe process must be used to remove these dupes.
- My goals is to create the program once and re-use it to play different quiz without touching ANY of the code again. To do this I need to fix the answer to each question for any quiz questions in the future. To do this, I added some restriction to the format of the quiz, such as requiring the question always has 4 answers. For the 48 questions, the answer of the first 12 is "1", "2" for the second 12 questions, so on and so forth.
In the initialization code, I declared the "state" variable as well as some constant variable to be used to set each state. The sensors and actuators that are initialized are:
- Touch Sensors
- Vision Sensor
- LED Eyes
- Controller LEDs
- Three servos
The start function runs in a loop to prompt any user to start the quiz by touching it's left ear. It also runs the people tracking algorithm to allow it to always turn towards people.
The quiz function runs the whole quiz in a loop by playing 12 random questions, read the result from the user. Based on the result correct or not, it also gives feedback to the user.
Once the quiz is done it will transit state to STATE_RESULT.
The result function will show the score to the user and if the score is high enough (9 or more), the robot will do a short dance.
The result function will exit if it detects both ears are touched, and change the state back to the Start function.
I will also show some other functions that are important to the run the program. First is the TrackingPeople function, which tries to keep the people in the camera's center by adjusting head servo and motors.
The second is the ReadResult function, which use the vision sensor to read the card result presented by the user.
The third one is the GetRandomNoDupe function, which is responsible for randomly picking new quiz index that is not picked previously. Note that you have to remember all the previous question index to be able to do the "de-dupe".
Of course, there are more functions than what I show here, and I will give a snapshot of all the functions. The whole code area is even larger than my 29 inch ultra-wide screen :)
For details of each function, please check the mixly code in the attachment. Feel free to modify the code to customize the interaction.
If you just want to customize the questions, you don't need to change any code. Just flash my code in and update the question MP3s in the speaker module. If you want to change the number of questions, you just need to modify a few numbers in the RunQuiz and GetRandomNoDupe functions and that's it.