coding mojo : node.js meetup

42
Building a Node.js Powered Robot @markawest

Upload: mark-west

Post on 23-Jan-2017

311 views

Category:

Technology


0 download

TRANSCRIPT

BuildingaNode.js PoweredRobot

@markawest

“AnyapplicationthatcanbewritteninJavaScript,willeventuallybewrittenin

JavaScript”

JamesAtwood(founder, stackoverflow.com)

NodeBot Rover

NodeBot RoverDemo

https://vimeo.com/162426456

Puttingthe HardwareTogether

TheArduino Ecosystem• MicroController platform.

• ManydifferentArduinomodels.

• OpenSourcedesign.

• Extensiblevia“Shields”.

Two ServosforCameraPan&Tilt

Servos wiredtoArduinoChassis

Raspberry PIInPlastic Case

WIFIDongle

Raspberry PICamera

Wired directlytothe

Raspberry PI

Actuators

Sensors

Nervous System

RaspberryPI2RaspberryPICam

ArduberryMicrocontroller Arduino Chassis Servo

Servo

Brain

NodeBot RoverHardware

Actuators

Sensors

Nervous System

RaspberryPI2RaspberryPICam

ArduberryMicrocontroller Arduino Chassis Servo

Servo

Brain

NodeBot RoverHardware

Controllingthe Hardware

RaspberryPI2

Arduberry

Servo

SoftwareCommunicationacrossHardwareLayers

Servo

Raspberry PI Chassis

JavaScriptPI Binary (Compiled C/C++)

TheNodeBots Movement

Source:nodebots.io

1. Maturity2. Community3. DSL4. Portability5. OpenSource6. Node.js ecosystem7. REPL

BenefitsofusingJohnny-Five

ImportsJ5Dependancy

Adds LEDinstance toREPL

Declares LEDasconnected toUNOPin13

BlinksLEDevery 500milliseconds

Codeblock triggered byUNO”Ready”Event

Initialises UNO

Johnny-FiveCodeExamplevar 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

});});

Johnny-FiveREPLDemo

https://vimeo.com/134953425

Arduberry

Servo

BridgingthegapwithFirmata

Servo

Raspberry PI Chassis

Johnny-Five(Firmata Client)

Std.Firmata(Firmata Server)

JavaScriptPI Binary (Compiled C/C++)

GettingStartedwithJohnny-Five1. BuyanArduino ExperimentersKit.

2. Followthetutorialsathttp://node-ardx.org.

3. Visithttp://johnny-five.io formoreinformationandinspiration.

UsingMQTTtoGlue theComponentsTogether

Johnny-FiveProcess

ExpressProcess

Raspberry PI2

WE

Browser

HTTPS

NodeBotRover

Hardware

Firmata

Johnny-FiveProcess

ExpressProcess

Raspberry PI2

WE

Browser

HTTPS

NodeBotRover

Hardware

Firmata

MQTTMessageBroker

MQTT

MQTToverWebSockets

Commands

Acknowledgements

MQTT.jsClient

MQTT.jsClient

Why Add aMessageBroker?

• Seperation ofconcerns.

• Isolate maincomponents foreasier testing.

MQTT– MQTelemetry Transport• Internet of Thingsconnectivityprotocol.

• Designed tobelightweightwith asmall footprint andlittleoverhead.

• Requires aMessageBroker(publish /subscribe).

• UsedbyFacebook forpushing updates tomobileclients.

Adding MQTTtothe NodeBot RoverBroker

• PublicMQTTBroker

– ManyPublicBrokersexist.– Onelessprocess torunon

Raspberry PI.

Client

• MQTT.js

– Provides anMQTTclientlibrary forNode.js.

– Extremely simpletouse.– Integrates seamlesslywith

Johnny-Five.

MQTT.js (Node.js)ClientExample

MQTTOverWebSockets with MQTT.js• MQTT.js isaNode.js package andis

meant foruse on the ServerSide.

• Toallow MQTT.js torunfromtheBrowser,we firstneeded to”Browserify”the MQTTlibrary.

• We could then access the”Browserified”MQTTclient libraryfromthe Browser.

• Thissolution requires that your MQTTBrokerhasaWebSocket endpoint.

HTML5SpeechRecognition(notNode.js,but nice toknow)

SpeechDemo

https://vimeo.com/168245807

MoreaboutHTML5SpeechRecognition

https://utbrudd.bouvet.no/2014/11/11/getting-started-with-html5-speech-recognition-on-

google-chrome