MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 12:04 pm

Hi - this is my first post to what looks like a fantastic resource for us developers!

What I'm trying to do:
I'm building a device that controls up to 40 servo motors and each one must be turned on and off to a tolerance of 1/10 of a second. I've played with the Arduino and got one servo working, but now I need to think of programming and 40 servos working. This is going in a unit sold to consumers and will be maintained and monitored via WiFi. The unit itself will be driven by Apps on cell phones and there will be a touch screen on the unit used daily by the operator.

I picked the Raspberry Pi 2 and Python as the tools to do the job. However now I'm now reading that the garbage collection in Python is random and can interfere with real time operations and Linux is multitasking that can cause a servo to miss a cycle or shorten the time it is on because I can't set a priority level for my program. My high hopes are now being deflated by reality.

I could develop in C++ but it will take 5 times as long to produce the software and the Quad processor on the Pi 2 should handle the Python interpreter to a tolerance of 1/10 of a second with no problem - that's my assumptions that are now being challenged with comments from other developers.

I'm assuming many here have worked with the Pi 2 and Python and might have some real-time experience that might save me thousands of man hours just to learn that garbage collection means more to the Pi and Linux than my program.

Thanks for any input...

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 1:26 pm

MauiSunset wrote:Hi - this is my first post to what looks like a fantastic resource for us developers!

What I'm trying to do:
I'm building a device that controls up to 40 servo motors and each one must be turned on and off to a tolerance of 1/10 of a second. I've played with the Arduino and got one servo working, but now I need to think of programming and 40 servos working. This is going in a unit sold to consumers and will be maintained and monitored via WiFi. The unit itself will be driven by Apps on cell phones and there will be a touch screen on the unit used daily by the operator.
I think you will run out of GPIO pins before you get to 40 servos so you may have to use arduinos as well or an additional pi.
I picked the Raspberry Pi 2 and Python as the tools to do the job. However now I'm now reading that the garbage collection in Python is random and can interfere with real time operations and Linux is multitasking that can cause a servo to miss a cycle or shorten the time it is on because I can't set a priority level for my program. My high hopes are now being deflated by reality.
True but unless you are very compute intensive I should have thought 0.1 second tolerance should be ok. I would like to see real evidence that "random" garbage collection is a real problem. What might be more important is the "Global Interpretter Lock" that stops a multi threaded python program using multiple cores. This would probably only matter if your code is compute intensive.
I could develop in C++ but it will take 5 times as long to produce the software and the Quad processor on the Pi 2 should handle the Python interpreter to a tolerance of 1/10 of a second with no problem - that's my assumptions that are now being challenged with comments from other developers.

I'm assuming many here have worked with the Pi 2 and Python and might have some real-time experience that might save me thousands of man hours just to learn that garbage collection means more to the Pi and Linux than my program.

Thanks for any input...
I have played with python but not done anything like this for real. Perhaps someone else can give a more qualified reply.

Roger Woollett

MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 1:35 pm

Thanks much for your input, I appreciate it.

I was hoping that one of the quad processors would do things like garbage collection - maybe not now but within a year.
It's going to take me at least 1 year to develop the product and I really don't want to use C++.

The 40 solenoids don't worry me since I'm using a digital way to activate them in a serial circuit - I could control up to 255 from 1 port.

I just remember programming in Basic 30+ years ago and the garbage collection problem hurt me then on a time critical program - sounds like the geeks in academia haven't made much progress in that area in 30 years.

Maui

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 1:42 pm

MauiSunset wrote: I just remember programming in Basic 30+ years ago and the garbage collection problem hurt me then on a time critical program - sounds like the geeks in academia haven't made much progress in that area in 30 years.
It sounds like you have managed to keep pace with them.

MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 1:49 pm

I'm 68 years old and still programming - I remember punching in Hex into some Heath Kit that had 4 K memory and thought I was in heaven then...

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 2:39 pm

MauiSunset wrote:I'm 68 years old and still programming - I remember punching in Hex into some Heath Kit that had 4 K memory and thought I was in heaven then...
So a newbie then. My first programs were on 5 hole paper tape sent by van to a Ferranti computer that used valves (vacuum tubes) not transistors.

Seriously I would stick to python. If you eventally find real problems you will have a prototype that you can translate into C++ so the investment will not be wasted.

Roger Woollett

MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 2:55 pm

RogerW wrote:
MauiSunset wrote:I'm 68 years old and still programming - I remember punching in Hex into some Heath Kit that had 4 K memory and thought I was in heaven then...
So a newbie then. My first programs were on 5 hole paper tape sent by van to a Ferranti computer that used valves (vacuum tubes) not transistors.

Seriously I would stick to python. If you eventally find real problems you will have a prototype that you can translate into C++ so the investment will not be wasted.

Roger Woollett
That's my leaning at this time - for the past 20 years I have only worked with prototyping systems and then turned over the fully functional system to an army of kids who program in C++.

But it would be nice to know that what I'm doing could be a consumer product without an army of C++ guys in the back office.

BTW, this is a project my son dreamed up and I volunteered to do the programming until he sells 500+ units on Kickstarter and can hire real programmers. Frankly, I'd rather be in Maui.

Also, working with breadboards, wires, LEDs, resistors, bring me back 35 years - it felt just the same - like you were on the beginning of a fantastic ride...just replace the LEDs with "wheat" size Emerson bulbs and divide everything by 1,000,000,000 and you have now what we had back then.

Thanks for the feedback.

(Vacuum tubes? wow - that's before my time)

ghp
Posts: 1466
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 8:48 pm

Hello,

will you control servo (pwm, 20ms cycle, pwm controlled) or solenoids with your machine ?
What about 7*24 h operation ? From time to time you will loose power... And there is need for maintenance, updating os which is cpu intensive.

My first ideas have been to control the hardware by an arduino due (54 digital IO + others), 84MHz clock, equipped with additional RTC-chip which ensures that after a power loss the apparatus is back really quick without the need to wait for a host. Then connect this by a serial TTL connection to a PI and handle user interface, timekeeping, data preparation in python there.
Think of producing g-code, continuously fed into a slave processor, (burned to eeprom there for persistency).

Best of both worlds, microcontroller and unix.

With this system, could be your greatest concern will be leap years, leap seconds and summer/winter time...

Regards,
Gerhard

MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 9:15 pm

12 V solenoid valves that are normally closed but opened for 1 to 3 seconds. (+-0.1 seconds is acceptable)

If the power goes out the device is dark and the operator can't use it - along with everyone else in the store (except for their Apps). When power is restored the device WiFi's into the web and gets the date and time and resumes operation.

Unless someone has some actual awful experience of Python/Raspbian losing more than 0.1 seconds in an hour I'm inclined to charge ahead with Python.

Like the Captain of the Titanic said, "Full steam ahead" - most of the time it worked just fine.....

thanks for the feedbback.

ghp
Posts: 1466
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 9:52 pm

Hello,

some time ago I did some investigation on how precise it is to measure short pulses of 10ms with python and compared this with a microcontroller. Most probably, these results can be interpreted 'the other way round' to estimate accuracy of pulse generation.
See chart in http://heppg.de/ikg/wordpress/?m=201503
The accuracy is -0.1+4.3 ms, which is awful for 10ms pulses, but a good indication for pulses of 1sec or more.

Regards,
Gerhard

MauiSunset
Posts: 27
Joined: Tue Jun 09, 2015 5:07 am

Re: Newbie to Raspberry Pi 2 and Python needs your advice

Fri Jun 12, 2015 10:39 pm

Thanks for the input.

I guess a test is in order - I should have thought of that.

Oh well, I'll be testing next week - thanks for the great idea.

Maui

Return to “Python”