nodebots presentation @seekjobs

79
nodebots Steven de Salas JavaScript Developer

Upload: steven-de-salas

Post on 11-Jan-2017

69 views

Category:

Devices & Hardware


1 download

TRANSCRIPT

Page 1: nodebots presentation @seekjobs

nodebots

Steven de SalasJavaScript Developer

Page 2: nodebots presentation @seekjobs

What is this talk about?

• 30 minutes • Robots

– Hardware Parts, Electronics, Fabrication, Power– Microcontrollers vs Microprocessors (lots!)

• NodeJS & JavaScript– Using Node to talk to USB, Bluetooth, Firmata– JS Libraries, other languages.

• Quick Demo• Getting Started

Page 3: nodebots presentation @seekjobs

What is nodebots?

• It’s a meetup. • That takes place in a

few cities. • For people who like to

make robots. • And who like

JavaScript.

Page 4: nodebots presentation @seekjobs

nodebots day 2016

Page 5: nodebots presentation @seekjobs

nodebots day 2016

Sumo bot fighting

Page 6: nodebots presentation @seekjobs

nodebots day 2016

That’s Andrew, He runs the (Melbourne) meetup

Page 7: nodebots presentation @seekjobs

Robots

Page 8: nodebots presentation @seekjobs

Robots

What does it What does it taketake to build to build one?one?

Page 9: nodebots presentation @seekjobs

Robots

Lets take one apart.Lets take one apart.

Page 10: nodebots presentation @seekjobs

Robots

Page 11: nodebots presentation @seekjobs

Robots

Page 12: nodebots presentation @seekjobs

What do we have?

Page 13: nodebots presentation @seekjobs

What do we have?

Frame

Page 14: nodebots presentation @seekjobs

What do we have?

MotorisedWheels

Page 15: nodebots presentation @seekjobs

What do we have?

Batteries

Page 16: nodebots presentation @seekjobs

What do we have?

Jumper Leads

Page 17: nodebots presentation @seekjobs

What do we have?

Breadboard

Page 18: nodebots presentation @seekjobs

What do we have?

Rubber Bands

Page 19: nodebots presentation @seekjobs

What do we have?

Blue Tac

Page 20: nodebots presentation @seekjobs

What do we have?

Zip Ties

Page 21: nodebots presentation @seekjobs

What do we have?

Sensors

Page 22: nodebots presentation @seekjobs

What do we have?

Brain(Microcontroller)

Page 23: nodebots presentation @seekjobs

What do we have?

Brain(Microcontroller)

Page 24: nodebots presentation @seekjobs

Modern Day Applied Electronics

✓X

Page 25: nodebots presentation @seekjobs

What is a Microcontroller?

Page 26: nodebots presentation @seekjobs

• Like a small computerwithout an O/S

What is a Microcontroller?

Page 27: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing

Page 28: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing• Runs a piece of code

over and over again

Page 29: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing• Runs a piece of code

over and over again• Receive and send

electrical signals

Page 30: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing• Runs a piece of code

over and over again• Receive and send

electrical signals• Turns things on and off

Page 31: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing• Runs a piece of code

over and over again• Receive and send

electrical signals• Turns things on and off

2Kb RAM, 16 MHz

Page 32: nodebots presentation @seekjobs

What is a Microcontroller?

• Like a small computerwithout an O/S

• Physical computing• Runs a piece of code

over and over again• Receive and send

electrical signals• Turns things on and off

2Kb RAM, 16 MHz

Page 33: nodebots presentation @seekjobs

Phenomenal Cosmic Powers !!!

Page 34: nodebots presentation @seekjobs
Page 35: nodebots presentation @seekjobs

Processing Power vs 80s Consumer Devices

16

2

32

1.88 8

1

64

208

128

64

0

20

40

60

80

100

120

140

Arduino UNO Atari 800 Comm 64 Mac 128K

CPU (MHz)RAM (Kb)Flash (Kb)

Page 36: nodebots presentation @seekjobs

Processing Powervs Today’s Consumer Devices

16

2

32

1GHz

1Gb

8Gb 2,4GHz

2Gb

32Gb 1,4GHz

1Gb

64Gb

0

20

40

60

80

100

120

140

Arduino UNO RasPi 3B Galaxy S5 iPhone 6

CPU (MHz)RAM (Kb)Flash (Kb)

Page 37: nodebots presentation @seekjobs

Processing Powervs Today’s Consumer Devices

16

2

32

1GHz

1Gb

8Gb 2,4GHz

2Gb

32Gb 1,4GHz

1Gb

64Gb

0

20

40

60

80

100

120

140

Arduino UNO RasPi 3B Galaxy S5 iPhone 6

CPU (MHz)RAM (Kb)Flash (Kb)

What about Moore’s Law?Microcontrollers do not appear to follow it.

Page 38: nodebots presentation @seekjobs

Programming a Microcontroller

• C++, no garbage collection • Program big? Cannot fit• Long strings = out of memory• Array resizing? (Mem Pointers)

Academically interesting

Page 39: nodebots presentation @seekjobs

Programming a Microcontroller

• C++, no garbage collection • Program big? Cannot fit• Long strings = out of memory• Array resizing? (Mem Pointers)

In practice:• SD Storage = tricky• Wifi = good luck• HTTPS = no luck

Academically interesting

Archaic

Page 40: nodebots presentation @seekjobs

Why not use a proper computer instead?

• No Analog Sensors• No PWM• Cannot drive motors• Will fry at high loads

In Short: Great for processing, not

good for manipulating electricity.

Raspberry Pi 3B

CPU 1GHzRAM 1GbLanguages AnyStorage To 64 GbConnectivity Wifi, HTTPs

Page 41: nodebots presentation @seekjobs

Microcontroller vs Microprocessor

• No O/S• Low RAM, no HD / network• Rugged• More power (200 mA)• Digital & Analog• Speaks C++

• Runs Linux• Lots RAM, HD + Network• Delicate • Less Power (50 mA)• Digital Only• Speaks Everything

Page 42: nodebots presentation @seekjobs

Microcontroller vs Microprocessor

• No O/S• Low RAM, no HD / network• Rugged• More power (200 mA)• Digital & Analog• Speaks C++

• Runs Linux• Lots RAM, HD + Network• Delicate • Less Power (50 mA)• Digital Only• Speaks Everything

Page 43: nodebots presentation @seekjobs

How about we put them together?

Page 44: nodebots presentation @seekjobs

How about we put them together?

USB

Page 45: nodebots presentation @seekjobs

How about we put them together?

SLAVEHandles theElectronics

MASTERReviews dataCoordinates &Makes decisions

USB

Two-way Serial communication

Page 46: nodebots presentation @seekjobs

How about we put them together?

SLAVEHandles theElectronics

MASTERReviews dataCoordinates &Makes decisions

USB

Two-way Serial communication

Page 47: nodebots presentation @seekjobs

How about we put them together?

SLAVEHandles theElectronics

MASTERReviews dataCoordinates &Makes decisions

USB

Two-way Serial communication I RULZ

Page 48: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

USB

Page 49: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

> hey buddy, turn on the light

USB

Page 50: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

> ???> hey buddy, turn on the light

USB

Page 51: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

> ???

$ npm install firmata

> hey buddy, turn on the light

USB

Page 52: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

> ???

$ npm install firmata> Yes Master.

> hey buddy, turn on the light

USB

Page 53: nodebots presentation @seekjobs

Communication

var SerialPort = require(‘serialport’).SerialPort;

var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});

usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});

> ???

$ npm install firmata> Yes Master.

> hey buddy, turn on the light

Bluetooth = Serial

Page 54: nodebots presentation @seekjobs

Running a Servo using C++ (Arduino)

Page 55: nodebots presentation @seekjobs

Running a Servo with Johnny Five

var five = require("johnny-five");var board = new five.Board();

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

var servo = new five.Servo({ pin: 10, type: "continuous" });

// Clockwise, top speed. servo.cw(1);});

Page 56: nodebots presentation @seekjobs

Johnny Five Library

• npm install johnny-five

• 7K stars, Rick Waldron

• “jQuery for robots”

• Support for many microcontrollers

• Simple, well thought API

• Large community

Page 57: nodebots presentation @seekjobs

Running a servo with Cylon JS

var Cylon = require("cylon");

Cylon.robot() .connection("arduino", { adaptor: "firmata", port: "/dev/ttyACM0" }) .device("servo", { driver: "servo", pin: 3 }) .on("ready", function(bot) { var angle = 0;

setInterval(function() { // +20deg every 100ms angle += 20; bot.servo.angle(angle++); }, 100);

}) .start();

Page 58: nodebots presentation @seekjobs

Cylon.JS

• npm install cylon

• 2.6K stars

• Many platforms

• Bit haphazard

• Less active community

Page 59: nodebots presentation @seekjobs

Do I have to use JavaScript?

Page 60: nodebots presentation @seekjobs

Do I have to use JavaScript?

Page 61: nodebots presentation @seekjobs

Do I have to use JavaScript?Nope. You just need to talk to the USB Serial Port

Page 62: nodebots presentation @seekjobs

Do I have to use JavaScript?

artoo

CORE(LibUsbDotNet)

Nope. You just need to talk to the USB Serial Port

(ruby)

Page 63: nodebots presentation @seekjobs

DEMO 1: C++ (only)

Page 64: nodebots presentation @seekjobs

DEMO 2: C++ <=> (0.10)

Page 65: nodebots presentation @seekjobs

DEMO 3: Firmata <=> johnny-five

Page 66: nodebots presentation @seekjobs

DEMO 4: Planetary Domination Robot

Page 67: nodebots presentation @seekjobs

DEMO 4: Planetary Domination Robot

PROTOCOL ERROR

Page 68: nodebots presentation @seekjobs

My own journey

Nov: Arduino Starter KitDec: Arduino Yun Microcontroller (Linux)

Youtube, basic Experiments, Wifi, control via Mobile App.

2016Jan: NodeJS, Sound bot.Mar: Move to MelbourneJul: Nodebots Day. First Nodebot.

2015Aug: Zero knowledge.Sep: Electromagnets,Electronics for dummies

(eBay: $75Second-hand)

Aug: Raspberry Pi 3B. Refinements.Oct: Second Robot. Third robot.

Page 69: nodebots presentation @seekjobs

Getting Started

Andrew Fisher https://github.com/ajfisher Chief Tinkerer

Nodebots AU Meetup(Hawthorn)Community Hackerspace First Wed of every month. Arduino Starter Kit

$100 (amazon)

Johnny Fivenode-serialport

npm install serialport npm install johnny-five

EITHER

Page 70: nodebots presentation @seekjobs

To Recap

Page 71: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code

Page 72: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!

Page 73: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)

Page 74: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++

code to tell controller what to do.

Page 75: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++

code to tell controller what to do.5. Added advantage is lots of memory / storage

and networking.

Page 76: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++

code to tell controller what to do.5. Added advantage is lots of memory / storage

and networking.6. Go to Nodebots AU meetup to find out more.

Page 77: nodebots presentation @seekjobs

To Recap

1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++

code to tell controller what to do.5. Added advantage is lots of memory / storage

and networking.6. Go to Nodebots AU meetup to find out more.7. Build some cool s**t! Because you can!

Page 78: nodebots presentation @seekjobs

nodebots day 2016

Sumo bot fighting

Page 79: nodebots presentation @seekjobs

THANKS!!!

Steven de Salas https://github.com/sdesalas Apprentice Tinkerer

Nodebots AU Meetup(Hawthorn)Community Hackerspace First Wed of every month. Arduino Starter Kit

$100 (amazon)

Johnny Fivenode-serialport

npm install serialport npm install johnny-five