Page 1 of 1

Servo Control from Python

Posted: Sat Apr 06, 2013 9:23 am
by simplesi
I've got full PWM on all Pins and I've got unipolar stepper motor control in V2 of my Scratch GPIO handler http://cymplecy.wordpress.com/2013/03/1 ... velopment/ and now I'd like to add in servo control because I want 'bots to wave arms :)

Is there a simple/easy/safe (as in won't interfere with sound for instance) way of doing this yet

Have the guru's come up with a user lib for bodgers like myself to use? :)

regards

Simon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 9:42 am
by ame
Do a search on the forum for 'servoblaster'. It might be what you want, or it might not play nice with the other GPIO services you are running.

Your only other alternative might be a separate servo controller board, using RS232 commands (or some other bus interface).

Good luck!

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 3:05 pm
by simplesi
I just find a lot of stuff about kernels and tricky stuff like that when I search.

The C crowd seem to have it sorted but I'm looking for the easy peasy Python approach

e.g
Set GPIO pin 11 to servomode
p11.setpostion(120) and it move to 120 degree position

Simon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 3:18 pm
by raspberrypiguy1
Sorry, but what do you want to do? You want all the Pi's pins to drive servos in Scratch or Python?

I would be very very interested in Servo control in Python!

The Raspberry Pi Guy

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 4:23 pm
by simplesi
I'm developing V2 of my Python code that lets Scratch talk to the GPIO.
I just do the frilly bits and rely on RPi.GPIO and PzyPYm etc to do digitial in/out and PWM.

I've written a little thread class (if thats the right words) to handle stepper motors and it can also talk to Ultrasonic range sensors.

The two main things left are servos and analogue inputs.

So I'm just waiting/wanting the code gurus who write the clever libs to provide a simple reliable method of controlling servos.

I don't need any pin but I think I'm going to need at least a couple, maybe 3 or 4 for robot arms, car sterring, pen/ip down control on floor turtles ertc

Simon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 4:29 pm
by gordon@drogon.net
simplesi wrote:I just find a lot of stuff about kernels and tricky stuff like that when I search.

The C crowd seem to have it sorted but I'm looking for the easy peasy Python approach

e.g
Set GPIO pin 11 to servomode
p11.setpostion(120) and it move to 120 degree position

Simon
Use servoblaster.

Radio control type Servos need a special type of PWM - it's not bog-standard PWM as you might know it. I tried to get it to work in wiringPi, and there is code to do it, but the jitter in the Linux kernel and DRAM refersh by the GPU makes the servos chatter just a bit more than they like - so my userland PWM is fine for LEDs and speed control of DC motors - it's not fine for RC Servos. (I burnt one out testing the code).

So until wiringPi v3 is ready, use servoblaster.

-Gordon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 5:24 pm
by simplesi
AFAICT adding Servoblaster would be quite complex to add into my auto install script - I basically don't understand it :(

A fixed point in my project is that people take standard Raspbian and just run one piece of code to get it set up

Maybe the thing to do is to add a dedicated servo chip like this one http://www.hobbytronics.co.uk/servo-controller-12ch-ht and try to talk to the I2C bus (which I'm probably going to have to do anyway for analog inputs)

Or leave it out completely until the laws of physics (or the Linix kernel) change to suit me :)

Simon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 6:19 pm
by raspberrypiguy1
Hi again,

What is Servoblaster?! I saw the original post but I still don't completely understand it! I thought the Pi only had one PWM pin? Does Servoblaster make all the Pins PWM?

Thanks

The Raspberry Pi Guy

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 6:43 pm
by croston
simplesi wrote:I'm developing V2 of my Python code that lets Scratch talk to the GPIO.
I just do the frilly bits and rely on RPi.GPIO and PzyPYm etc to do digitial in/out and PWM.
Pizypwm is redundant with the software PWM support in the latest RPi.GPIO.

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 8:53 pm
by simplesi
I know but I daren't change to using it in case I introduce a bug ahead of tomorrows Jam :)

After 9pm, its first on the list to implement :)

Simon
PS right after the beers of course :)

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 9:00 pm
by simplesi
What is Servoblaster?! I saw the original post but I still don't completely understand it! I thought the Pi only had one PWM pin? Does Servoblaster make all the Pins PWM?
Its software to turn any pin into a servo type pin.

"PWM" can mean a few things - I use it when talking about simply changing on/off cycle to give a variable effecitive power out to feed motors and control their speed or dim LEDs.

One pin exposed on the GPIO does do this sort of PWM but one on its own isn''t much use to most people so the likes of @croston have added software code to nearly do the same as true hardware PWM - and for motor/led control, it does the job.

Servo pulse control uses a precise pulse timing and needs different approach.

That's how I see it anyway :)

Simon

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 9:10 pm
by raspberrypiguy1
Ah, great! That's cleared that up! I will have a look at it in the morning... What Jam are you going to tomorrow?

The Raspberry Pi Guy

Re: Servo Control from Python

Posted: Sun Apr 07, 2013 9:13 pm
by simplesi

Re: Servo Control from Python

Posted: Mon Apr 08, 2013 11:17 am
by saltydog

Re: Servo Control from Python

Posted: Tue Apr 09, 2013 9:41 pm
by simplesi
its this phrase
Since it uses the same on-board PWM module as the sound card it may interfere with sound.
that puts me off from using it as Scratch has had a few sound issues and although I don't tend to do much with sound myself, I wouldn't want to introduce any problems into anyone using Scratch on RPi.

I feel the stuff I'm putting out "has to work" no ifs or buts as my target audience is 10yr odls and their parents/teachers

I'm starting to think that maybe a workaround is to try and add more stepper motor control code and just use steppers where I would have gone for servos - more wires and slower response but they may be sufficient in practice

Simon

Re: Servo Control from Python

Posted: Tue Apr 09, 2013 11:21 pm
by saltydog
ServoBlaster gives you the option of using PCM or PWM hardware.
https://github.com/richardghirst/PiBits ... rvoBlaster
Note that use of PWM will interfere with 3.5mm jack audio output. Instead
of using the PWM hardware, you can use the PCM hardware, which is less likely
to cause a conflict.
Since RPIO is based on Servoblaster, I wonder if it also offers the same option?

Chris

Re: Servo Control from Python

Posted: Wed Apr 10, 2013 8:46 am
by simplesi
which is less likely to cause a conflict.
Unfortunately, I need "no likely" to cause a conflict :)

I don't want anyone, think 10 year old / busy primary teacher, having issues with normal Scratch due to my addon.

As I said, I don't use sound myself but I had a class using my Scratch For Arduino version on a load of Shrimps and some of the groups immediately added sound to their twirling ballerina's and one group that had a 7 seg display counting up recorded " 1,2,3,4,5 once a caught a fish alive..." and added it their project!! :)

http://www.euxton.lancsngfl.ac.uk/index ... d=46:year6

its terrible when the kids go off piste!!!! :)

Simon

Re: Servo Control from Python

Posted: Thu Apr 11, 2013 1:29 am
by danjperron
why not using the pololu servo controller

check this post

http://www.raspberrypi.org/phpBB3/viewt ... 94#p309394

Daniel

Re: Servo Control from Python

Posted: Thu Apr 11, 2013 3:07 pm
by simplesi
Cost too much unfortunately :)

I don't think I need fine precision, I probably just need the servo's to not burn out by constantly chattering !

Simon

Re: Servo Control from Python

Posted: Thu Apr 11, 2013 11:26 pm
by danjperron
Well if cost is an issue you could just buy the cpu itself.

I don't know are good you are with micro-controller programming.

Does the kit for your kids will include a breadboard? if yes than they could just plug the 18 pins DIP cpu on it!

I know that Pololu uses Pic16F628. So you could use the Pic16F628A which has its own internal oscillator . So you will need to plug ground, power, pin for communication (serial TXM) and the output for each of your R/C Servo. The cpu is less than $2 US.

This is an example I found on the net
http://www.digitalnemesis.com/info/projects/picservo/
http://www.merlotti.com/EngHome/Computi ... roller.pdf

Sometimes when cost is an issue, it takes more time to be there.

Daniel

Re: Servo Control from Python

Posted: Fri Apr 12, 2013 8:46 am
by simplesi
Its not just the cost :)
I'm basically want to make controlling outside world as easy and cheap as possible from the RPi.

So at the moment, the only external component I'm using for both DC and stepper motors, is a ULN2003 at £0.37 :)

As well as being cheap, its easy to explain its function in beginners terms (buffers the RPi from ill effects from motors) so I love it :)

I do realise that once an external MCU is added, controlling motors/servos/analogue input is very easy to achieve (for us lot and I could make the interface invisible to pupils/teachers) but I feel that that's a step too far in moving away from the the RPi can do itself and would be a case of - just plug this little circuit in and watch what it can do.

I just need to wait a little bit more time for the servo wizards to give us the cake with the extra icing on the top :)

Simon

Re: Servo Control from Python

Posted: Fri Apr 12, 2013 1:26 pm
by danjperron
I see your point,

I did order some pic12F1840 to get some A/D to my next RPi project. This is a 8 pins DIP with 6 I/O. I could easily create the code to run 4 servos with it. If someone is interested just tell me.
I will share my code.

Daniel

Re: Servo Control from Python

Posted: Sat Apr 20, 2013 4:13 pm
by danjperron
I received the cpu and I was able to create a 4 servos modules.

which it could be enhanced to be a 60 servos system.

I create a new post for it

http://www.raspberrypi.org/phpBB3/viewt ... 95#p335295

Daniel