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 Slide

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

    View Slide

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

    View Slide

  4. An amazing science project
    Advanced Biology

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  8. You Get to Build Things
    Diabolical
    block towers

    View Slide

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

    View Slide

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

    View 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 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 Slide

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

    View Slide

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

    View Slide

  15. A thought:
    maybe I could make toys

    View Slide

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

    View Slide

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

    View 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 Slide

  19. Yes, this book

    View Slide

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

    View 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 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 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 Slide

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

    View 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 Slide

  26. DIY != Industrial

    View Slide

  27. Kit Arrival

    View Slide

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

    View Slide

  29. Assembly

    View Slide

  30. Assembly

    View Slide

  31. Assembly

    View Slide

  32. Assembly

    View Slide

  33. Assembly

    View Slide

  34. Assembly

    View Slide

  35. Assembly

    View Slide

  36. Assembly

    View Slide

  37. Assembly

    View Slide

  38. Assembly

    View Slide

  39. Assembly

    View Slide

  40. Assembly

    View Slide

  41. Assembly

    View Slide

  42. Assembly

    View Slide

  43. Assembly

    View Slide

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

    View Slide

  45. Hello World

    View Slide

  46. Practical First Job

    View Slide

  47. View Slide

  48. Lincoln Logs

    View Slide

  49. Wood Train & Fire Truck

    View Slide

  50. Ladder: For Fire Truck

    View Slide

  51. Detachable Wing

    View Slide

  52. Flying Wooden Train

    View Slide

  53. Flying Wooden Train with
    Hidden Pirate Treasure Chest

    View Slide

  54. Flying Wooden Train with
    Hidden Pirate Treasure Chest

    View Slide

  55. 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 Slide

  56. 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 Slide

  57. Or maybe...

    View Slide

  58. ... wait for it

    View Slide

  59. A miniature bike shed!

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  63. 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 Slide

  64. 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  69. Materials Science
    Wood HPDE Plastic
    Acrylic
    Machinable Wax

    View Slide

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

    View Slide

  71. 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 Slide

  72. 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 Slide

  73. 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 Slide

  74. Programming Errors
    They take
    physical form!

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  80. Demo : IPython Notebook

    View Slide

  81. Demo : IPython Notebook

    View Slide

  82. Demo : IPython Notebook

    View Slide

  83. Demo : IPython Notebook

    View Slide

  84. Milling

    View Slide

  85. Milling

    View Slide

  86. Milling

    View Slide

  87. Milling

    View Slide

  88. Milling

    View Slide

  89. Rough Cut

    View Slide

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

    View Slide

  91. User Testing

    View Slide

  92. Integration Testing

    View Slide

  93. Variation
    Ripple Track

    View Slide

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

    View Slide

  95. Future Direction?
    Printed Circuit Boards?

    View Slide

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

    View Slide

  97. 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 Slide

  98. 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 Slide

  99. 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 Slide

  100. 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 Slide

  101. 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 Slide

  102. 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 Slide