Python: A "Toy" Language

Python: A "Toy" Language

Presentation at PyCon 2013, Santa Clara. This talk was unreviewed and scheduled in place of a talk by Audrey Roy Greenfeld who was unable to attend at the last minute. Watch video at https://www.youtube.com/watch?v=BWyDA5y6TIg

70c42f4cf225f1455a7e01379bbd4d48?s=128

David Beazley

March 20, 2013
Tweet

Transcript

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

  2. Is this about toy problems? def fibonacci(n): if n <=

    2: return 1 else: return fibonacci(n-1) + fibonacci(n-2)
  3. No, let's talk about kids... (oh no...)

  4. An amazing science project Advanced Biology

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

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

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

    Learning ... and Chemistry A natural hacking instinct
  8. You Get to Build Things Diabolical block towers

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

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

    real birds)
  11. Hacker Pro-Tip Kids are the ultimate excuse for buying "tools"

    - Drill press - Telescope - Magnifying glass - Catapult - Oscilloscope - Soldering Iron - Laser - Welding torch
  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.
  13. Question: how do you get your kid to want to

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

    be a diabolical pirate scientist BDFL? ... in space.
  15. A thought: maybe I could make toys

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

  17. A thought: maybe I could make toys Python + Kids

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

    + Building Stuff == Fun (also good way to avoid working on book) with Python?
  19. Yes, this book

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

    Duh!
  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
  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
  23. DIY CNC Milling • ShapeOko Project • 1-man project (Edward

    Ford) • Chicago area • Super cheap $ So, shortly after last PyCon, this caught my eye...
  24. CNC Milling • Scary speed • Lot's of noise •

    Flying chips • Thrilling Danger! In a nutshell: Computer controlled whirling knives
  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...
  26. DIY != Industrial

  27. Kit Arrival

  28. Just to be clear... ... I have never done anything

    with CNC ever. (I'm a software geek, what could possibly go wrong?)
  29. Assembly

  30. Assembly

  31. Assembly

  32. Assembly

  33. Assembly

  34. Assembly

  35. Assembly

  36. Assembly

  37. Assembly

  38. Assembly

  39. Assembly

  40. Assembly

  41. Assembly

  42. Assembly

  43. Assembly

  44. Assembly Curse Words Uttered: CNC Mill - 0 Stroller -

    137 (Stroller cost more)
  45. Hello World

  46. Practical First Job

  47. None
  48. Lincoln Logs

  49. Wood Train & Fire Truck

  50. Ladder: For Fire Truck

  51. Detachable Wing

  52. Flying Wooden Train

  53. Flying Wooden Train with Hidden Pirate Treasure Chest

  54. Flying Wooden Train with Hidden Pirate Treasure Chest

  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."
  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"
  57. Or maybe...

  58. ... wait for it

  59. A miniature bike shed!

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

  61. Random Consequence... "Daddy, can you make something?" Actual meaning: Install

    a new iPad app. (I digress)
  62. Electronics/Tech Stepper Motors (3) Arduino w/ Grblshield Laptop (USB)

  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
  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)
  65. Whirling Knives You're in the physical world Plotting with 25000

    RPM end mill
  66. Physics • No instantaneous motion • Hardware limitations • Material

    properties (0,0) (50,10) (20,40) Accelerate Decelerate Accelerate Decelerate Accelerate Decelerate
  67. Geometry Restrictions cutter (can't cut exactly into vertices)

  68. It's Inexact There are real hardware "errors" • Wobble in

    rotary tools (runout) • Misalignment/centering issues
  69. Materials Science Wood HPDE Plastic Acrylic Machinable Wax

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

  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)
  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) ]
  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!
  74. Programming Errors They take physical form!

  75. Real Dangers Rotating Knives! • Drill through table • Jamming

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

    • Shattered End Mill • Harmonic vibration • Destruction A simple sign error can get interesting TDD?
  77. Solution? IPython Notebook? Is there anything it can't do? Why

    not CAM?
  78. Project: Marble Track Plot mathematical functions into curvy marble track

    f(x) = 30*sin(0.15*x)
  79. Project: Marble Track Track Cross-section Top View Track Path Normal

    vector f'(x)
  80. Demo : IPython Notebook

  81. Demo : IPython Notebook

  82. Demo : IPython Notebook

  83. Demo : IPython Notebook

  84. Milling

  85. Milling

  86. Milling

  87. Milling

  88. Milling

  89. Rough Cut

  90. Challenges • Exceptions are common • There's a "panic" button

    • Often stop/resume • Still working on software for it...
  91. User Testing

  92. Integration Testing

  93. Variation Ripple Track

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

  95. Future Direction? Printed Circuit Boards?

  96. Is There a Point? • CNC is a long-solved problem

    • CAD/CAM is long-solved • Why bother?
  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... Also $300
  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). Also $300
  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). Also $300 And nothing shouts out "fun" like a JCL script.
  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)
  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/
  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