Factory Automation with Python (Pycon 2017)

Factory Automation with Python (Pycon 2017)

F932a58935f19875076d7b2232a20fd3?s=128

Jonas Neubert

May 19, 2017
Tweet

Transcript

  1. FACTORY AUTOMATION WITH PYTHON STORIES ABOUT ROBOTS, SERIAL PORTS, AND

    BARCODE READERS Jonas Neubert
  2. 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
  3. 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.
  4. CAUSING FACTORY DOWNTIME SINCE 2002 Jonas Neubert Software Engineer at

    Tempo Automation slides: http://jonasneubert.com/pycon2017 twitter: @jonemo
  5. None
  6. Conveyor Belt

  7. Barcode Reader

  8. Pusher Paddles

  9. Pusher Paddles

  10. Pusher Paddles

  11. Pusher Paddles

  12. Pusher Paddles

  13. Sensing + Actuation + Brains ========== Automation

  14. None
  15. Laser (photons) RS­232 (electrons)

  16. 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()
  17. Awesome! An instrument driver in under 15 lines of Python.

  18. 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)
  19. # 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()
  20. 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
  21. Sensing + Actuation + Brains ========== Automation

  22. “API Docs”

  23. PROGRAMMABLE LOGIC CONTROLLER (PLC)

  24. Industrial PC Usually a simple OS (this one is Windows

    CE) Real-time kernel Programmed with IEC-61131
  25. 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!
  26. 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!
  27. 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
  28. 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)
  29. 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
  30. Sensing + Actuation + Brains ========== Automation

  31. Start Noread? Read Barcode Yes Find Package Color Red or

    Blue? Left Paddle Right Paddle No Gum Color Database Blue Red
  32. 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)
  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. 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…
  45. 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