Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Perl Code To Control Industrial Applications?

by jdlev (Scribe)
on Feb 11, 2014 at 07:43 UTC ( #1074359=perlquestion: print w/ replies, xml ) Need Help??
jdlev has asked for the wisdom of the Perl Monks concerning the following question:

I have a home brewery I'd like to tinker with, and I'd like to build various process controls into my brew system. I'd like to be able to monitor temperatures, turn heating elements on and off, run timers, control systems remotely (well, inside my house), set alarms, and more. Can perl do this? If perl can't handle this, what type of coding would I be looking at to handle industrial applications?

Next, what is the piece of equipment that would I would connect thinks like my temperature probes, etc, to. There will naturally be some hard wiring utilized for things like a control box with switches to turn on the elements etc, but what piece of hardware would I need to connect to monitor my brewhouse and control the different elements in my brew house? Thanks, Jeff

I love it when a program comes together - jdhannibal

Comment on Perl Code To Control Industrial Applications?
Re: Perl Code To Control Industrial Applications? (vendor)
by Anonymous Monk on Feb 11, 2014 at 07:55 UTC

    You need to ask your "hardware vendor" :)

    Then grab whatever you need, probably one of WWW::Mechanize(LWP) or Inline::C/Inline::CPP/XSpp, and you're off and running

    If your vendor is really antique (and not forward thinking) you'll be stuck with something serialport which is EEW :)

    MisterHouse -- It Knows Kung-Fu

Re: Perl Code To Control Industrial Applications?
by Discipulus (Curate) on Feb 11, 2014 at 08:10 UTC
    i think Arduino is the only thing close to your needs. Really Perl and others can do coffee but a beer plant seems a bit exhagered.

    Unfortunately Arduino does not (yet ?) speaks Perl but an over-semplified-version-of-C so maybe this is not the rigth place.

    In any case if you develop Serial::Beer::Plant please share with us!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      In any case if you develop Serial::Beer::Plant please share with us!
      I am more interested in Serial::Beer::Tasting.

      --MidLifeXis

Re: Perl Code To Control Industrial Applications?
by karlgoethebier (Curate) on Feb 11, 2014 at 08:16 UTC
Re: Perl Code To Control Industrial Applications?
by wjw (Deacon) on Feb 11, 2014 at 09:04 UTC
    Under normal circumstances, you would be looking at using a small PLC for automation like this. Maybe a Raspberry PI, or a PIC controller.Your programming would be in what is called ladder logic in the case of the PLC.

    However, there are a number of projects out there from which you can get a good start using your Perl skills and some relatively inexpensive hardware.

    You may find some interesting inspiration here

    I have used a perl program which monitors the USB or RS232 output of my Radio Shack DMM to store temperature, voltage, resistance values, etc, retrieved over a long period of time in a text file.

    The following link points to a system for home automation written in perl which I suspect would work well for basic process monitoring and control. See it here

    Hope that is helpful... Update::Addendum; I don't know how much automation experience you have, but just a note: You will want to use a PLC or similar control hardware if you need real-time process control! Anything safety related should not be controlled via a non-real-time device. For a home brew system, you should be ok with the stuff pointed out above unless you are controlling things like gas valves or the like. Sorry if you already know this, but I would feel pretty negligent not pointing this out if you were un-aware of the issues involved.

    ...the majority is always wrong, and always the last to know about it...
    Insanity: Doing the same thing over and over again and expecting different results.
Re: Perl Code To Control Industrial Applications?
by mje (Deacon) on Feb 11, 2014 at 09:15 UTC

    There are 2 obvious choices.

    Use an Arduino and Perl. Unfortunately, arduino's need to be programmed in C but then you can talk to them from Perl. So you put the interface to you hardware sensors, relays etc in the Arduino and then you can read and control them from Perl using the usb/serial port or something like HTTP if you add a network card to your arduino. I've done a little of this in the past - see monitoring our machine room temperature with nagios, perl and arduino and Version 2 electricty meter power logging

    The second choice is a raspberry pi. Interfacing it to the electronics is slightly harder but there is a Perl module to talk directly to the gpio on the pi. So this would be an all Perl solution.

    An arduino (something like an AT Mega) will cost you around £20 and a pi around £25 so little difference there. The arduino will need C code writing so if you want a Perl only solution it will have to be the pi. The pi also has the advantage that it already has networking although this can easily be added to an arduino.

    The raspberry pi is really a small computer which has HDMI out so you can connect it to a monitor and usb to connect a keyboard and mouse. People usually install a version of Linux. It will need a power supply and it is really a bit short on memory to run an operating system - I even had problems running out of memory installing CPAN modules at first (see Raspberry Pi - will it get our children programming? and if so why not in Perl?). The arduino on the other hand can be powered off the usb port or a small battery and has loads of options to cut power usage to run for longer times on a battery.

    Simple temperature probes will be fairly easy. Turning on/off heating elements will be harder as you have to isolate them from the controller. You're going to need some electronics knowledge.

Re: Perl Code To Control Industrial Applications?
by zentara (Archbishop) on Feb 11, 2014 at 11:42 UTC
    If I was to setup something like this from scratch, meaning not using other people's kits or whatever; and if you really want to keep computer control in a central location, like a laptop; I would look to get a USB breadboard

    Then once you have the idea of how to read/write to it, you can get going. It probably does the same thing the old parallel printer port interfaces did, just write values in C, to a specific memory address. I'm sure Perl can do that.

    Then, make up your control interface using something like Tk, SDL, Wx, Gtk3, or whatever Perl GUI you like.

    Here for example is a simple dial guage which you can either use to set temperature, or read it's current value.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $gray50_width = 2; my $gray50_height = 2; my $gray50_bits = pack "CC", 0x02, 0x01; $mw->DefineBitmap('mask' => 2,2, $gray50_bits); $mw->fontCreate('medium', -family=>'courier', -weight=>'bold', -size=>int(-14*14/10)); my $c = $mw->Canvas( -width => 200, -height => 200, -bd => 2, -relief => 'sunken', -background => 'black', )->pack; $c->createLine(100,100,10,100, -tags => ['needle'], -arrow => 'last', -width => 5, -fill => 'hotpink', ); my $gauge = $c->createOval( 10,10, 190,190, -fill=> 'lightblue', -outline => 'skyblue', -width => 5, -tags => ['gauge'], -stipple => 'mask', ); my $hub = $c->createOval( 90,90, 110,110, -fill => 'lightgreen', -outline => 'seagreen', -width => 2, -tags => ['hub'], ); $mw->bind('<B1-Motion>' => sub{ my $ev = $c->XEvent; &update_meter($ev->x,$ev->y); }); my $text = $c->createText( 100,50, -text => 180, -font => 'medium', -fill => 'yellow', -anchor => 's', -tags => ['text'] ); $c->raise('needle','text'); $c->raise('hub','needle'); MainLoop; sub update_meter { my($x,$y) = @_; # transform coords center to 100,100 $x = $x - 100; $y = 100 - $y; my $cos = $x/($x**2 + $y**2)**(.5); my $sin = $y/($x**2 + $y**2)**(.5); my $x1 = 100.0 + 90.0 * $cos; my $y1 = 100.0 - 90.0 * $sin; $c->coords('needle', 100,100, $x1, $y1); #see perldoc -f cos my $angle = sprintf('%.2d', 180 / 3.1416 * atan2( sqrt(1 - $cos * $ +cos), $cos )); if( $y < 0){ $angle = 359 - $angle } $c->itemconfigure($text,-text => $angle); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl Code To Control Industrial Applications?
by Your Mother (Canon) on Feb 11, 2014 at 16:52 UTC
Re: Perl Code To Control Industrial Applications?
by bulk88 (Priest) on Feb 12, 2014 at 00:22 UTC


    I have a home brewery I'd like to tinker with, and I'd like to build various process controls into my brew system. I'd like to be able to monitor temperatures, turn heating elements on and off, run timers, control systems remotely (well, inside my house), set alarms, and more. Can perl do this? If perl can't handle this, what type of coding would I be looking at to handle industrial applications?

    Next, what is the piece of equipment that would I would connect thinks like my temperature probes, etc, to. There will naturally be some hard wiring utilized for things like a control box with switches to turn on the elements etc, but what piece of hardware would I need to connect to monitor my brewhouse and control the different elements in my brew house? Thanks,

    Jeff
    I would NOT use Perl in a industrial safety/property damage situation. First of all, you need an event loop. Signals are unreliable and filled with race conditions. What will happen if you have a kernel panic that leaves a heater relay energized because the pin controlling the relay is stuck on? If you use solenoids for fluid transfer, what happens when it is electrically stuck open? Pressure safety limit systems need to be mechanical and generally accepted industrial/commercial parts with a traceable manufacturer to sue if your 100 PSI safety valve doesnt open until 900 PSI and your tank burst at 800 PSI and now the FBI is investigating WTF you were doing. Think McMaster or Grainger.

    What happens when a heater is stuck on, pressure valve opens and all water is boiled out dry over a number of hours, the tanks and pipes and frame of the tank reach 100s of degrees, will your wood or vinyl floor ignite from the heat of the frame legs touching the floor?

    Since you are brewing, now in some cases you have flammable alcohol vapor in the air if there is an accident.

    To learn what happens when your fluid, heat, and pressure machines have failures, watch a couple video reports from http://www.youtube.com/user/USCSB/videos. Some of the case reports involve software or rely on a "light switch on the wall controls the burner and remembering to turn it off for the night". Also read http://en.wikipedia.org/wiki/Therac_25 to learn what happens when you write your own event loop for a life safety system and have no idea what you are doing.

    I've researched using Perl for novelty robot toys many years ago, I didn't find anything that didn't ship as a closed source C library from the IO board's mfg (National Instruments). So no Perl interface.

    Regarding Arduino, I am not sure I trust it for anything but toys. With one of its predecessors I worked hands on with, which was toy/educational rated, the boards froze during uploaded or during operation, especially when there was a input problem and the operator jiggled the control joystick (event loop got into an impossible state I believe) and had the board/machine had to be power cycled for to respond for input again. What happens when short circuit happens on another circuit in the building and the lights dip? or an induction motor starts up or stalls? Relays have this problem which can fry controls http://en.wikipedia.org/wiki/Flyback_diode. What if you have a winter coat that generates crazy amounts of static, and you take the coat off then touch or get near a wire that leads to an IO pin?

    I have such a problem. If I touch the plastic of my laptop, I usually hear a zap as it dischages. Laptop is fine, since I'm pretty sure the plastic case is slightly conductive and the laptop was zapped repeatedly in a lab to make sure you can't kill it in the field (but they position the electrodes only where the industry standard document says, not paying attention to the most vulnerable locations). If I touch the serial port on the back and the spark hits the serial port, laptop freezes (with audio stuttering in a loop if it was playing music) until a power cycle. Those are the kinds of things you need worry about.

    In CS, when you fail, just hit the reset button, say we lost the data, and make a twitter post saying tough luck customers goto lunch and come back and it should be up by then. In ME/hard engineering, when you fail, you have lawsuits, clipboards holding PHBs, and badges with or without guns showing up looking for blood.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1074359]
Approved by stefbv
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-09-17 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (56 votes), past polls