Author Topic: question on arrays and remembering servo movement.  (Read 1715 times)

0 Members and 1 Guest are viewing this topic.

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
question on arrays and remembering servo movement.
« on: March 05, 2010, 10:55:55 AM »
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
}



« Last Edit: March 05, 2010, 10:57:53 AM by blackbeard »
"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
Re: question on arrays and remembering servo movement.
« Reply #1 on: March 06, 2010, 06:40:03 PM »
bump
"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
Re: question on arrays and remembering servo movement.
« Reply #2 on: March 07, 2010, 07:18:06 PM »
bump
"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: question on arrays and remembering servo movement.
« Reply #3 on: March 07, 2010, 07:28:07 PM »
Is there a problem with it? Does something not work?

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
Re: question on arrays and remembering servo movement.
« Reply #4 on: March 10, 2010, 07:54:57 AM »
Is there a problem with it? Does something not work?

what i'm wondering is if i'm using an array properly. i know there is a problem in that code where i didn't invert the movements as it backtracks but you should get the idea of what it's trying to do.
"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

 


Get Your Ad Here