
R1D1

So I wrote a code to assist in obstacle avoidance when I'm driving my robot, but it doesn't work, so I tried a couple of similar codes in a smaller version to find the culprit.
Code #1 below only results in my sensor servo jittering. Code #2 works, but doesn't give me what I need, which is the exact location of the servo so I can know in what direction I'm taking sensor readings in.
After watching the code execute I'm under the impression that the GetServo() returns the position that the servo has been "directed to be in" and not the actual position. Is this correct? If so, then what command am I looking for that will tell me the position it is in so I wont' get the position it is supposed to be in while the servo is still on it's way there.
If the GetServo() does in fact return the exact position the servo is in, then why is my Code#1 below not working when Code #2 does?
Thanks in advance for any assistance.
Code #1
:Pan_Left
sleep(100)
Servo(D2, 85)
ServoSpeed(D2,5)
if(Getservo(D2))=85
goto(Pan_Right)
endif
goto(Pan_Left)
:Pan_Right
sleep(100)
Servo(D2, 125)
if(Getservo(D2))= 125
goto(Pan_Left)
endif
sleep(25)
goto(Pan_Right)
Code #2
:Pan
Servo(D2, 85)
ServoSpeed(D2,5)
sleep(2000)
Servo(D2, 125)
sleep(2000)
goto(Pan)
GetServo() tells you the last position the servo was told to go to. It is primarily useful in a script where either another script, a movement panel, or another object may have told the servo to move, and your script needs to know the initial position to make decisions about the next position to go to.
Alan
Code:
EDIT:
This is taken from the EZ-Script manual...
although I believe it's between 1 and 180 with 0 (zero) being servo release.
To get the real position you will have to tap into the potentiometer in the servo itself. Then come up with a way to read it, such as via the A-D converter inputs. There are other servos which have that capability built in should you wish to change the servos out so as to have that capability.
EDIT
There is an inexpensive servo which has the potentiometer available to the user.
http://www.adafruit.com/products/1404
And the thread in which I first mentioned the servo.
http://www.ez-robot.com/Community/Forum/Thread?threadId=8309&page=1