Detailed code for the pyb.Servo library

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sdlc
Posts: 3
Joined: Wed Feb 17, 2016 10:32 am

Detailed code for the pyb.Servo library

Post by sdlc » Wed Feb 17, 2016 10:42 am

Hi All !

I am working on a project using a pyboard and servos.
I would be very interested in having the detailed code for the pyb.Servo library.
I have spend much time searching it, but I haven't found it yet....
Where could I find it?

Thank you very much!

Simon

User avatar
dhylands
Posts: 3457
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Detailed code for the pyb.Servo library

Post by dhylands » Wed Feb 17, 2016 1:55 pm

It's written in C. You'll find the code in this file: https://github.com/micropython/micropyt ... al/servo.c

You can also control servos by using pwm like what's done here: https://github.com/dhylands/upy-example ... ic_test.py

sdlc
Posts: 3
Joined: Wed Feb 17, 2016 10:32 am

Re: Detailed code for the pyb.Servo library

Post by sdlc » Fri Feb 19, 2016 10:53 pm

Hi dhylands!

Thank you for your answer.

Actually, I have already implemented three functions in order to control my eight servos:
The first one generates PWM (I have adapted the PWM generation presented in the Quick Ref of the pyboard), the second one converts angles (in degrees) into a pulse width percent, and the third one allows me to control my servos by giving an angle order, and not a pwpercent.

My problem is following:
When I call the latter function several times with a short delay between each call (1 sec), the servo doesn't rotate continuously but step by step. And if the order remains the same, it "jerks" each second.
I don't have this problem when I use the Servo(X).angle() function.

Do you have any idea?

User avatar
deshipu
Posts: 1374
Joined: Thu May 28, 2015 5:54 pm

Re: Detailed code for the pyb.Servo library

Post by deshipu » Sat Feb 20, 2016 12:10 am

My guess is that you are resetting the timer, instead of only changing the duty cycle. But really hard to tell without seeing the code.

sdlc
Posts: 3
Joined: Wed Feb 17, 2016 10:32 am

Re: Detailed code for the pyb.Servo library

Post by sdlc » Sat Feb 20, 2016 9:31 am

It was indeed the case.......Stupid mistake!
Thank you!!

Post Reply