USA
Asked — Edited
Resolved Resolved by thetechguru!

Getservo() Explanation

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)


ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

#1  

Servos are one way communication. They will go to the position you tell them, but have no way (except very expensive Dynamixel servos) to report back that they have actually reached that position.

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

United Kingdom
#2  

I'm unable to test your script, but GetServo does give back the last servo position, but I did notice something that might be causing the issue in script #1. on the "IF" lines, I think the brackets (parentheses) should be around the last number value like below...

: 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)

EDIT: This is taken from the EZ-Script manual...

Quote:

GetServo( Port ) Returns the servo Position value of the specified port Servo position is between 0 and 100 Example: $x = GetServo(d0)

although I believe it's between 1 and 180 with 0 (zero) being servo release.

#3  

The GetServo command only returns the position at which the servo is supposed to be. Not where it really is. At any moment that can be different. As it moves to the position for example or if it is snagged on something and cannot physically move to where it is supposed to be. In normal operation, however, it should be where it is supposed to be, given the sleep time delay to allow for that to happen. That also assumes it has been properly calibrated.

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. https://synthiam.com/Community/Questions/8309&page=1

#4  

Use code 2... as mentioned getservo returns the last postion ARC Told the servo to go to.... doesn't mean the servo got there. However, 99.99% of the time (unless the servo has no power, is binding on something or is otherwise not working) it will move to that position....

#5  

Thanks all for your help. I should have known this, but I haven't played with these in about 10 years, the answer makes sense. Thanks WBS00001 for the resource about the analog feedback servos, I'm sure I'll be getting some of those soon.