KEMBAR78
Javascript on Arduino | ODP
Javascript on Arduino
Keith Bloomfield - Dev9
Javascript on Arduino
● Told from experience
– motivation
– approach
– lessons learned
● Talking points:
– hardware
– software
– design patterns
– hardware/software
integration
– code samples
Javascript on Arduino
Motivation
Javascript on Arduino
Motivation
SainSmart palletizing
robotic arm
Javascript on Arduino
Motivation
SainSmart palletizing
robotic arm - $118.23
Javascript on Arduino
Motivation
SainSmart palletizing
robotic arm - $118.23
Pros
● Much cheaper than rival
hobby robotic arms
● Performs surprisingly well
in terms of speed
Javascript on Arduino
Motivation
SainSmart palletizing
robotic arm - $118.23
Cons
● Not much lifting power
● Difficult to replace parts
● No instructions
Javascript on Arduino
Motivation
IoT is the buzzword of the day
Javascript on Arduino
Motivation
IoT is the buzzword of the day
Javascript on Arduino
Motivation
IoT is the buzzword of the day
But it isn't entirely new
● Parts are cheaper
● Tutorials are available
● Technology is more developer friendly
● Similar reasons why many people became
software developers
● We will get back to this
Javascript on Arduino
Arduino
- Is a microcontroller (Open source prototyping platform) – A small
computer on a single integrated circuit (memory, processor, I/O peripherals).
- One of several competing products
Shield
- Extends capabilities of the Arduino
- Requires a driver
- Requires soldering
Javascript on Arduino
Javascript is powering devices
● Johnny-five http://johnny-five.io
● Cylon http://cylonjs.com
● Espruino (Javascript on the metal) http://www.espruino.com/
● and more!
Javascript on Arduino
Javascript is powering devices
Firmata: It's a protocol, it's a library...
Javascript on Arduino
Javascript is powering devices
Firmata: It's a protocol, it's a library...
- Enables communication between a
computer and a microcontroller using the
midi message format:
http://www.midi.org/techspecs/midimessages.php
Javascript on Arduino
IoT is the buzzword of the day?
Javascript on Arduino
IoT is the buzzword of the day?
The cloud acts as the OS of the device.
Javascript on Arduino
Software:
johnny-five: JS Robotics & IoT framework
compulsive ('13) – Loops and delays without traditional
timers. Time based event loop process queue
temporal? (TODO '14) – Non-blocking, temporal task
sequencing.
Javascript is powering devices
Javascript on Arduino
johnny-five
- has a useful REPL
(read-eval-print loop)
- supports a growing number of
boards, shields, sensors,
actuators
Javascript is powering devices
Javascript on Arduino
Hardware: Arduino Mega 2560
AdaFruit Servo Shield
Servos
IR motion sensor
Javascript is powering devices
Javascript on Arduino
Hardware: Load Sensor
HX711 Load Cell Amp
MultiColor Led
HUZZA ESP8266 Wifi breakout
Javascript is powering devices
Javascript on Arduino
Powered by:
Arduino: Basic arm motion only
(4) 1.5V AA Batteries: Arm with augmented body
5V 2A power supply: Arm, lid, motion sensor. Struggles lifting
when all 3 in operation at the same time.
5V 10A power supply: Sufficient
Servos require lots of power!
Javascript on Arduino
Be careful about mishaps. The larger/stronger the robot, the
more severe the accident.
Accidents can quickly disable functionality.
Servos require lots of power!
Javascript on Arduino
Be careful about mishaps. The larger/stronger the robot, the
more severe the accident.
Accidents can quickly disable functionality.
Recovery may take several days (new hardware in the mail)
Servos require lots of power!
Javascript on Arduino
Be careful about mishaps. The larger/stronger the robot, the
more severe the accident.
Accidents can quickly disable functionality.
Recovery may take several days (new hardware in the mail)
+ Add an emergency stop early
Servos require lots of power!
Javascript on Arduino
When composition relies heavily on found
components, and the idea is ad hoc, hardware
refactoring/reassembly is frequent.
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
When composition relies heavily on found
components, and the idea is ad hoc, hardware
refactoring/reassembly is frequent.
+ Plan well, measure accurately and thoroughly.
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
When composition relies heavily on found
components, and the idea is ad hoc, hardware
refactoring/reassembly is frequent.
+ Plan well, measure accurately and thoroughly.
+ Expect to spend considerable time refactoring if you
are planning as you go.
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
+ Refactor small, iterative/incremental, stable as possible
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
+ Refactor small, iterative/incremental, stable as possible
+ Use a board to track tasks
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
+ Refactor small, iterative/incremental, stable as possible
+ Use a board to track tasks
+ Keep changes in sync with the REPL
Lesson: It's easy to end up in
the weeds
Javascript on Arduino
Couples sensory information to action selection (what to do next)
in an intimate bottom-up fashion.
Subsumption Architecture
Javascript on Arduino
Subsumption Architecture
Couples sensory information to action selection (what to do next)
in an intimate bottom-up fashion.
Behaviors prioritized and interruptive.
Javascript on Arduino
Subsumption Architecture
Couples sensory information to action selection (what to do next)
in an intimate bottom-up fashion.
Behaviors prioritized and interruptive.
Lejos: Robot accessed directly through behaviors, focus on
looping actions broken by flipping a boolean to false. Static
methods/fields for convenience
Javascript on Arduino
Couples sensory information to action selection (what to do next)
in an intimate bottom-up fashion.
Behaviors prioritized and interruptive.
Lejos: Robot accessed directly through behaviors, focus on
looping actions broken by flipping a boolean to false. Static
methods/fields for convenience
Challenge: Action selection implementation
Subsumption Architecture
Javascript on Arduino
Hardware in terms of stateful objects
On node.js?
Subsumption Architecture
Javascript on Arduino
Johnny-five:
Animation
Subsumption Architecture
Javascript on Arduino
REST + JSON?
●
Javascript on Arduino
REST + JSON?
● CoAP (Constrained Application Protocol)
http://coap.technology/
● QUIC (Quick UDP Internet Connections)
https://www.chromium.org/quic
● CBOR (Concise Binary Object Representation)
http://cbor.io/
● Apache thrift
https://thrift.apache.org/
● protobuf (Protocol Buffers – serializing structured
data)
https://github.com/google/protobuf
Javascript on Arduino
- Costly,
prohibitive
ramp-up time
● Inexpensive,
interoperable, plug-and-
play components
● Expensive computation
occurs in the cloud
● The only limitation is
creativity
Javascript on Arduino
The Robot...
Javascript on Arduino
Javascript on Arduino
- Detects presence of cat
Javascript on Arduino
- Detects presence of cat
-Waits for cat to do its business
Javascript on Arduino
- Detects presence of cat
-Waits for cat to do its business
-Warns off nearby cat(s)
Javascript on Arduino
- Detects presence of cat
-Waits for cat to do its business
-Warns off nearby cat(s)
-Scoops the clumps, deposits
them in bin
Javascript on Arduino
- Detects presence of cat
-Waits for cat to do its business
-Warns off nearby cat(s)
-Scoops the clumps, deposits
them in bin
- Levels the mounds
Javascript on Arduino
- Detects presence of cat
-Waits for cat to do its business
-Warns off nearby cat(s)
-Scoops the clumps, deposits
them in bin
- Levels the mounds
(v2) Tracks litter level in bin
(v2) Notifies user once bin is full
(v2) Detects clumps
(v2) Wireless
Javascript on Arduino
Demo + Q&A
Github:
github.com/kthblmfld/poopscavator
Demo:
https://www.youtube.com/watch?v=kCbXBw0zStk

Javascript on Arduino

  • 2.
    Javascript on Arduino KeithBloomfield - Dev9
  • 3.
    Javascript on Arduino ●Told from experience – motivation – approach – lessons learned ● Talking points: – hardware – software – design patterns – hardware/software integration – code samples
  • 4.
  • 5.
  • 6.
    Javascript on Arduino Motivation SainSmartpalletizing robotic arm - $118.23
  • 7.
    Javascript on Arduino Motivation SainSmartpalletizing robotic arm - $118.23 Pros ● Much cheaper than rival hobby robotic arms ● Performs surprisingly well in terms of speed
  • 8.
    Javascript on Arduino Motivation SainSmartpalletizing robotic arm - $118.23 Cons ● Not much lifting power ● Difficult to replace parts ● No instructions
  • 9.
    Javascript on Arduino Motivation IoTis the buzzword of the day
  • 10.
    Javascript on Arduino Motivation IoTis the buzzword of the day
  • 11.
    Javascript on Arduino Motivation IoTis the buzzword of the day But it isn't entirely new ● Parts are cheaper ● Tutorials are available ● Technology is more developer friendly ● Similar reasons why many people became software developers ● We will get back to this
  • 12.
    Javascript on Arduino Arduino -Is a microcontroller (Open source prototyping platform) – A small computer on a single integrated circuit (memory, processor, I/O peripherals). - One of several competing products Shield - Extends capabilities of the Arduino - Requires a driver - Requires soldering
  • 13.
    Javascript on Arduino Javascriptis powering devices ● Johnny-five http://johnny-five.io ● Cylon http://cylonjs.com ● Espruino (Javascript on the metal) http://www.espruino.com/ ● and more!
  • 14.
    Javascript on Arduino Javascriptis powering devices Firmata: It's a protocol, it's a library...
  • 15.
    Javascript on Arduino Javascriptis powering devices Firmata: It's a protocol, it's a library... - Enables communication between a computer and a microcontroller using the midi message format: http://www.midi.org/techspecs/midimessages.php
  • 16.
    Javascript on Arduino IoTis the buzzword of the day?
  • 17.
    Javascript on Arduino IoTis the buzzword of the day? The cloud acts as the OS of the device.
  • 18.
    Javascript on Arduino Software: johnny-five:JS Robotics & IoT framework compulsive ('13) – Loops and delays without traditional timers. Time based event loop process queue temporal? (TODO '14) – Non-blocking, temporal task sequencing. Javascript is powering devices
  • 19.
    Javascript on Arduino johnny-five -has a useful REPL (read-eval-print loop) - supports a growing number of boards, shields, sensors, actuators Javascript is powering devices
  • 20.
    Javascript on Arduino Hardware:Arduino Mega 2560 AdaFruit Servo Shield Servos IR motion sensor Javascript is powering devices
  • 21.
    Javascript on Arduino Hardware:Load Sensor HX711 Load Cell Amp MultiColor Led HUZZA ESP8266 Wifi breakout Javascript is powering devices
  • 22.
    Javascript on Arduino Poweredby: Arduino: Basic arm motion only (4) 1.5V AA Batteries: Arm with augmented body 5V 2A power supply: Arm, lid, motion sensor. Struggles lifting when all 3 in operation at the same time. 5V 10A power supply: Sufficient Servos require lots of power!
  • 23.
    Javascript on Arduino Becareful about mishaps. The larger/stronger the robot, the more severe the accident. Accidents can quickly disable functionality. Servos require lots of power!
  • 24.
    Javascript on Arduino Becareful about mishaps. The larger/stronger the robot, the more severe the accident. Accidents can quickly disable functionality. Recovery may take several days (new hardware in the mail) Servos require lots of power!
  • 25.
    Javascript on Arduino Becareful about mishaps. The larger/stronger the robot, the more severe the accident. Accidents can quickly disable functionality. Recovery may take several days (new hardware in the mail) + Add an emergency stop early Servos require lots of power!
  • 26.
    Javascript on Arduino Whencomposition relies heavily on found components, and the idea is ad hoc, hardware refactoring/reassembly is frequent. Lesson: It's easy to end up in the weeds
  • 27.
    Javascript on Arduino Whencomposition relies heavily on found components, and the idea is ad hoc, hardware refactoring/reassembly is frequent. + Plan well, measure accurately and thoroughly. Lesson: It's easy to end up in the weeds
  • 28.
    Javascript on Arduino Whencomposition relies heavily on found components, and the idea is ad hoc, hardware refactoring/reassembly is frequent. + Plan well, measure accurately and thoroughly. + Expect to spend considerable time refactoring if you are planning as you go. Lesson: It's easy to end up in the weeds
  • 29.
    Javascript on Arduino +Refactor small, iterative/incremental, stable as possible Lesson: It's easy to end up in the weeds
  • 30.
    Javascript on Arduino +Refactor small, iterative/incremental, stable as possible + Use a board to track tasks Lesson: It's easy to end up in the weeds
  • 31.
    Javascript on Arduino +Refactor small, iterative/incremental, stable as possible + Use a board to track tasks + Keep changes in sync with the REPL Lesson: It's easy to end up in the weeds
  • 32.
    Javascript on Arduino Couplessensory information to action selection (what to do next) in an intimate bottom-up fashion. Subsumption Architecture
  • 33.
    Javascript on Arduino SubsumptionArchitecture Couples sensory information to action selection (what to do next) in an intimate bottom-up fashion. Behaviors prioritized and interruptive.
  • 34.
    Javascript on Arduino SubsumptionArchitecture Couples sensory information to action selection (what to do next) in an intimate bottom-up fashion. Behaviors prioritized and interruptive. Lejos: Robot accessed directly through behaviors, focus on looping actions broken by flipping a boolean to false. Static methods/fields for convenience
  • 35.
    Javascript on Arduino Couplessensory information to action selection (what to do next) in an intimate bottom-up fashion. Behaviors prioritized and interruptive. Lejos: Robot accessed directly through behaviors, focus on looping actions broken by flipping a boolean to false. Static methods/fields for convenience Challenge: Action selection implementation Subsumption Architecture
  • 36.
    Javascript on Arduino Hardwarein terms of stateful objects On node.js? Subsumption Architecture
  • 37.
  • 38.
  • 39.
    Javascript on Arduino REST+ JSON? ● CoAP (Constrained Application Protocol) http://coap.technology/ ● QUIC (Quick UDP Internet Connections) https://www.chromium.org/quic ● CBOR (Concise Binary Object Representation) http://cbor.io/ ● Apache thrift https://thrift.apache.org/ ● protobuf (Protocol Buffers – serializing structured data) https://github.com/google/protobuf
  • 40.
    Javascript on Arduino -Costly, prohibitive ramp-up time ● Inexpensive, interoperable, plug-and- play components ● Expensive computation occurs in the cloud ● The only limitation is creativity
  • 41.
  • 42.
  • 43.
    Javascript on Arduino -Detects presence of cat
  • 44.
    Javascript on Arduino -Detects presence of cat -Waits for cat to do its business
  • 45.
    Javascript on Arduino -Detects presence of cat -Waits for cat to do its business -Warns off nearby cat(s)
  • 46.
    Javascript on Arduino -Detects presence of cat -Waits for cat to do its business -Warns off nearby cat(s) -Scoops the clumps, deposits them in bin
  • 47.
    Javascript on Arduino -Detects presence of cat -Waits for cat to do its business -Warns off nearby cat(s) -Scoops the clumps, deposits them in bin - Levels the mounds
  • 48.
    Javascript on Arduino -Detects presence of cat -Waits for cat to do its business -Warns off nearby cat(s) -Scoops the clumps, deposits them in bin - Levels the mounds (v2) Tracks litter level in bin (v2) Notifies user once bin is full (v2) Detects clumps (v2) Wireless
  • 49.
    Javascript on Arduino Demo+ Q&A Github: github.com/kthblmfld/poopscavator Demo: https://www.youtube.com/watch?v=kCbXBw0zStk