Top Topics

74*245 Motor Driver

H-Bridge Driver

Simple PWM Gen.

Handy Method Measuring RPM

Measuring RPM via Photo reflector

Introduction to Robotic

DC, Stepper,and Servo Motor

Related Link

Microcontroller Tutorial

Computer Interface
Tutorial

.............more links

 

 

 

BACK NEXT

3.4 Encoder

The encoder consists of an infrared emitter and phototransistor. They are aimed at each other. The emitter is a simple diode that emits infrared light and the phototransistor detects the infrared light from the emitter unless there is interference from a solid object between the two. The circuit is illustrated in the figure 3.3.1. This principle is used to determine how far the robot has traveled. The gear attached to the motor is placed between the emitter and the phototransistor. When the robot is in motion, the teeth of the gear cross between the emitter and the transistor causing a hardware interrupt. It will be recognized as a PCA (Programmable Counter Array) interrupt since the encoder is connected to PCA interrupt pin. Counting the interrupts (each tooth of the gear) allows us to calculate the distance the robot has moved. The emitter used for the project is the Omron EX-SX1088 LED and phototransistor packaged together.5 (See figure 3.4.1 and figure 3.4.2)

 

Figure 3.4.1(encoder circuit)

Figure 3.4.2 Encoder

3.5. Chassis

The chassis of the robot is constructed primarily of Legos. This made it easy to prototype design ideas and to make any necessary design alterations throughout the progress of the project. The specifications for the competition allow the robot’s dimensions to be at a maximum of 21 x 21 x 20 cm (width, length, and height). A robot of this size would have a great deal of trouble navigating through the course as the hallways are only 23 cm wide, leaving only 1 cm on each side of the robot in the hallway. With this in mind, we wanted to keep the chassis of the robot as small as possible to increase maneuverability. We chose to use two wheels as the method of steering for its simplicity and also to conserve space. A roller ball was used as a third wheel of sorts; it balances the robot and gives the front end a ride height that is congruent with the height of the LEDs on the candle. We also made sure that we have enough space to put the Lego, audible and distance sensor circuit boards on top of the robot chassis.

3.6 Software

The controller board was programmed in C using Keil uVision 2. The software was designed with modularity in mind. Each task the robot needs to accomplish is done through a series of function calls. Many functions are used multiple times in one run to cover the candle. The flowchart illustrates the code used for this project. (See figure 3.6.1)

The following is a list of the functions and a brief description of each. (Complete listing of source code is available in appendix B.) unsigned char ADC(unsigned char chnum) This function returns the value of a channel number passed to it from the analogto- digital converter. Because the Lego board uses an 8-bit analog-to-digital converter, the values range from 0 to 255, and an unsigned char is an appropriate data type for the return value.

void initializeCounter(void)
initializeCounter simply sets up the timers and the pulse width modulation (PWM) for the interrupt of the encoder. It enables the programmable counter array module 3 to be used for detecting a hardware interrupt caused by some external event, in this case the encoder.

void cupPlacement(void)
To use the servo motor to place the cup over the candle, the timers used for the operation have to be set up, this occurs initially in this function. The servo motor is then moved into position over the candle, and is returned to its original position. getBackHomeFromRoom1 (or 2, 3, 4 depending on the room the candle is located) is then called to return the robot to the home area.

void Delay(void)
This is a simple delay function consisting of a nested for loop that is used for timing in the positioning of the servomotor.

void start(void)
start loops idly until the filter acknowledges the proper starting signal, detected on port 1.3. This function is called immediately after initializeCounter in the main code.

void lightFind(void)
This function guides the robot to the candle while periodically checking the distance sensor to ensure the candle is not too close. Positioning the robot the proper distance directly in front of the candle is accomplished by moving forward any time the center light sensor sees the light from the candle. If the light is sensed by either the right or the left sensor exclusively, the trajectory of the robot is altered to the appropriate direction. If no light is detected by any of the sensors, the robot will scan in alternating directions, at increasing lengths. For example, the first time the light from the candle is undetected, the robot will turn approximately 10 degrees to the left. If the light is not found during that scan, or the light is again lost, the car will turn approximately 20 degrees in the opposite direction. This pattern keeps the robot from getting forced to make a complete 360 degree turn simply because the candle is just 10 degrees in the opposite direction, if it isn’t found in one short turn, it will be found during the next turn in
the opposite direction.

The entire time the robot is moving toward the candle, it looks at the distance sensor. If this value increases to a predetermined intensity for the candle to be in front of the car at the proper distance, and at least one of the light sensors sees a light, the robot is stopped and cupPlacement is called.

void room1(void), void room2(void), void room3(void), void room4(void) These functions are designed to use the line sensors and the encoder to get the robot to the doorway of the proper room. Each room was given a number and each function corresponding to that number puts the robot at the doorway to that room. These functions are called only once per run by the main code and are almost identical with the exception of different distance values to be traveled from the home area to the desired room. Once this function is called, it simply looks at the state of the counter, incremented by the PCA interrupt caused by the wheel rotation, and the lower light sensors facing the floor of the course. In each
possible state the motors can be in within this function, a direction bit is set. This global variable is then considered each time the encoder causes an interrupt. If the direction bit is set to 1, meaning the motors are both set to forward, the interrupt routine increments the counter called straightCounter. If the direction bit is set to 0, the interrupt knows that both motors are not set to forward and straightCounter will not be incremented (see figure 3.6.2). This increases the accuracy of the distance calculations greatly. Generally speaking, when both of the motors are not set to move forward very little, if any, forward progress is achieved, so the variable used to gauge distance will not be altered in the interrupt. In summary, this function follows the white line on the floor of the course for a specified distance, then returns.

PulseTime() interrupt 6 using 1
{
if(CCF3 == 1)
{
counter++; // This counter is incremented regardless of the
// direction the motors are set to
if(direction == 1) // If both motors are moving forward
counterStraight++; // Increment the counter for
// straight movement
TF2 = 0; // This resets the timer 2 overflow bit
// This is the 'watchdog' timer
// Each time this interrupt occurs it keeps
// the timer counting. It is important to do this
// here because we know the wheels are turning
// so as long as the wheels turn, the watchdog
// timer interrupt will not occur
CCF3=0; // reset the module 3 interrupt flag
}
}

BACK NEXT