Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Factory Automation with Python (Pycon 2017)

Factory Automation with Python (Pycon 2017)

Jonas Neubert

May 19, 2017
Tweet

More Decks by Jonas Neubert

Other Decks in Programming

Transcript

  1. SOFTWARE IS EATING THE DICTIONARY Oxford Dictionary of English, 3rd

    revised ed., Oxford University Press, 2010, p 626 Gamma, Helm, Johnson & Vlissides: “Design Patterns: Elements of Reusable Object- Oriented Software”, Addison-Wesley, 1995, p 99 factory (n.): A building or group of buildings where goods are manufactured or assembled chiefly by machine. W hat this talk is about factory (n.): An interface for creating families of related or dependent objects without specifying their concrete classes. What this talk is *not* about
  2. SOFTWARE IS EATING JOB TITLES, TOO International Society of Automation,

    isa.org Recruiters who fill my Linkedin Inbox without reading my profile first Automation Engineer (n.) Creates and applies technology to monitor and control the production and delivery of products and services. Automation Engineer (n.) Software engineer with special interest in testing and deploying code.
  3. CAUSING FACTORY DOWNTIME SINCE 2002 Jonas Neubert Software Engineer at

    Tempo Automation slides: http://jonasneubert.com/pycon2017 twitter: @jonemo
  4. class BarcodeReaderDriver: def __init__(self, port): self.port = serial.Serial( port, 9600,

    7, 'E', 1, 5) def read_barcode(self): self.port.write(b'*') line = self.port.readline() return line.strip().decode('ascii') def close(self): self.port.close() def __enter__(self): return self def __exit__(self, *args): self.close()
  5. Caveats Serial cable only works up to 15 meters (50

    feet) (That's 1.4% of the length of the Tesla Gigafactory 1) Your server doesn't have enough serial ports (Inspecting a single bottle for barcodes usually takes six)
  6. # server.py from xmlrpc.server import SimpleXMLRPCServer DEV = '/dev/cu.usbserial-AL01Z5WB' srv

    = SimpleXMLRPCServer(("localhost", 2121)) with BarcodeReaderDriver(DEV) as driver: srv.register_instance(driver) srv.serve_forever() # client.py from xmlrpc.client import ServerProxy cl = ServerProxy('http://localhost:2121') cl.read_barcode()
  7. SPOILER: IN THE NEXT DEMO WE'LL LAUNCH A DUCK! 1.

    Industrial automation equipment exists 2. (pure) Python works fine for interfacing with it 3. Python's “batteries” are useful in this domain, too 4. … and often result in more elegant and efficient solutions
  8. Industrial PC Usually a simple OS (this one is Windows

    CE) Real-time kernel Programmed with IEC-61131
  9. I/O Slices Library of slices for signal types — mix

    and match Examples: 5V Digital, 0-10V Analog, Relays, Motor Control, … Each signal binds to a variable!
  10. VAR_GLOBAL DO_CONVEYOR_ON AT %QX0.1: BOOL; DO_CONVEYOR_REVERSE AT %QX0.2: BOOL; END_VAR

    PROGRAM MAIN VAR CONVEYOR_ON: BOOL := FALSE; CONVEYOR_REVERSE: BOOL := TRUE; END_VAR IF CONVEYOR_ON <> DO_CONVEYOR_ON THEN DO_CONVEYOR_ON := CONVEYOR_ON; ELSIF CONVEYOR_REVERSE <> DO_CONVEYOR_REVERSE THEN DO_CONVEYOR_REVERSE := CONVEYOR_REVERSE; END_IF; Writable over Ethernet!
  11. Python implementations of the ADS Protocol (Automation Device Specification) Wrapper

    around vendor supplied C library — Python implementations of protocol pip install pyads github.com/chwiede/pyads github.com/counsyl/counsyl-pyads
  12. from counsyl_pyads import AdsConnection from counsyl_pyads import AdsClient from counsyl_pyads.adsdatatypes

    import * ads_conn = AdsConnection( target_ip='192.168.99.25', target_port=801, target_ams='5.10.208.214.1.1:801', source_ams='192.168.99.1.1.1:5555', ) plc = AdsClient(ads_conn) plc.write_by_name( 'MAIN.CONVEYOR_ON', BOOL, True)
  13. Python IEC-61131 (PLC) business logic connects to services user interface

    signal I/O human safety machine safety timing critical little to no downtime part of test suite requires downtime factory tests re-certification? regular release schedule don't touch this
  14. Start Noread? Read Barcode Yes Find Package Color Red or

    Blue? Left Paddle Right Paddle No Gum Color Database Blue Red
  15. ms3 = ServerProxy('http://localhost:2121') plc = AdsClient(ads_conn) plc.write_by_name( 'MAIN.CONVEYOR_ON', BOOL, True)

    while True: bc = ms3.read_barcode() col = upc_to_color(bc) if not col: time.sleep(0.25) elif col.r > col.b: time.sleep(1) plc.write_by_name( 'MAIN.LEFT_PADDLE', BOOL, True) else: time.sleep(1) plc.write_by_name( 'MAIN.RIGHT_PADDLE', BOOL, True)
  16. WANT TO GET STARTED? Device Drivers “APIs for robots” File

    Formats & Protocols parsers, converters, viewers, … Data Science & Machine Learning vibration monitoring, predictive maintenance, scheduling optimization, … Security you'll be busy…
  17. QUESTIONS http://jonasneubert.com/pycon2017 twitter: @jonemo packages mentioned pypi: pyserial pypi: microscan

    pypi: pyads github: chwiede/pyads github: counsyl/counsyl-pyads equipment used Barcode Reader: Microscan MS3 Coneyor: Dorner 1100 Series PLC: Beckhoff CX 1020