Servo command

I can write to the servo, changing it’s position but it would be useful to be able to read the servo’s current position. I’ve looked at the servo code but don’t see a way to do that. Is it possible?

Thanks!
Brenda

Hi Brenda,
There is no way to actually read the angle back from the servo, you can only give it signals and the signals set the servo at particular angles. You can store the angle value locally in your program before writing that to the servo. Would that help. Can you give us some more details about what you are trying to do with it and maybe there might be an alternate way to do that.

-Karan

Hi Karan,

Thank you for the reply. Here are my thoughts on what I’m trying to do. When the GoPiGo is booted, I can’t be sure what the angle of the servo is. If I know, I could set the angle to straight ahead. I typically write in ‘C’ though I’m familiar with a several languages. On boot, the servo typically points to left of straight ahead. Through experimentation I’ve determined that setting the servo angle to 80 is straight ahead with a maximum of right angle of 1 and a maximum of left angle of 170. Those values move the servo to point to the right and left respectively. Those values I’ve defined in ‘C’ to be used when scanning through the environment. If there is an approach to this you prefer, I’d like to hear it. Always open to improvements.

A different issue is enabling the Pi camera programmatically in ‘C’. I haven’t found an existing library to do that. The closest I’ve come is the ‘Raspicam’ code. I was thinking of reverse engineering that into a library with an API interface. I’d like to hear your thoughts on this too.

Thanks!!
Brenda

For restoring the servo angle on boot, saving it to a text file and read it from there when the program starts might be your best bet. Every other solution would take a lot more time to get working.

For using the pi camera, using the system() function from C might help: http://stackoverflow.com/questions/29762189/how-to-execute-bash-commands-from-c. You can give a bash command in it or write a script in Bash and call it from the C code.

-Karan