Saturday, May 4, 2013

Capstone Project - Servo's Interfacing Documentation



I used this servo for the turret and left/right steering. But almost any servo will work for this application. And here you can find the PIC16F887 Microcontroller.

Interface:

Both servos in the project work the exact same way. A PWM(Pulse Width Modulation) signal is achieved with the following algorithm to control the rotation. The servos rotation was programatically limited to avoid vehicle stalling and over-rotation. The L/R servo is connected to RB7 (Pin 40) of the vehicle's microcontroller. The Turret servo is connected to RB6 (Pin 39) of the vehicle's microcontroller. When the receiver receives the proper signals the servos will rotate accordingly and stop at their preprogrammed positions.

 


Programming Algorithm: (Actual code will be discussed later..)

#define LRServo RB7
#define TURRServo RB6

int facenorth = 223, fullrotationdelay = 3000;
int leftrightpositiondelay = facenorth, turretpositiondelay = facenorth;
int rightbound = 265, leftbound = 180;
int delayincrementstep = 5;

while ( ProgramRunning )
{
//Update PWM signal for L/R Servo
if( TurnRight && leftrightpositiondelay <= rightbound)
{
//If right switch is pressed and we have not reached the right bound
leftrightpositiondelay += delayincrementstep;
//increment the high pulse by the delay increment step 5
}
else if( TurnLeft && leftrightpositiondelay >= leftbound)
{
//If left switch is pressed and we have not reached the left bound
leftrightpositiondelay -= delayincrementstep;
//decrement the high pulse by the delay increment step 5
}
if( TurretRight && turretpositiondelay <= rightbound)
{
//If right switch is pressed and we have not reached the right bound
turretpositiondelay += delayincrementstep;
//increment the high pulse by the delay increment step 5
}
else if( TurretRight && turretpositiondelay >= leftbound)
{
//If left switch is pressed and we have not reached the left bound
turretpositiondelay -= delayincrementstep;
/decrement the high pulse by the delay increment step 5
}
LRServo = 1; //PWM High Pulse
DelayMicroseconds(leftrightpositiondelay); //High pulse delay
LRServo = 0; //PWM Low Pulse
DelayMicroseconds(fullrotationdelay – leftrightpositiondelay); //TTOTAL – THIGH = TLOW
TURRServo = 1; //PWM High Pulse
DelayMicroseconds(turretpositiondelay); //High pulse delay
TURRServo = 0; //PWM Low Pulse
DelayMicroseconds(fullrotationdelay – turretpositiondelay); //TTOTAL – THIGH = TLOW
}

No comments:

Post a Comment