javazone 2015 : nodebots - javascript powered robots with johnny-five

15
NodeBots: JavaScript Powered Robots with Johnny-Five Mark Alan West

Upload: mark-west

Post on 14-Feb-2017

58 views

Category:

Software


0 download

TRANSCRIPT

PowerPoint-presentasjon

NodeBots: JavaScript Powered Robots with Johnny-FiveMark Alan West

Welcome to my Lightning Talk! In this talk I will give you a quick introduction to Johnny-Five and the world of NodeBots1

So what are NodeBots? Simply put, they are Robots powered the JavaScript and the Node,js platform! 2

SOURCE: WWW.NODEBOTS.IO

The NodeBots movement is a worldwide phenomenon, with meetup groups spread across the whole world. The community has many events, including an international NodeBots day in July.3

The most popular software solution for programming NodeBots is currently Johnny-Five. The name comes from the 80s classic sci-fi comedy Short Circuit. In this film a military Robot called Johnny-Five gets struck by lightning and becomes self aware, with hilarious consequences.4

Why use Johnny-Five?MaturityCommunityDSLPortabilityOpen SourceJavaScriptNode.js ecosystemREPL

The reasons for Johnny-Fives popularity in the NodeBots world are as follows:

Maturity - Johnny-Five is stable and robust.Community - An active and helpful community led by Rick Waldron.DSL - Easy to learn, consistent DSL which reflects real world objects such as LED and Motor (along with their actions). It is also much easier to learn and requires less boilerplate than say the Arduino Language.Portability - Johnny-Five is supporting more and more platforms - such as the Arduino, Raspberry PI, Tessel 2 and Spark Core. You can reuse your code even if you upgrade your robots hardware.Open Source - is Johnny-Five missing a feature? Go ahead and add it! Feel free to delve into the code!JavaScript - Itss a great chance to reuse your JavaScript knowledge (or even get started with learning JavaScript).Node.js ecosystem - Want to control your robot with a Keyboard? Over MQTT? With Voice Commands? Node has over 160000 modules that cater for everything and these can be easily installed though the Node Package Manager, or NPM.REPL The REPL allows you to change the state of running code from the command line. This makes it very easy to play with and learn the DSL.5

var five = require("johnny-five");

var myBoard = new five.Board();

myBoard.on("ready", function() {

var myLed = new five.Led(13);

myLed.blink(500);

this.repl.inject({ replLed: myLed });});Imports J5 DependancyAdds LED instance to REPLDeclares LED as connected to UNO Pin 13Blinks LED every 500 millisecondsCode block triggered by UNO Ready EventInitialises UNO

Johnny-Five Code Example

So lets have a quick look at the Johnny-Five code for making an LED blink on and off.

The code here does the following:

Imports the Johnny-Five dependency.Initialises the Board.On a successful initialisation event sets up the LED as connected to pin 13 and blinks it.Ive also added the LED to the Node.js REPL so I can write commands directly.6

https://vimeo.com/134953425

In this video I am running the code youve just seen. As you can see the LED is blinking every 500 milliseconds. I then go to the command line and use LED reference to stop the LED blinking and then switch it on and off all from the command line. This REPL is a great way of becoming familiar with the Johnny-Five DSL, as well as allowing you to mess about with actuators connected to the UNO.7

Why use the Arduino UNO?1. Price2. Robustness3. Flexibility

Drawback with the UNO:Doesnt run JavaScript

When working with Johnny-Five I prefer to use the Arduino UNO for conecting to the various physical components, due to its following strengths:

(a) Price - The UNO is very cheap at around 200kr. Copies available from Ebay are closer to 100kr.(b) Robustness - The UNO is resistant to damage from mishandling, faulty wiring, short circuits and so on.(c) Flexibility - The UNO supports a range of Digital and Analog inputs and outputs out of the box.

You could also use the Raspberry PI, but it is no where near as robust and doesnt support analog inputs and output out of the box. 8

Laptop running Johnny-FiveArduino UNO running FirmataSerial CableAllowing Johnny-Five to talk to Firmata(WIFI & Bluetooth also supported)

How do Johnny-Five and the UNO work together? Well the Arduino UNO doesnt understand JavaScript.

Therefore Johnny-Five runs on a PC, which then sends commands to a tethered Arduino UNO. The connection between the UNO and the Host can be a Serial Cable, or even a WIFI or BlueTooth connection. The UNO is running a program called Standard Firmata which provides an API for Johnny-Five to communicate with.

In this example the PC can be swopped out with anything able to run Node.js (including a Raspberry PI). 9

Actuators(i.e. Servos, Motors, LEDs)Brain

Sensors(i.e Button, Heat, Motion)

Nervous System

Confused? Well a Robot should have the following four types of components:

Sensors for receiving stimuli. For example detecting visual or auditory events.Actuators for interacting with the physical world. For example legs that move the robot away from danger.A Brain for interpreting stimuli from the sensors and triggering relevant responses in the actuators. A Nervous System for relaying messages between the brain, sensors and actuators.

In this diagram I have specifed the UNO as the Nervous System and a PC running Johnny-Five, but you could use a Raspberry PI for the Brain, or even for both the brain and the Nervous System. But try to remember that the PI is less robust and flexible than the UNO.

There does exist other platforms that combine the best of both the UNO and PI, such as the Tessel 2, but I havent yet tried this out.10

Ok its time for a live demo of a real NodeBot in action. Keep your fingers crossed!11

Sensors

Nervous System

BrainActuators

Demo Setup

LandDanceTake-off

Getting Started with NodeBotsBuy an Arduino Experimenters Kit.

Follow the tutorials at http://node-ardx.org.

Visit http://johnny-five.io for more information and inspiration.

Ok so if you are interested in playing around with NodeBots, or any type of robotics, then I would encourage you to start buying an Arduino Experiementers Kit. These cost from 300-400kr up to over 1000kr. I would shop around and buy a kit with the most possible sensors and actuators.

Once youve got your hands on a kit then Id visit the node-ardx website and run through the tutorials there. These will get you started with J5 and will also get your started with building electronic circuits. A lot of fun!

And finally you should take a peek at the J5 webite for more information and inspiration. 14

Thanks for [email protected]@markawest

Thanks for listening! Come and have a chat if youd like to talk more about NodeBots or any kind of Robotics you can also contact me on Twitter!15