Sparkfun Magician Robot Santa Claus Seeker

Make your Sparkfun Magician Robot go north in search of Santa!

An mbed, some IR sensors, a compass, a Sparkfun Magician robot: separate they may be boring, but together they make an unstoppable Santa Claus seeking machine! Or at least a North Pole search machine. Five Sharp 2Y0A21 IR sensors border the front of the robot and provide collision detection to stop the Seeker from hitting anything. A compass rises out majestically from the front to avoid magnetic interference from the motors and lead the Seeker to its objective. The two Magician motors are linked to the mbed through a TB6612FNG dual hbridge provide the muscle moving it forward to Santa's house. And at the head of the army stands the programmed mbed, leading the pieces forward and around. And now you can do it yourself!

Motor and H-bridge

The Sparkfun Motors are best powered through a connection to an H-bridge to allow forward and reverse motion. As there are two motors, either two H-bridges are needed or a dual H-bridge can be used to control both. A TB6612FNG dual H-bridge from Polulu was used for this project, as it had the smallest form factor which allowed plenty of room for other peripherals. The connection scheme is shown in the table below

mbedDual H-Bridge Breakout BoardRobot DC MotorsBattery
VinVmot+
GndGnd-
VoutVcc
p21PWMB
p22BIN2
p23BIN1
p24AIN1
p25AIN2
p26PWMA
Vout/Stby
A01left-red
A02left-blk
B02right-blk
B01right-red

In the above connections, it should be noted that the motors are separately connected to the power source. They sink significant current which the mbed cannot provide through its power outs. Four AA batteries are needed to power both the motor and the mbed. It was found that this setup drained the batteries quickly, so a wall outlet adapter (to 5V DC) was also used to power just the motors, while the batteries powered the mbed. The final embodiment had eight batteries: four powered the motors and four powered the mbed and sensors. The PWM pins have to be connected to one of pins 21-26, as those are PWM enabled pins on the mbed. BIN1-2 and AIN1-2 do not, and can be connected to any of the digital pins, if you want to add other PWM sensors. The motor.h library was then used to control the H-bridge and thus the motors through these pins, as will be seen in the overall program.

Import library

Public Member Functions

Motor (PinName pwm, PinName fwd, PinName rev)
Create a motor control interface.
void speed (float speed)
Set the speed of the motor.

IR Sensors

Five Sharp 2Y0A21 IR sensors were used to allow the robot to detect its environment. Of the entire setup, these were probably the most finnicky part, as they are not always consistent in their measurements both within one run and from run to run. However, they were good enough to allow the robot to avoid hitting obstacles and go around them. Each IR sensor has three output wires, and they are connected as shown in the table below.

mbedIR
+3.3V busred
GND busblack
p15-p20yellow

There are six AnalogIn pins, so the five sensors mostly saturated the mbed analog capacity. Reading from the sensors was done using mbed's included AnalogIn interface.

#include "mbed.h"

AnalogIn IRsensor(p20)

int main()
{
    float sensorRead;
    while (1)
    {
        sensorRead = 21/IRSensor;
        wait(0.2);
    }
}

The above loop reads the values of the IRSensors five times a second, and calibrates them. The analog values the mbed reads in are inversely related to the distance values, and there's an additional multiplicative factor that has to be taken into account. The value of 21 was gotten both experimentally and from the Sharp 2Y0A21's datasheet. As can be seen in the code, values for all five sensors were read in and together these determined whether the robot would turn or go straight.

Compass

For the robot to persistently seek out Santa Claus, it needed a way to know whether it was going due North or if it had to turn in said direction. This is where the HMC6352 Digital Compass comes into play. The linked page has a detailed description of how to connect the I2C compass to an mbed, but we'll still go through a brief explanation. The pin connections are in the table below.

mbedHMC6352
+3.3V busVcc
GND busGnd
p27SCL
p28SDL

Pins p10 and p9 can be substituded for p27 and p28 on the mbed, but one of these two configurations has to be used because they are the only pins that support I2C communication on the mbed. Communication with the compass was achieved with the HMC6352 library.

Import library

Public Member Functions

HMC6352 (PinName sda, PinName scl)
Constructor.
int sample (void)
Sample the device and return the result.
void setSleepMode (int enterOrExit)
Enter into or exit from sleep mode.
void setReset (void)
Update bridge offsets.
void setCalibrationMode (int enterOrExit)
Enter into or exit from calibration mode.
void saveOpMode (void)
Save the current operation mode byte to EEPROM.
int getSlaveAddress (void)
Read the memory location on the device which contains the slave address.
int getOffset (int axis)
Read the current offset for X or Y axis magnetometer.
void setOffset (int axis, int offset)
Set the offset for X or Y axis magnetometer.
int getTimeDelay (void)
Get the current time delay.
void setTimeDelay (int delay)
Set the time delay of the device.
int getSumNumber (void)
Get the number of measurements being summed each sample.
void setSumNumber (int sum)
Set the number of measurements being summed each sample.
int getSoftwareVersion (void)
Get the software version on the device.
int getOpMode (void)
Get the current operation mode.
void setOpMode (int mode, int periodicSetReset, int measurementRate=0)
Set the operation mode.
int getOutputMode (void)
Get the current output mode of the device.
void setOutputMode (int mode)
Set the output mode of the device.

The last important thing to note is that the compass is affected by magnetic fields in its surroundings, including the motors. In order to prevent the motors from detrimentally affecting the readings, the compass was placed no a mast about 15 cm above the robot itself and at the very front. This seemed to work well enough to prevent motor interference, though interference from electronics in the vicinity would, on occasion, cause the robot to go the wrong direction.

Algorithm

The base of the algorithm for the robot motion is the idea that it should always be going forward and north unless there is an obstacle in the way. Obstacles avoidance is approached by having the robot turn right whenever possible (assuming there was nothing to the right) or otherwise turn left, and have it move forward the moment it has turned enough and nothing is in front of it. To make sure it has turned enough, the IR sensors pointing diagonally ensure there is nothing too close to them (the diagonal right sensor if it's turning left, the diagonal left sensor if it's turning right). Once it gets to moving forward, the robot looks to the north to see if it's good to go in that direction. When the coast is clear, it gets to turning in that direction (checking that it's not hitting any obstacles in the process) and starts moving forward again when it's pointing north. The robot only looks to the north once every 3.5 seconds, to ensure that there is plenty of time to clear the coast. This is done despite sensor input because the IR sensor values often jump around in value; 3.5 seconds was found to be an appropriate amount of time. The full code can be found below:

Import programSantaSeeker

IT GOES NORTH MOST OF THE TIME

Demonstration

Here's a video showing just how good the Santa Claus Seeker is at Seeking the Claus!

Future Improvements

This robot is just about the best Santa Seeker out there, but there are honestly some things that could improve its performance even more. The IR sensors work to give distance measurements, but they are often finnicky and the data points jump around a lot. Adding sonar sensors would likely improve the speed and accuracy of obstacle avoidance.


Please log in to post comments.