When projects go terribly wrong · 2007-01-19 · Cute real-time effects from a webcam Feature...
Transcript of When projects go terribly wrong · 2007-01-19 · Cute real-time effects from a webcam Feature...
How to build a robot
When projects go terribly wrong
In the beginning
● Had been coasting for years with “ fronds”– Programmable blinkylights
● Got bored of hauling batteries around● So...
Build a robot!
● Of course● “ lurch” , a two-wheeled self-balancer● It started off well...
– Got some motors, encoders, accelerometer– Lots of left over microcontrollers– Plausible-looking design on paper
● Clearly at this point, before I had a wheel turning, I needed to look at navigation and AI
● Boring:– Ultrasonic– Line following– Contact switches
Not boring AI
● Vision!– How hard could it be?
● Lots of useful info from a camera● CPU power is cheap● Cool if it works● Start to hack...
Hacking away
● While hacking, Rachel comes back from lecture about Chinese astronomy
● Looks at test program:– “ hey, those look like constellations”
● Yeah, they do– and this year's BM theme is “ Vault of heaven”
● Tweak, tweak, hack, hack...● And then
And then...
● Fail to organize projector, generator, etc● Never gets exhibited● “ Sure this version is cool, but the next
version...”
Time passes
Oh by the way...
● “ I entered Constellation for Maker Faire”● Better make it work then
OK, so what is it?
● Cute real-time effects from a webcam
Feature tracker Lua Script
OpenGL
Feature Tracker
● Tracks N (50-200) features per frame● Looks for new interesting features● “ Interesting” means:
– well defined in 2 dimensions– High contrast
● Tracks feature for as long as it can● Loses feature if it
– goes away– changes shape
Scripting
● First version hard-coded C++● Cute, but inflexible
C++ = annoying
● Needed something better● Too many “ it would be neat if” ideas which
were too fiddley to implement● Solution: scripting language
Lua Scripting
● Intended to be easy & accessible● After all, programming is just typing● Allows lots of experiments in a short time● Useful script in about 30 lines:
require('bokstd')
t=tracker.new(100,120)
star = gfx.texture('blob.png')
-- Function to construct a new tracked feature pointfunction trackpoint(x, y, w) pt = { x=x, y=y } -- updated by tracker
-- drawing function function pt.draw(self) gfx.sprite(self, 5, star) end
-- We could also define "move" and "lost" functions here, if we -- care about those events.
return ptend
function features.add(self, idx, x, y, weight) self[idx] = trackpoint(x, y, weight)end
function process_frame(frame) --drawframe(frame)
t:track(features)
gfx:setstate({colour={1,1,0,1}, blend='alpha'}) features:foreach('draw')end
Fun things
● Do you smoke?
Mesh
● Things get interesting when you connect points
Constellatoins
● Mesh basis of constellations● When a star is
– Old enough– Big enough
● Becomes basis of constellation● Join adjacent stars on the mesh● Lines don't cross initially
– But might if the stars move
Explosions!
● When the feature behind a star gets lost● Star goes into nova (of course)● Lets people create and destroy large
numbers of stars– They seem to enjoy it
Something cute
● Your eyes/brain can pick out features with just the points– But only if they move
If your brain can do that...
● There are only ~100 points there● That's not much information● So if your brain can get stuff from that
– Shouldn't be too hard for a computer...● Hmm...
Future stuff
● Release source● More powerful trackers● Actual machine vision
– Maybe even build robot