Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

An amazing science project Advanced Biology

Slide 5

Slide 5 text

An amazing science project Advanced Biology ... and Chemistry

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

You Get to Build Things Diabolical block towers

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

A thought: maybe I could make toys

Slide 16

Slide 16 text

A thought: maybe I could make toys with Python?

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Yes, this book

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

DIY != Industrial

Slide 27

Slide 27 text

Kit Arrival

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Assembly

Slide 30

Slide 30 text

Assembly

Slide 31

Slide 31 text

Assembly

Slide 32

Slide 32 text

Assembly

Slide 33

Slide 33 text

Assembly

Slide 34

Slide 34 text

Assembly

Slide 35

Slide 35 text

Assembly

Slide 36

Slide 36 text

Assembly

Slide 37

Slide 37 text

Assembly

Slide 38

Slide 38 text

Assembly

Slide 39

Slide 39 text

Assembly

Slide 40

Slide 40 text

Assembly

Slide 41

Slide 41 text

Assembly

Slide 42

Slide 42 text

Assembly

Slide 43

Slide 43 text

Assembly

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

Hello World

Slide 46

Slide 46 text

Practical First Job

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Lincoln Logs

Slide 49

Slide 49 text

Wood Train & Fire Truck

Slide 50

Slide 50 text

Ladder: For Fire Truck

Slide 51

Slide 51 text

Detachable Wing

Slide 52

Slide 52 text

Flying Wooden Train

Slide 53

Slide 53 text

Flying Wooden Train with Hidden Pirate Treasure Chest

Slide 54

Slide 54 text

Flying Wooden Train with Hidden Pirate Treasure Chest

Slide 55

Slide 55 text

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."

Slide 56

Slide 56 text

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"

Slide 57

Slide 57 text

Or maybe...

Slide 58

Slide 58 text

... wait for it

Slide 59

Slide 59 text

A miniature bike shed!

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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)

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

Materials Science Wood HPDE Plastic Acrylic Machinable Wax

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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)

Slide 72

Slide 72 text

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) ]

Slide 73

Slide 73 text

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!

Slide 74

Slide 74 text

Programming Errors They take physical form!

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

Demo : IPython Notebook

Slide 81

Slide 81 text

Demo : IPython Notebook

Slide 82

Slide 82 text

Demo : IPython Notebook

Slide 83

Slide 83 text

Demo : IPython Notebook

Slide 84

Slide 84 text

Milling

Slide 85

Slide 85 text

Milling

Slide 86

Slide 86 text

Milling

Slide 87

Slide 87 text

Milling

Slide 88

Slide 88 text

Milling

Slide 89

Slide 89 text

Rough Cut

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

User Testing

Slide 92

Slide 92 text

Integration Testing

Slide 93

Slide 93 text

Variation Ripple Track

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

Future Direction? Printed Circuit Boards?

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

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.

Slide 100

Slide 100 text

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)

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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