ThermaBot, the Heat Seeking Robot
The idea behind ThermaBot was to build a robot that could sense a persons heat source and then use this to follow them around a room without bumping into them by using a few of our modules. The modules we used were a TPA81, 2 SRF08's an RD02 and an LCD03 all controlled using a PIC18F4410.
The TPA81 is mounted on the front of the robot so that the 8 pixel reading runs horizontally across the front of its path of travel, mounting the TPA81 like this we were able to detect when a heat source was present and also where the heat source is positioned in front of it. Using this data we are able to use the RD02 to steer towards the heat source as it moves. The SRF08's are also mounted on the front and are used to detect the distance to the object that it is following, when the this distance falls below a set limit the robot stops driving forward and instead rotates on the spot to face the heat source as it moves until the object moves away again. The LCD03 is used to display readings from the TPA81 and SRF08's. All communication with these modules is done on the i2c bus, you can find more information about the I2C bus in our I2C tutorial. Here is how these modules are connected:
ThermaBot is controlled by a PIC18f4410 using a C program written for Microchip's PICC18 Compiler. Here I will detail some of the functions used to control ThermaBots behavior.
This function is run only once at the start of the program, it calculates the threshold values for each pixel of the TPA81 by taking an average of 16 readings while rotating and adding 2 to them. Anything above this threshold value is considered to be a heat source. After this function has finished the program falls into a continuous loop that controls ThermaBots behavior
This function is used to start an SRF08 taking a ranging, putting a value of 0x00 into this function causes all SRF08 modules on the bus to start a ranging at the same time.
This is used to set an internal timer on the PIC18 running. The value passes to this function is used to set the high and low bytes of the timer giving us the option of creating longer or shorter timer counts. The timers roll over flag is then set to 0, when a set time has elapsed this will then be set to 1 automatically. This timer is set for 70ms which is how long it takes for an SRF08 to perform a ranging, while this timer is running we can perform other processes and wait for this time to elapse if it hasn't already.
This gets the temperature readings from each of the TPA81's pixels and stores them in a data array.
Is there heat
Scans through the array containing the temperature readings, If there is a temperature detected above the threshold but below the upper threshold then a heat source has been detected and the function returns 1. If no heat source was detected then 0 is returned.
This finds the peak value of the array holding the temperature readings and then returns its position, this is the peak of the heat source detected and will be the pixel that will be steered towards.
Is there object
Checks the range data from the SRF08's against a threshold distance of 30cm, if one of the ranges is below this value then 1 is returned otherwise a 0 is returned.
Drive to heat
This function is used to drive towards a heat source at a distance and turn towards it as it moves. The value of peakHeat() is used to determine if ThermaBot should steer left, steer right or drive straight forward. The further left or right from the center the heat source is will also make it turn faster or slower to keep up with the movement.
Turn with heat
As drive to heat except instead of driving towards a heat source is stays stationary and rotates on the spot to face it.
Wait for timer
Waits for the timers roll over flag to be set to 1 if it has not already, this gives the range finders enough time to complete a ranging.
Get SRF data
This function gets the range data from the SRF08's.
Flow of the program
At start up the program will pause for a moment to let everything power up and then it will call getThreshold() to calculate the threshold temperature of each pixel, after this it falls into a continuous loop that controls ThermaBots behavior. First the SRF08's are commanded to start a ranging session and an internal timer is set for 70ms and started. 70ms is how long the SRF08 takes to perform a ranging and while this timer is running we can process other functions before reading data back from the rangers, this is to speed up the flow of the program. Next we get the temperature readings and check it to see if a heat source has been found and where the peak on this heat source is in the TPA81's data. If a heat source has been found then the function isThereHeat() will return 1. The results from the last ranging session are then processed and if an object is detected then the function isThereObject() will return 1. Next the program uses the output from isThereHeat() and isthereObject to decide what action to take. If there is a heat source detected but no object is detected then driveToHeat() is performed and ThermaBot will start to drive towards a heat source. If a heat source is detected and an object is detected close up then the function turnWithHeat() is called and ThermaBot will rotate to face the object. If no heat source is detected then the motors are stopped whether there is a object up close or not. After these functions have been processed we wait for the timer to finish, this insures that we do not try to read range data back from the SRF08 before a ranging has completed and get inaccurate results. Once the timer has expired we grab the range data from the SRF08's and can go back and repeat the process.
ThermaBot will quite happily follow us round the room but as the TPA81 has a FOV of 41° it is possible to move too fast and your heat source to be lost, in this instance ThermaBot will stop and wait for you to come back for it.
Download the ThermaBot zip file