Turn your robot starter kit into a jousting bot!

This project builds upon the line-following robot from the RadioShack Make: it Robotics Starter Kit to create a jousting robot. Build one to learn how to modify a kit with just a bit of additional hardware and software, then build a second robot with a friend and organize a tournament!

With two robots, they will charge at each other down a defined track, adding a deadly edge to their line-following capabilities. A momentary button switch will act as the jousting lance’s tip, while a lever switch will act as the target (the knight’s “shield”). Depending on which robot wins and which robot loses, audible victory & defeat tunes will be played.

Along the way there’s a lot to learn about building and programming a robot.

Watch the video below to see the Joust-A-Bot in action and then let’s get started building your own jousting robot!


 

Circuit

Schematic

When you get to the step for building the circuit, you can refer to the diagrams below.

Here's the circuit schematic for the Joust-a-Bot.

Here’s the circuit schematic for the Joust-A-Bot.

Breadboard layout for the Joust-a-Bot

This is the breadboard layout for the Joust-A-Bot.

Breadboard

To help you check your progress along the way, the project steps refer back to these pictures of the breadboard build.

Breadboard with resistors and wiring for the speaker, lance button and bump switch.

Breadboard with resistors and wiring for the speaker, lance button and bump switch.

Breadboard with wiring from the robot's controller board.

Breadboard with wiring from the robot’s controller board.

Programming

Understanding the Line-Following Sketch

Line-following robots like this one generally use infrared (IR) sensors to guide them. If the optical sensor is over a white reflective surface, the IR light from the sensor is reflected and received. If the sensor is over a black surface, the IR light is absorbed and the sensor does not detect it. By guiding the robot based on readings from the sensors, a line-following robot straddles a black line on a white background. The two optical sensors keep the robot over the line.

The line-following sketch that comes with the starter kit works well, and the code is reasonably commented. However, many beginner programmers or even experienced Arduino programmers may find the code a little obscure.

For one thing the robot’s controller board has its own microprocessor, and the Arduino Uno compatible board you connect communicates with the controller’s processor using digital pins you would normally have access to under Arduino. Avoid using digital pins 0-3.

The code calls custom functions from the MakeItRobotics library, which may seem confusing. Also the bit-wise math calculations may not be familiar to many beginner and even intermediate programmers. But fear not, for all of the steps below are documented and as long as you are patient with your build, you’ll have a jousting robot in no time!

Ack! Hexidecimal numbers and bit-wise math! Ack!

Ack! Hexidecimal numbers and bit-wise math! Ack!

The good news is you don’t really have to mess with any of that for this project. I mention it here because if you want to go on to do bigger and better things with this robot kit (which you should totally want to do) you’ll want to get a better understanding of the code and how it works with the controller hardware.

Understanding the Jousting Sketch

I adapted the line-following sketch to build the Joust-A-Bot robot. I made one little change to the original code for the purpose of jousting, and incorporated some popular example code to manage input from the lance button and output to the speaker.

Incorporated Debounce and toneMelody examples, and borrowed some fun tunes.

Incorporated Debounce and toneMelody examples, and borrowed some fun tunes.

You have to set up some constants and variables for use with the Joust-A-Bot. I also turned a hard-coded value for the robot’s speed into a variable (the playspeed variable). This allowed me to implement different speeds depending on whether the robot is jousting, celebrating victory, or agonizing in defeat.

Set up constants and variables for the Joust-A-Bot.

Set up constants and variables for the Joust-A-Bot.

In the set-up section of the sketch, I added code to define the lance and shield pins as input.

Define the lance and shield pins as inputs.

Define the lance and shield pins as inputs.

There’s a problem with using buttons as input into an Arduino or other microprocessor. When the button transitions its state it has a mechanical “bounce” period, during which a microcontroller may see input from the button fluctuate rapidly between high and low.

Luckily, there’s a handy example sketch in the Arduino IDE to debounce the input. We use the debounce code here to remove bounce errors from the lance button and lever switch.

If a hit is detected by the lance button, the code calls the win() function to declare victory!

Debounce the lance button.

Debounce the lance button.

I originally wanted to make a little knight’s shield for the robot. Instead the cardboard tube knight actuates the switch. So in the code below, the bump switch is referred to as the “shield”.

If a hit is detected by the shield bump switch, you have lost and the code calls the lose() function.

Debouce the bump switch.

Debouce the bump switch.

For Joust-A-Bot, we want to create a white track between two black lines for the robot to travel down. We have to change the behavior of the robot, turning right where the line-following robot would typically turn left, and vice-versa.

Reverse the normal direction of turns so the robot will drive within the jousting lane.

Reverse the normal direction of turns so the robot will drive within the jousting lane.

As discussed above, if the lance button detects a hit, you call it a win. The robot will play a victory tune and dance a merry jig.

Note the last line in the code snippet below stops the robot from moving. To joust again you press the reset button on the robot’s controller board.

You win!

You win!

Here’s the code for the victory music:

Play the victory tune from Final Fantasy.

Play the victory tune from Final Fantasy.

If the shield bump switch is triggered, you have lost. Rest in peace. Better luck next time.

Ouch! You lost.

Ouch! You lost.

Here’s the code for the defeat tune:

"What matter wounds? For each time he falls, he shall rise again, and woe to the wicked. "Don Quixote

“What matter wounds? For each time he falls, he shall rise again, and woe to the wicked.”Don Quixote

Jousting

Set up the Jousting Lane

The field is prepared for combat!

The field is prepared for combat!

All you need for a jousting lane is two black lines on a white background. I used black electrical tape on white foam board from a craft store to make my jousting field. I cut the foam board in half length-wise and taped the ends together to give me one long lane. I’m able to fold the jousting field in half to be more portable.

A double length of foam board gives our knights plenty of room to work with.

A double length of foam board gives our knights plenty of room to work with.

The black lines should be parallel and just far enough apart to let the robots sit between them with a little room to spare on either side of the optical sensors. The wider apart your lines, the more wobble the robots will have in their path.

Let the Games Begin!

Set one robot jouster up on each end of your jousting track. Switch them on and let them charge at each other. Each time a lance or bump switch is triggered, you will have to reset that robot with the reset button on the controller board.

Will you feel the thrill of victory or the agony of defeat? Perhaps you’ll just learn something about robotics and have fun doing it!

Will you feel the thrill of victory or the agony of defeat? Perhaps you’ll just learn something about robotics and have fun doing it!

I’ll be honest, these robots are not expert jousters. They miss each other quite often. Or they crash and get hung up without either registering a hit (win) or triggering the bump switch (lose). Still, it’s pretty fun to watch them try!

Making expert jousters is not really the point. What did you learn from this project? How would you improve it? What other projects based on the Robotics Starter Kit can you come up with? It’s up to you to adapt the basic design from here.

Robotics is fun as a hobby, and a constant challenge to your abilities. If you try this project and come up with some improvements, please share your experience in the comments. I can’t wait to see what you come up with!