Servo Control from Python


23 posts
by simplesi » Sat Apr 06, 2013 9:23 am
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/19/scratch-gpio-development/ 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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by ame » Sun Apr 07, 2013 9:42 am
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!
Posts: 936
Joined: Sat Aug 18, 2012 1:21 am
Location: Japan
by simplesi » Sun Apr 07, 2013 3:05 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by raspberrypiguy1 » Sun Apr 07, 2013 3:18 pm
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
13... Now 14... Now 15 year old Raspberry Pi tutorial maker, programmer, electronics tinkerer, fascinated by space & the ISS, Maths enthusiast. Oh... And the Raspberry Pi is awesome!
User avatar
Posts: 365
Joined: Sun Sep 02, 2012 7:01 pm
by simplesi » Sun Apr 07, 2013 4:23 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by gordon@drogon.net » Sun Apr 07, 2013 4:29 pm
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
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1530
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by simplesi » Sun Apr 07, 2013 5:24 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by raspberrypiguy1 » Sun Apr 07, 2013 6:19 pm
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
13... Now 14... Now 15 year old Raspberry Pi tutorial maker, programmer, electronics tinkerer, fascinated by space & the ISS, Maths enthusiast. Oh... And the Raspberry Pi is awesome!
User avatar
Posts: 365
Joined: Sun Sep 02, 2012 7:01 pm
by croston » Sun Apr 07, 2013 6:43 pm
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.
User avatar
Posts: 449
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
by simplesi » Sun Apr 07, 2013 8:53 pm
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 :)
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by simplesi » Sun Apr 07, 2013 9:00 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by raspberrypiguy1 » Sun Apr 07, 2013 9:10 pm
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
13... Now 14... Now 15 year old Raspberry Pi tutorial maker, programmer, electronics tinkerer, fascinated by space & the ISS, Maths enthusiast. Oh... And the Raspberry Pi is awesome!
User avatar
Posts: 365
Joined: Sun Sep 02, 2012 7:01 pm
by simplesi » Sun Apr 07, 2013 9:13 pm
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by saltydog » Mon Apr 08, 2013 11:17 am
Have you looked at RPIO.
viewtopic.php?f=32&t=36670&hilit=rpio

Chris
Posts: 18
Joined: Mon Dec 24, 2012 10:40 am
by simplesi » Tue Apr 09, 2013 9:41 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by saltydog » Tue Apr 09, 2013 11:21 pm
ServoBlaster gives you the option of using PCM or PWM hardware.
https://github.com/richardghirst/PiBits/tree/master/ServoBlaster
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
Posts: 18
Joined: Mon Dec 24, 2012 10:40 am
by simplesi » Wed Apr 10, 2013 8:46 am
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.php?option=com_content&view=article&id=535:ict-in-y6&catid=46:year6

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

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by danjperron » Thu Apr 11, 2013 1:29 am
why not using the pololu servo controller

check this post

http://www.raspberrypi.org/phpBB3/viewtopic.php?p=309394#p309394

Daniel
Posts: 903
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada
by simplesi » Thu Apr 11, 2013 3:07 pm
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by danjperron » Thu Apr 11, 2013 11:26 pm
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/Computing/servo_controller.pdf

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

Daniel
Posts: 903
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada
by simplesi » Fri Apr 12, 2013 8:46 am
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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
Posts: 2053
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
by danjperron » Fri Apr 12, 2013 1:26 pm
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
Posts: 903
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada
by danjperron » Sat Apr 20, 2013 4:13 pm
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/viewtopic.php?p=335295#p335295

Daniel
Posts: 903
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada