More than Just Lines on a Map: Best Practices for U.S Bike Routes
Â
Scaling into Meatspace: A JavaScript engineer's persepctive
1.
2. Solving the robot problem
⢠I want to build a robot
⢠I love coding
⢠I want pro gear
â servos
â motors
â accelerometers
â GPS
â etc
⢠I want it on the web
⢠I want it now
3. So, this robotâŚ
⢠has physical devices that attach simply
⢠is running a software framework that
â talks to those physical devices
â exposes their properties to the web
â responds to user input from the web in as close to
real time as possible
â can express a degree of autonomy
â is fast to develop in
4. But isnât JavaScript a terrible language
to build robots with?
⢠JavaScript has bad timers
⢠Very slow and memory inefficient compared
to close-to-the-metal languages like C/C++
⢠All the C/Java guys I know are like, "What the
hell are you doing? Are you crazy?"
5. Those guys donât know everything
⢠We have modern, low wattage RISC based ARM
processors
⢠We have modern interpreters (i.e. V8) that are
very good at optimising our code at run time
⢠Writing device drivers in C/C++ is a total chore for
most people
⢠We can buy off the shelf components that can do
our time critical
⢠Itâs not the 90s!
6. What do we gain by using JavaScript?
⢠It makes a lot of high level tasks very easy
⢠These days it can do way cool stuff
⢠Big community FTW
8. What currently exists for JS robotics?
⢠The original talk:
http://www.slideshare.net/nonken/robotic-javascript
⢠Nodecopter (nodecopter.com)
⢠Nodeserial (@voodootikigod)
⢠Firmata (Julian Gautier)
⢠Johnny 5 (Rick Waldron)
9. What do they do for us?
⢠Nodecopter helps us talk to a proprietary
helicopter drone
⢠Nodeserial helps us talk to the serial port
⢠Firmata helps us talk with an Arduino
⢠Johnny5 helps us control that Arduino with JS
11. Whatâs the ideal architecture?
⢠We want a familiar interface
⢠Web pages are good
⢠Something REST-like would be ideal
⢠Express helps
⢠BackboneIO (Backbone over WebSockets)
⢠State machine representation of physical devices
⢠Adding a new physical device should be as simple
as plugging it in
12. Whatâs the ideal architecture?
⢠Model-Collection-Controller/Model-View-
Collection
⢠Discrete physical devices are represented as
discrete models in memory on server
⢠Models bound to device change events
⢠Controllers talk to client via WebSockets
⢠Robot's canonical state kept on server, allows
autonomous behaviour
13. Step up Raspberry Pi
⢠Modern ARM based SOC
⢠Low power
⢠Runs Linux
⢠Loads of storage space
⢠USB 2.0
⢠Bonus onboard graphics processor
14. Add some clever USB devices
⢠Wifi
⢠Pololu
â serial comms using serialport
⢠Phidget
â http/serial bridge using phigetapi
15. Add Node.JS and the SPD framework
⢠Listens on local TCP/IP network
⢠Serves up dynamic web pages
⢠Uses Backbone API
⢠Automagically builds models on client
⢠Changes in remote hardware bound directly to
client-side events
⢠Looks to all the world exactly like a web site
⢠We donât even have to care about transport
17. Give me that checklist
⢠Itâs got servos
⢠Itâs got motors
⢠Itâs got GPS
⢠Itâs got accelerometers
⢠Itâs got Arduino (should you really need non-USB based
sensor arrays)
⢠It communicates with the web in real time
Itâs going to get a lot more
⢠Real time streaming HD video
⢠Kinect vision
⢠Firmata?
18. Enough talk
⢠Drive the car around the stage
⢠Get my Google Map on
⢠Detect a crash
⢠Damn
19. Notes
Bibliography Shout outs
⢠Available on request ⢠jashkenas
⢠voodootikigod
⢠RIAEvangelist
⢠visionmedia
I want to build a robotbut I hate solderingI love codingbut I hate the pain of embedded languagesI want pro gear: servos, motors, accelerometers, GPS, etc.but I donât want to have to care about TTL, parity checks, serial cables or baud ratesI want it on the webI want it nowtomorrow is acceptable
JavaScript has bad timersincapable of generating high precision line signals for GPIO devicesVery slow and memory inefficient compared to close-to-the-metal languages like C/C++youâd never write a device driver in itprobably sucks for battery lifeAll the C/Java guys I know are like, "What the hell are you doing? Are you crazy?"
We have modern, low wattage RISC based ARM processorsWe have modern interpreters (i.e. V8) that are very good at optimising our code at run timeWriting device drivers in C/C++ is a total chore for most people and should be avoided if at all possibleWe can buy off the shelf components that can do our time critical stuff and still talk high level protocolsItâs not the 90s! Why are we even talking about writing device drivers?
It makes a lot of high level tasks very easyproduce a working prototype, fastavoid boring tasks that have already been solvedall the wholesome goodness of the Internet OOBeventscan everyone say "behaviour"?These days it can do cool things likebe a serverreal time Internet using WebSocketsspeak protocols other than Internet, e.g. serialBig communityJS is the World's most popular programming language and is FTW
Nodecopter helps us talk to a proprietary helicopter dronethat's just talking to a robot that someone else built.Nodeserial helps us talk to the serial portthis is great because it's useful for all sorts of devices but it doesn't tell us how to talk to our devicesFirmataLovely idea but just tells us how to talk, not what to sayJohnny5 helps us control an Arduino with JSagain, great but if I want cool stuff like GPS I still have to wire it myselfstill doesn't help with our goal of fully integrating both meat and cyber spaces
Model-Collection-Controller/Model-View-CollectionDiscrete physical devices are represented as discrete models in memory on serverModels bound to device change eventsControllers talk to client via WebSocketsRobot's canonical state kept on server (the car itself!), allowingautonomous behaviournetwork failover handled gracefully
WifiPololu (serial using serialport)Phidget (http/serial bridge using phigetapi)