Maze Robot Sensor Integration

Featured ProjectsPublished February 26, 2010 at 12:15 am No Comments

DSCN6956

This project was completed during a course on robotics taught by Prof. Dave Barret at Olin College. The final project for the course, the goal of the project was to navigate a maze using a Surveyor robotic platform. As part of this project, additional sensors were added to the robot. This writeup will focus on the addition of the sensors because they illustrate an example of engineering problem solving skills as we extended the capability of a platform beyond its original design. This project was completed with collaboration from Leif Jentoft.

background

The challenge of this final project was that the surveyor platform only contained a single sensor, a video camera. Furthermore, the platforms were running a parallel programming language called Occam Pi that made making the maze solving algorithms pretty easy, but adding sensors difficult. Because of the distinct difference between the colors of the walls of the maze and floor, a color differentiation algorithm using the camera could be successful in navigating the maze. All of the other teams chose to take this approach. While a few of the teams did have success with this approach, we chose to install a few Sharp infrared distance sensors instead.

We knew from the beginning that there were significant issues with this approach. Like most sensors, the Sharp IR distance sensors that we were trying to use output only analog voltages between  a low voltage (almost zero) and the high power rail.  The Surveyor used a Blackfin DSP chip as its CPU. By design, it was limited to having only digital inputs so we needed to provide the Surveyor with some sort of digital values so that we could use IR distance sensors to help us navigate the maze.

The Occam SDK for the Surveyor platform could not yet read serial values at the beginning of the project. While this functionality was added to the  SDK midway through the project, it was too late for us to use.

the micro-controller

For this kind of application, there were many choices of applicable micro-controllers. Because I had worked with a PIC extensively in the past and my collaborator was also very familiar with PICs as well as the C code used to write code for them, we chose to use a PIC over other available solutions. The PIC we wanted was a PIC16F690; it accepted a wide range of voltage inputs and had everything we need in a very small package. On the downside, Microchip (the company who made this PIC) didn’t offer a free compiler to use this PIC16 series controllers and we were unwilling to take the time to figure out how to use third party libraries. For that reason we opted to use an overpowered PIC18F series PIC. Because the Surveyor used 3.3V and not the more standard 5v as its source, we needed to use a low voltage PIC to ensure proper operation. We opted to use a PIC18LF2221 because it had built in math functions, plenty of analog and digital IO pins and an internal oscillator that we could use to clock the PIC. The LF indicates that it can be used at lower voltages.

The plan was to use the PIC to translate the analog output from the IR distance sensors into a PWM (pulse width-modulated) signal. Because both the Surveyor and the PIC had processors that were clocked, we could effectively translate the analog signal into a digital pulse. We chose a linear relationship between the length of the pulse and the voltage to help determine the distance. Because there were problems changing inputs and accessing different digital inputs on the Surveyor, we changed our initial conceptual design from one PWM signal line per sensor to a scheme that used inputs to tell what sensor was being read and then had the value sent along one PWM channel that was used by all the sensors. We considered this part of the design to be a work-around for a bug that was either in the base code of the Surveyor’s Occam Pi based code or in the hardware itself. Because we didn’t have another robot to debug on, or much time to figure this out; we simply used the workaround as a solution. We considered this less than ideal as we knew it would make the PIC code seem a little messy when compared with our ideal design.

circuit

circuit diagram-PIC18
circuit diagram-PIC18

The circuit diagram above describes the wiring of the PIC and the sensors. The 10k resistor between ground and pin 1 as well as the 10 micro-Farad capacitor bridging power to ground  between pins 19 and 20 are needed to run the PIC without an oscillator and are not particulars of our design. The sensor ground and power were also filtered to clean up the analog signal from the IR sensors. The important items that were included on the design are single PWM signal out line and the four sensor enable pins that match four different analog inputs.

code/logic

After setting the proper configuration bits we then worked on the logic needed to make this system work. The code needed to run this PIC was written in C using the Microchip 18C compiler and associated libraries. The logic portion of the code used to run a single sensor the example shown below.

Inside of an infinite while loop (because we want our code to always be running on the PIC waiting for input signals), we used the following logic:

if (INTCONbits.T0IF == 1 && PORTCbits.RC4 ==1 ){ //if the timer interrupt goes off…and sensor 4 is selected

INTCONbits.T0IF = 0;  //reset the timer interrupt flag, we now have ~1000 clock ticks to process everything else

//get RA0 analog in

ADCON0 = 0×03;                           // select AN0 and set GO_DONE bit to start A/D conversion

while (ADCON0bits.GO_DONE); // do nothing until the A/D conversion is done

pwm0 = ADRESH/4;//input from RAO, 8 most significant bits

//generate the pulses

if (counter < pwm0){PORTBbits.RB0=1;}

if (counter > pwm0){PORTBbits.RB0=0;}

}

When the Timer (set to expire every millisecond) went off and if the Surveyor had set the enable pin for this particular sensor high, then we set the digital out to high if the scaled analog input is greater than a counter than counts the number of milliseconds that have passed. We set the bits low when the counter is greater than the analog input, thus generating a crude PWM signal.

The counter is incremented at the bottom of the loop.

counter++; //counts the number of milliseconds

if (counter > 50){counter=0;} //reset counter to set PWM to 100Hz

When the counter goes over  50 we reset the counter to 0 so that way we get a 100hz PWM signal as an output. We then sampled the sensors to allow the  vehicle to follow walls and see open spaces in front of it. This logic code was the same for each sensor with the exception that the enable bit and the analog input were received on a different ports.

conclusions

In conjunction with wall following algorithms, our robot was able to solve the maze. Though, other teams succeeded in using the camera to complete the challenge, our robot was also successful. Our work on this sensor integration was preserved so that students in the future would be able to easily integrate analog sensors into the Surveyor platform.

This project was shown at Olin Exposition in the Spring of 2008.

Leave a Reply

(required)

(required)