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

Python: A "Toy" Language by David Beazley

Python: A "Toy" Language by David Beazley

Kids, CNC machines, toy making, and Python.

PyCon 2013

March 15, 2013
Tweet

More Decks by PyCon 2013

Other Decks in How-to & DIY

Transcript

  1. Python: A "Toy"
    Language
    David Beazley (@dabeaz)

    View full-size slide

  2. Is this about toy problems?
    def fibonacci(n):
    if n <= 2:
    return 1
    else:
    return fibonacci(n-1) + fibonacci(n-2)

    View full-size slide

  3. No, let's talk about kids...
    (oh no...)

    View full-size slide

  4. An amazing science project
    Advanced Biology

    View full-size slide

  5. An amazing science project
    Advanced Biology
    ... and Chemistry

    View full-size slide

  6. An amazing science project
    Advanced Biology
    ... and Chemistry
    Machine Learning

    View full-size slide

  7. An amazing science project
    Advanced Biology
    ... and Chemistry
    Machine Learning
    ... and Chemistry
    A natural hacking
    instinct

    View full-size slide

  8. You Get to Build Things
    Diabolical
    block towers

    View full-size slide

  9. You Get to Build Things
    A doghouse
    (for toy dog)

    View full-size slide

  10. You Get to Build Things
    Or maybe a
    birdhouse...
    (for real birds)

    View full-size slide

  11. Hacker Pro-Tip
    Kids are the ultimate excuse for buying "tools"
    - Drill press
    - Telescope
    - Magnifying glass
    - Catapult
    - Oscilloscope
    - Soldering Iron
    - Laser
    - Welding torch

    View full-size slide

  12. Hacker Pro-Tip
    Kids are the ultimate excuse for buying "tools"
    - Drill press
    - Telescope
    - Magnifying glass
    - Catapult
    - Oscilloscope
    - Soldering Iron
    - Laser
    - Welding torch
    You know, for kids. The big one. Yourself.

    View full-size slide

  13. Question:
    how do you get your kid to
    want to be a diabolical
    pirate scientist BDFL?

    View full-size slide

  14. Question:
    how do you get your kid to
    want to be a diabolical
    pirate scientist BDFL?
    ... in space.

    View full-size slide

  15. A thought:
    maybe I could make toys

    View full-size slide

  16. A thought:
    maybe I could make toys
    with Python?

    View full-size slide

  17. A thought:
    maybe I could make toys
    Python + Kids + Building Stuff == Fun
    with Python?

    View full-size slide

  18. A thought:
    maybe I could make toys
    Python + Kids + Building Stuff == Fun
    (also good way to avoid working on book)
    with Python?

    View full-size slide

  19. Yes, this book

    View full-size slide

  20. Seriously though...
    Writing Python programs to make toys...
    well, yeah. Duh!

    View full-size slide

  21. Making Things
    There's a bit of "maker"
    movement going on
    - 3D Printing
    - Hacker spaces
    - Arduino, Raspberry Pi
    - DIY
    It's been on my mind
    - "Oh, that might be cool"
    However, I've never been that actively involved

    View full-size slide

  22. Issue
    Drawing and clicking "print" is a big "meh."
    3D printing seems just a bit too magical
    If machine breaks, could I figure out how to fix it?
    More enjoyment from figuring out how to do
    something than actually doing it

    View full-size slide

  23. DIY CNC Milling
    • ShapeOko Project
    • 1-man project
    (Edward Ford)
    • Chicago area
    • Super cheap $
    So, shortly after last PyCon, this caught my eye...

    View full-size slide

  24. CNC Milling
    • Scary speed
    • Lot's of noise
    • Flying chips
    • Thrilling Danger!
    In a nutshell: Computer controlled whirling knives

    View full-size slide

  25. CNC Milling
    • Scary speed
    • Lot's of noise
    • Flying chips
    • Thrilling Danger!
    In a nutshell: Computer controlled whirling knives
    It sounded perfect! You know, for kids...

    View full-size slide

  26. DIY != Industrial

    View full-size slide

  27. Just to be clear...
    ... I have never done
    anything with CNC ever.
    (I'm a software geek, what
    could possibly go wrong?)

    View full-size slide

  28. Assembly
    Curse Words Uttered:
    CNC Mill - 0
    Stroller - 137
    (Stroller cost more)

    View full-size slide

  29. Practical First Job

    View full-size slide

  30. Lincoln Logs

    View full-size slide

  31. Wood Train & Fire Truck

    View full-size slide

  32. Ladder: For Fire Truck

    View full-size slide

  33. Detachable Wing

    View full-size slide

  34. Flying Wooden Train

    View full-size slide

  35. Flying Wooden Train with
    Hidden Pirate Treasure Chest

    View full-size slide

  36. Flying Wooden Train with
    Hidden Pirate Treasure Chest

    View full-size slide

  37. Flying Wooden Train with
    Hidden Pirate Treasure Chest
    "Kid, if this doesn't stop, I'm going to start making you
    write a requirements doc."

    View full-size slide

  38. Flying Wooden Train with
    Hidden Pirate Treasure Chest
    "Kid, if this doesn't stop, I'm going to start making you
    write a requirements doc--in Docbook XML"

    View full-size slide

  39. ... wait for it

    View full-size slide

  40. A miniature bike shed!

    View full-size slide

  41. Random Consequence...
    "Daddy, can you make something?"

    View full-size slide

  42. Random Consequence...
    "Daddy, can you make something?"
    Actual meaning: Install a new iPad app.
    (I digress)

    View full-size slide

  43. Electronics/Tech
    Stepper
    Motors (3)
    Arduino w/
    Grblshield
    Laptop
    (USB)

    View full-size slide

  44. Software
    import serial
    ser = serial.Serial(
    '/dev/tty.usbmodem641', 9600)
    def command(cmd):
    ser.send(cmd.encode('ascii')+b'\n')
    resp = ser.readline()
    if resp != b'Ok\n':
    raise RuntimeError(resp)
    It's just serial ports... use pyserial
    Simple command/response protocol

    View full-size slide

  45. GCode
    G1 Z10
    G1 X0 Y0
    G1 Z-2
    G1 X50 Y10
    G1 X20 Y40
    G1 X0 Y0
    G1 Z0
    Movement controlled by simple commands
    It's a lot like plotting/turtle graphics
    (0,0)
    (50,10)
    (20,40)

    View full-size slide

  46. Whirling Knives
    You're in the physical world
    Plotting with 25000 RPM end mill

    View full-size slide

  47. Physics
    • No instantaneous motion
    • Hardware limitations
    • Material properties
    (0,0)
    (50,10)
    (20,40)
    Accelerate
    Decelerate
    Accelerate
    Decelerate
    Accelerate
    Decelerate

    View full-size slide

  48. Geometry Restrictions
    cutter
    (can't cut exactly into vertices)

    View full-size slide

  49. It's Inexact
    There are real hardware "errors"
    • Wobble in rotary tools (runout)
    • Misalignment/centering issues

    View full-size slide

  50. Materials Science
    Wood HPDE Plastic
    Acrylic
    Machinable Wax

    View full-size slide

  51. A Science Experiment?
    Feed rates, rotational speed, cut depth, etc.

    View full-size slide

  52. CAM Software
    Maybe there's a reason why there's a whole
    industry of expensive "Computer Aided
    Manufacturing" Software
    Of course, there's a
    free Python one
    too...
    (I have not used it)

    View full-size slide

  53. DIY CAM
    CNC is "simple" enough to write scripts
    part = [
    (0, 0),
    (0, 44.175),
    (23.175, 44.175),
    (23.175, 37.175),
    (60, 37.175),
    (60, 44.175),
    (83.175, 44.175),
    (83.175, 0),
    (0,0)
    ]

    View full-size slide

  54. DIY CAM
    Direct streaming of GCode
    command('F1000')
    for z in range(1,10):
    command('G1 Z-%s' % z)
    for x, y in part:
    command('G1 X%s Y%s' % (x,y))
    command('G1 Z0')
    You'll see those whirling knives moving around!

    View full-size slide

  55. Programming Errors
    They take
    physical form!

    View full-size slide

  56. Real Dangers
    Rotating Knives!
    • Drill through table
    • Jamming
    • Shattered End Mill
    • Harmonic vibration
    • Destruction
    A simple sign error can get interesting

    View full-size slide

  57. Real Dangers
    Rotating Knives!
    • Drill through table
    • Jamming
    • Shattered End Mill
    • Harmonic vibration
    • Destruction
    A simple sign error can get interesting TDD?

    View full-size slide

  58. Solution?
    IPython Notebook?
    Is there anything it
    can't do?
    Why not CAM?

    View full-size slide

  59. Project: Marble Track
    Plot mathematical functions into curvy
    marble track
    f(x) = 30*sin(0.15*x)

    View full-size slide

  60. Project: Marble Track
    Track Cross-section
    Top View
    Track Path
    Normal
    vector
    f'(x)

    View full-size slide

  61. Demo : IPython Notebook

    View full-size slide

  62. Demo : IPython Notebook

    View full-size slide

  63. Demo : IPython Notebook

    View full-size slide

  64. Demo : IPython Notebook

    View full-size slide

  65. Challenges
    • Exceptions are common
    • There's a "panic" button
    • Often stop/resume
    • Still working on
    software for it...

    View full-size slide

  66. User Testing

    View full-size slide

  67. Integration Testing

    View full-size slide

  68. Variation
    Ripple Track

    View full-size slide

  69. Future Direction?
    Resin Casting
    (Photos: Guerilla Guide to CNC)

    View full-size slide

  70. Future Direction?
    Printed Circuit Boards?

    View full-size slide

  71. Is There a Point?
    • CNC is a long-solved problem
    • CAD/CAM is long-solved
    • Why bother?

    View full-size slide

  72. Is There a Point?
    • CNC is a long-solved problem
    • CAD/CAM is long-solved
    • Why bother?
    Answer: It's every bit as fun as my first computer...

    View full-size slide

  73. Is There a Point?
    • CNC is a long-solved problem
    • CAD/CAM is long-solved
    • Why bother?
    Answer: It's every bit as fun as my first computer...
    (and in 1978, programming was a solved problem).

    View full-size slide

  74. Is There a Point?
    • CNC is a long-solved problem
    • CAD/CAM is long-solved
    • Why bother?
    Answer: It's every bit as fun as my first computer...
    (and in 1978, programming was a solved problem).
    And nothing shouts out "fun" like a JCL script.

    View full-size slide

  75. It's Supposed To Be Fun
    Why did you start using Python?
    ... it's okay to admit it. It was probably because it was fun.
    (if it's not fun, you're not doing it right)

    View full-size slide

  76. Bigger Point?
    "Every child is an artist. The problem is how
    to remain an artist when we grow up."
    - Pablo Picasso
    s/artist/hacker/

    View full-size slide

  77. Final Comments
    • You can do this!
    • ShapeOko (http:/
    /www.shapeoko.com)
    • Guerrilla Guide to CNC
    (http:/
    /lcamtuf.coredump.cx/gcnc/)
    • Thanks!
    • Follow at @dabeaz

    View full-size slide