adafruit / Adafruit_CircuitPython_ServoKit

CircuitPython helper library for the PWM/Servo FeatherWing, Shield and Pi HAT kits.
MIT License
69 stars 29 forks source link

A function to access the current servo angle #12

Closed Chaitanya-Mehta closed 4 years ago

Chaitanya-Mehta commented 4 years ago

If we can add a function to access the current angle of the servo that is commanded, the library will be much more useful. I am using PCA9685 in a robot and I need to access the current angle of the servo to command the next angle via increment.

ladyada commented 4 years ago

that isn't supported but if you'd like to add it and submit a PR it would be welcome!

Chaitanya-Mehta commented 4 years ago

Alright! I am not so experienced with programming, but I will surely try. Would you please let me know the class where I need to make necessary changes, and provide a link to that?

caternuson commented 4 years ago

Maybe it's already in place? https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/adafruit_motor/servo.py#L109 Would this work? To set:

kit.servo[0].angle = 180

To query:

kit.servo[0].angle
ladyada commented 4 years ago

@Chaitanya-Mehta please try that

Chaitanya-Mehta commented 4 years ago

Yes. It works as the angle is defined as property. I found that way and also checked via implementation. So, it's working.

To get the last servo angle in the variable x; x= kit.servo[0].angle

Thanks Ladyada!