a raspberry pi hexy
TRANSCRIPT
Clean Code and Hexapod Robots
Prepared for National University Feb 12, 2016, DevCampus: Innovation For Excellence
Arcbotics Hexy- 19 DOF- open-source, 5mm acrylic- funded on kickstarter, 2012- 168k+ USD 860+ backers,- 250 USD, 1/10th usual cost
Hexy Modifications- motivations- hardware- software
What is robotics?Why is it so awesome?
Robotics is the study, and applications of robots.(duh)
Robots aregoal-oriented machines that sense, plan, and act in a continuous loop in effort to achieve their goal.
- Consistent - Strong- Reliable- Robust - Don’t get tired or lazy
Robots do things people:- Can't do (space, deep sea)- Won't do(boring, dull)- Shouldn't do (dangerous, unhealthy, risky)
What is clean code?Why is it so awesome?
"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
Bad code can function. Yearly, countless hours and significant resources are lost because of poorly written code.
Code is read at least 10x more than it is written.
“Don’t just do something. Stand there.” - The Art of Linux
Programming
- performs as expected- easy to understand and
consequently easy to reuse, modify, maintain or extend.
- contains everything that it needs and nothing that it doesn't.
- result of a coder who cares deeply about her craft.
Clean code is really hard :(- learn by reading about ideas of
veteran coders and their code- get better through writing more with
intention (experience)
Hexy Modifications- Metal Gear Servo - Pi Zero- Drive Servo via I2C- Code from scratch!
Raspberry Pi Zero - 1 Ghz Single Core Processor- 60 mm x 30 mm x 5mm- 5 USD only <3
Do all processing on board.No need for an external computer or bluetooth.
Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685
A Little Hexapod Robotics Theory
Kinematics Inverse-Kinematics
Joint Angles <-> Robot Position
GaitsLimb Movement
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
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
Clean Code in a Hexapod Robot….
Original Code: github.com/ArcBotics/PoMoCo
My Code (WIP): github.com/mithi/hexy
Some Guiding Principles to Clean Code...four things!
ONE Minimal DuplicationDRY. Refactor.
Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior.
Refactoring improves nonfunctional attributes of the software.
TWO EXPRESSIVEMeaningful, distinct, intention revealing names.
THREE SINGLE RESPONSIBILITY For classes & methods
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
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
With functions, we measure size by counting physical lines. With classes, responsibilities.
FOUR The best code is no code at all. less code == less bugs
A Few Examples.
Thank you for listening.