Servo Position Status Variable?

Does the GoPiGo hardware maintain a “last servo angle cmd” status variable? (I don’t see a “getter” in gopigo.py )

My servo tends to move on its own when not enabled, so it probably would be unreliable. Perhaps that is reason not to keep it around.

Hi @cyclicalobsessive,

You’re right.
We don’t have a getter for the servo position.
I think we’ll implement it in the near future - this could work by regularly updating the servo, so that we avoid having the servo move on its own.


My servo tends to move on its own when not enabled, so it probably would be unreliable. Perhaps that is reason not to keep it around.

I think this post should help you understand why it’s moving sometimes :
forum.dexterindustries.com/t/solved-servo-trouble-servo-moves-unexpectedly-on-power-up-and-during-regular-operation/3137/3

This can also happen while the servo is not activated. Interferences might be the cause.
I haven’t tried, but maybe writing to the servo port digitalWrite(servo_pin, 0) might hold the line down and prevent the servo from rotating while it’s not operational. Again, it’s something I haven’t tested and it might not work.


Thank you!

1 Like

I wasn’t able to find a “getter” for the servo position. Was a “getter” for the servo position ever implemented?

I’ve mounted a distance sensor on a servo and it’s apparent that the methods to set the servo position are not blocking. I’m able to do some experimenting to see how long it takes the servo to move into position and can use that to insert some sleeps. However, it would be better if I could query the current servo position to tell when the target angle has been reached (similar to the way that the wheel movement can be monitored).

Hi @e.goldbloom, I implemented a wrapper around my tilt and pan servos that has a getter with some limitations, but the servo does not provide position sensing so you have to figure out how long to wait. The processor commands a position, and the servo races as fast as it can to that position. I have SG90 servos which are spec’d at 0.1s per 60 degrees, so 90 degree rotation = wait about 150 ms before starting a distance measurement.

# tiltpan.py    Tilt and Pan Servo Management Class
#
# Pan Servo:  PAN_LEFT_LIMIT  = 0, PAN_CENTER  = 90, PAN_RIGHT_LIMIT = 180   (for GoPiGo3 servo compatibility)
# Tilt Servo: TILT_DOWN_LIMIT = -90, TILT_CENTER = 0, TILT_UP_LIMIT   = 90
#
# Methods:
#  TiltPan(egpg)          # creates class object
#  tilt(pos = tilt_pos)
#  pan(pos = pan_pos)
#  tiltpan_center()       # convenience tilt(TILT_CENTER), pan(PAN_CENTER)
#  center()               # same as tiltpan_center()
#  off()                  # turn both servos off / non-holding position (sets pos to UNKNOWN)
#  nod_yes(spd=0.03)
#  nod_no(spd=0.02)
#  nod_IDK(spd=0.02)
#  get_tilt_pos()
#  get_pan_pos()
#
#
"""

# Usage:
import tiltpan
import easygopigo3
import myconfig
egpg = easygopigo3.EasyGoPiGo3(use_mutex=True)
myconfig.setParameters(egpg)
tp = tiltpan.TiltPan(egpg)
tp.tiltpan_center()
tp.tilt(tiltpan.TILT_CENTER)  # -90 to +90
tp.pan(tiltpan.PAN_CENTER)
print tp.get_pan_pos(), tp.get_tilt_pos()
tp.tiltpan.off()

"""

available here: (you don’t need the myconfig stuff - DI integrated keeping the parms in a json file)

1 Like

Hi @cyclicalobsessive,

Thanks for the info. It looks like you are saving the value when the servo position is set. I was planning to do the same thing to keep me from moving the servo if it is already set to that value. I’ve also written a script that will allow me to time the servo going through various angles. I can use the output of that to determine what the sleep values should be to minimize wait time. It sounds like that’s about the best that I can do.

Thanks again for your input.

1 Like