ok so here is what i want to do. i want to write a program that remembers the commands sent to a robot through a remote control and backtracks accordingly. i may also edit this code so if the robot does not receive commands that it can find it's way back. this only deals with the right servo but it wouldn't need much to make it do the same kind of thing for the left one as well. this is a semi psudo code of what i'm sort of thinking. if you can find any holes to poke i would very much appreciate it :)
int servomemstep //this is variable is compared with the servomemory variable to check which pulses are sent to the servo and how long.
int servomemory; //this is the number of saved movements
int controlcheck; //checks the state of the controler
int rightservomovement [servomemory]; //saves the pulses sent to the servo in order to read them later for backtracking
int rightservosmovef //if this is 3 then the servo moves forward. if none or more then one are 3 then it rechecks for the input
int rightservomoveb //if this is 3 then the servo moves backward. if none or more then one are 3 then it rechecks for the input
int rightservomoves //if this is 3 then the servo stays put. if none or more then one are 3 then it rechecks for the input
int gohome //if this is 3 then the "go home" command has been received and the servo will backtrack. if none or more then one are 3 then it rechecks for the input
int positivecondition //used to calculate weather a valid signal has been achieved or if the program needs to check again for a signal
void looop () {
//below is the check to see if a control is recieved. since the controller is inaccurate the signal needs to be received 3 times within a certain
range to be considered a positive reception.
while (positivecondition != 1;) {
positivecondition = 0
for (controlcheck < 4; controlcheck++) { //checks to see if controler's frequency is between a certain range 3 times
if pulsein (6, >300); pulsein (6, < 400);) {rightservomoves = rightservomoves + 1;}
}
controlcheck = 0
for (controlcheck < 4; controlcheck++) { //checks to see if controler's frequency is between a certain range 3 times
if pulsein (6, >500); pulsein (6, < 600);) {rightservomovef = rightservomovef + 1;}
}
controlcheck = 0
for (controlcheck < 4; controlcheck++) { //checks to see if controler's frequency is between a certain range 3 times
if pulsein (6, >700); pulsein (6, < 800);) {rightservomoveb = rightservomoveb + 1;}
}
controlcheck = 0
for (controlcheck < 4; controlcheck++) { //checks to see if controler's frequency is between a certain range 3 times
if pulsein (6, >900); pulsein (6, < 1000);) {gohome= gohome + 1;}
}
controlcheck = 0
if (rightservomoves = 3) {gohome = gohome + 1;}
if (rightservomoves = 3) {positivecondition = positivecondition + 1;}
if (rightservomovef = 3) {positivecondition = positivecondition + 1;}
if (rightservomoveb = 3) {positivecondition = positivecondition + 1;}
}
positivecondition = 0
//this is where the movements are set and performed
while ((rightservomoves + rightservomovef + rightservomoveb) => 3;) {
if (rightservomoves = 3) {(servo stays put); servomemory = servomemory + 1; rightservomovement [servomemory] = (whatever pulse makes it stay put); rightservomoves = 0;}
if (rightservomovef = 3) {(servo moves forward); servomemory = servomemory + 1; rightservomovement [servomemory] = (whatever pulse makes it move forward); rightservomovef = 0;}
if (rightservomoveb = 3) {(servo moves backward); servomemory = servomemory + 1; rightservomovement [servomemory] = (whatever pulse makes it move backward); rightservomoveb = 0;}
}
//this is it's return code
servomemstep = servomemory
for (gohome = 3; servomemstep > 0; servomemstep = servomemstep - 1;) {
pinmode (8, HIGH)
delay (rightservomovement [servomemstep])
pinmode (8, LOW)
}
gohome = 0
}