a raspberry pi hexy

77
Clean Code and Hexapod Robots Prepared for National University Feb 12, 2016, DevCampus: Innovation For Excellence

Upload: mithi-sevilla

Post on 22-Jan-2017

337 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: A raspberry pi hexy

Clean Code and Hexapod Robots

Prepared for National University Feb 12, 2016, DevCampus: Innovation For Excellence

Page 2: A raspberry pi hexy
Page 3: A raspberry pi hexy
Page 4: A raspberry pi hexy

Arcbotics Hexy- 19 DOF- open-source, 5mm acrylic- funded on kickstarter, 2012- 168k+ USD 860+ backers,- 250 USD, 1/10th usual cost

Page 5: A raspberry pi hexy
Page 6: A raspberry pi hexy

Hexy Modifications- motivations- hardware- software

Page 7: A raspberry pi hexy

What is robotics?Why is it so awesome?

Page 8: A raspberry pi hexy

Robotics is the study, and applications of robots.(duh)

Page 9: A raspberry pi hexy
Page 10: A raspberry pi hexy
Page 11: A raspberry pi hexy
Page 12: A raspberry pi hexy
Page 13: A raspberry pi hexy

Robots aregoal-oriented machines that sense, plan, and act in a continuous loop in effort to achieve their goal.

Page 14: A raspberry pi hexy

- Consistent - Strong- Reliable- Robust - Don’t get tired or lazy

Page 15: A raspberry pi hexy

Robots do things people:- Can't do (space, deep sea)- Won't do(boring, dull)- Shouldn't do (dangerous, unhealthy, risky)

Page 16: A raspberry pi hexy

What is clean code?Why is it so awesome?

Page 17: A raspberry pi hexy

"Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought about by the code's author and if you try to imagine improvements, you are led back to where you are sitting in appreciation of the code someone left for you, code left by someone who cares deeply about the craft" - Michael Feathers, Working Effectively with Legacy Code

Page 18: A raspberry pi hexy
Page 19: A raspberry pi hexy
Page 20: A raspberry pi hexy

Bad code can function. Yearly, countless hours and significant resources are lost because of poorly written code.

Page 21: A raspberry pi hexy

Code is read at least 10x more than it is written.

Page 22: A raspberry pi hexy

“Don’t just do something. Stand there.” - The Art of Linux

Programming

Page 23: A raspberry pi hexy

- performs as expected- easy to understand and

consequently easy to reuse, modify, maintain or extend.

Page 24: A raspberry pi hexy

- contains everything that it needs and nothing that it doesn't.

Page 25: A raspberry pi hexy

- result of a coder who cares deeply about her craft.

Page 26: A raspberry pi hexy

Clean code is really hard :(- learn by reading about ideas of

veteran coders and their code- get better through writing more with

intention (experience)

Page 27: A raspberry pi hexy
Page 28: A raspberry pi hexy

Hexy Modifications- Metal Gear Servo - Pi Zero- Drive Servo via I2C- Code from scratch!

Page 29: A raspberry pi hexy
Page 30: A raspberry pi hexy
Page 31: A raspberry pi hexy
Page 32: A raspberry pi hexy
Page 33: A raspberry pi hexy
Page 34: A raspberry pi hexy
Page 35: A raspberry pi hexy

Raspberry Pi Zero - 1 Ghz Single Core Processor- 60 mm x 30 mm x 5mm- 5 USD only <3

Page 36: A raspberry pi hexy

Do all processing on board.No need for an external computer or bluetooth.

Page 37: A raspberry pi hexy
Page 38: A raspberry pi hexy
Page 39: A raspberry pi hexy
Page 40: A raspberry pi hexy

Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685

Page 41: A raspberry pi hexy
Page 42: A raspberry pi hexy
Page 43: A raspberry pi hexy
Page 44: A raspberry pi hexy

A Little Hexapod Robotics Theory

Page 45: A raspberry pi hexy

Kinematics Inverse-Kinematics

Page 46: A raspberry pi hexy
Page 47: A raspberry pi hexy

Joint Angles <-> Robot Position

Page 48: A raspberry pi hexy
Page 49: A raspberry pi hexy
Page 50: A raspberry pi hexy

GaitsLimb Movement

Page 51: A raspberry pi hexy
Page 52: A raspberry pi hexy
Page 53: A raspberry pi hexy

Stance Phase | Power Stroke- leg is on the ground where it supports and

propels the body. - leg retracts or moves towards the rear of

the body

Page 54: A raspberry pi hexy

Swing Phase | Return Stroke- leg lifts and swings to the starting position

of the next stance phase- leg protracts or moves towards the front of

the body

Page 55: A raspberry pi hexy

Clean Code in a Hexapod Robot….

Page 56: A raspberry pi hexy

Original Code: github.com/ArcBotics/PoMoCo

My Code (WIP): github.com/mithi/hexy

Page 57: A raspberry pi hexy

Some Guiding Principles to Clean Code...four things!

Page 58: A raspberry pi hexy

ONE Minimal DuplicationDRY. Refactor.

Page 59: A raspberry pi hexy

Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior.

Page 60: A raspberry pi hexy

Refactoring improves nonfunctional attributes of the software.

Page 61: A raspberry pi hexy

TWO EXPRESSIVEMeaningful, distinct, intention revealing names.

Page 62: A raspberry pi hexy

THREE SINGLE RESPONSIBILITY For classes & methods

Page 63: A raspberry pi hexy

The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.

usually verbs

Page 64: A raspberry pi hexy

The first rule of classes is that they should be small. The second rule of classes is that they should be smaller than that.

usually nouns

Page 65: A raspberry pi hexy

With functions, we measure size by counting physical lines. With classes, responsibilities.

Page 66: A raspberry pi hexy

FOUR The best code is no code at all. less code == less bugs

Page 67: A raspberry pi hexy

A Few Examples.

Page 68: A raspberry pi hexy
Page 69: A raspberry pi hexy
Page 70: A raspberry pi hexy
Page 71: A raspberry pi hexy
Page 72: A raspberry pi hexy
Page 73: A raspberry pi hexy
Page 74: A raspberry pi hexy
Page 75: A raspberry pi hexy
Page 76: A raspberry pi hexy
Page 77: A raspberry pi hexy

Thank you for listening.