Controling servo with python and A13 also generating PWM through a pin

Started by MMp131316, April 18, 2013, 09:39:42 PM

Previous topic - Next topic

MMp131316

Hello all ;),
I am trying to control a medium servo motor with python, and i am wondering if there are any python libraries with which i can control more easilly the servos( something like servo.move(number_of_degrees)) or at least is there any python function to give a pwm through a pin?

Thanks for your time!
Regards. ;)

olimex

it would be tricky to do PWM with pulse width 900-2200 uS on Linux

MMp131316

It trully was a simple task ::) I thought it would be more difficult :)
Thanks anyway

olimex


MMp131316

I repetated it with 2 video players and it worked ok. Should have i observed some delays when the servo was moving?? :)

olimex

no, you should see servo turned at wrong angles
servo tunr angle depend on the pulse width
Llinux RTOS cant guarantee fixed time for code execution as if higher priority task interrupt your code while it makes the pulse this pulse width may vary i.e. your servo angle may vary too depend on how many processes you run on your board

empedokles

Python can't be used for controlling servos? Is this correct?

olimex

Our tests show Python bit-bang ON/OFF acheieve 100kHz i.e. 10 uS resolutioin which on the normal servos which require timing between 800 and 2100 uS represent 1 degree resolution, so yes, it's possible
the problem is that Linux is RTOS and if the code will be executed at same speed depend on how many processes you are running at the same time
i.e. running Servo and meantime packet is received from the Ethernet, and at the same time user decides to play video and processor must decode video stream etc.

JohnS


olimex

I mean that when you may have N-processes (where N is 1 to 100) running at same time you can't make sure your code will be executed always at same speed

empedokles

Could one solve that by another module or shield? Which controls motors?

olimex

sure AVR-T32U4 will drive up to 7 servos IIRC and you can control it through the UEXT or USB

Simon

Hi all,

Like Olimex stated it may result in unwanted movement of the servo if you make the pulse using Python. The other way to do this is to use an on-chip hardware timer that will produce the pulse for you. Now you only need to set the timer registers determining the cycle time and the on-time. This results in the following questions:
1. is there a timer available?
2. with an external IO pin?
3. and is there a driver?
4. how to access it from Python?
Hoping for an answer.
Regards, Simon.