Ron Dagdag
Published © LGPL

Accessibility Controls for Droids

Accessibility is important. This project uses facial gestures to control a droid remotely using augmented reality capabilities of Facebook.

IntermediateFull instructions provided8 hours2,194

Things used in this project

Hardware components

Littlebits Droid Inventor Kit
×1
Arduino Coding Kit
littleBits Arduino Coding Kit
×1
littlebits wireless transmitter
×1
littlebits wireless receiver
×1

Software apps and online services

Facebook AR Studio
Node-RED
Node-RED

Story

Read more

Code

Node-Red Droid API

JavaScript
[{"id":"e42bcbc.438fa38","type":"debug","z":"54510668.716858","name":"","active":true,"console":"false","complete":"payload","x":667.5,"y":219,"wires":[]},{"id":"5e713cce.482bf4","type":"http in","z":"54510668.716858","name":"","url":"/command/:name","method":"get","upload":false,"swaggerDoc":"","x":120,"y":345,"wires":[["4af1489d.9b3e48","84c74cd1.a611a"]]},{"id":"4af1489d.9b3e48","type":"template","z":"54510668.716858","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"Action\": \"{{req.params.name}}\" }","x":331,"y":390,"wires":[["75c6fac.bc81d04"]]},{"id":"75c6fac.bc81d04","type":"change","z":"54510668.716858","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":514,"y":510,"wires":[["ad03d01b.93ab5"]]},{"id":"ad03d01b.93ab5","type":"http response","z":"54510668.716858","name":"","x":728,"y":525,"wires":[]},{"id":"84c74cd1.a611a","type":"template","z":"54510668.716858","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{req.params.name}}","x":314,"y":311,"wires":[["e42bcbc.438fa38","a8792a69.9db7e8"]]},{"id":"130143f.22adbbc","type":"arduino out","z":"54510668.716858","name":"Turn","pin":"5","state":"PWM","arduino":"2f78da34.408576","x":710,"y":371,"wires":[]},{"id":"65d58fd3.a459e","type":"arduino out","z":"54510668.716858","name":"Motor","pin":"9","state":"PWM","arduino":"2f78da34.408576","x":700.5,"y":283,"wires":[]},{"id":"a3a1aefa.4695b","type":"inject","z":"54510668.716858","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":true,"x":299.5,"y":467,"wires":[["a8792a69.9db7e8"]]},{"id":"4fb9b41b.82fd3c","type":"inject","z":"54510668.716858","name":"","topic":"","payload":"straight","payloadType":"str","repeat":"","crontab":"","once":true,"x":306,"y":530,"wires":[["a8792a69.9db7e8"]]},{"id":"2220a82e.dfa018","type":"arduino out","z":"54510668.716858","name":"scream","pin":"1","state":"OUTPUT","arduino":"2f78da34.408576","x":680,"y":449,"wires":[]},{"id":"a8792a69.9db7e8","type":"function","z":"54510668.716858","name":"Command","func":"command = msg.payload;\nvar motor = { payload:0 };\nvar turn = { payload:0};\n// set the payload to the level and return\nswitch(command)\n{\n    case \"forward\":\n        motor.payload = 255;\n        turn = null;\n        break;\n    case \"stop\":\n        motor.payload = 110;\n        turn = null;\n        break;\n    case \"reverse\":\n        motor.payload = 0;\n        turn = null;\n        break;\n    case \"left\":\n        motor.payload = 130;\n        turn.payload = 135;\n        break;\n    case \"right\":\n        motor.payload = 130;\n        turn.payload = 45;\n        break;\n    case \"straight\":\n        motor.payload = 110;\n        turn.payload = 90;\n        break;\n    case \"scream\":\n        return [null, null, {\"payload\" : true}]\n    default:\n        motor.payload = 110;\n        turn.payload = 90;\n} \n\nreturn [motor, turn,{ \"payload\" : false}];","outputs":"3","noerr":0,"x":504,"y":328,"wires":[["65d58fd3.a459e"],["130143f.22adbbc"],["2220a82e.dfa018"]]},{"id":"2f78da34.408576","type":"arduino-board","z":"","device":"/dev/cu.usbmodem68"}]

Facebook AR Studio script

JavaScript
//Header
// Created by Ron Dagdag
//Copyright 2018-present
//All rights reserved.

//This source code is licensed under the license found in the
//LICENSE file in the root directory of this source tree.


var Animation = require('Animation');
var FaceTracking = require('FaceTracking');
var Scene = require('Scene');
const Reactive = require('Reactive');
const Networking = require('Networking');
const Diagnostics = require('Diagnostics');
const FaceGestures = require('FaceGestures');

var server = 'http://4a471498.ngrok.io';
var urlForward = server + '/command/forward';
var urlStop = server + '/command/stop';
var urlReverse = server + '/command/reverse';
var urlLeft = server + '/command/left';
var urlRight = server + '/command/right';
var urlStraight = server + '/command/straight';

var face = FaceTracking.face(0);
var ft = Scene.root.child("Device").child("Camera").child("Focal Distance").child("facetracker0");
var lightning = ft.child("lightningForward");
lightning.hidden = FaceGestures.hasMouthOpen(face).not();

var lightningLeft = ft.child("lightningLeft");
lightningLeft.hidden = FaceGestures.isLeanedLeft(face).not();

var lightningRight = ft.child("lightningRight");
lightningRight.hidden = FaceGestures.isLeanedRight(face).not();


var lightningReverse = ft.child("lightningReverse");
lightningReverse.hidden = FaceGestures.hasEyebrowsRaised(face).not();


FaceGestures.isLeanedLeft(face).monitor().subscribe(function(changedValue) {
  Diagnostics.log(changedValue);
	if (changedValue.newValue) {
    Diagnostics.log('Left Face!');
    Networking.fetch(urlLeft);
	} else{
    Networking.fetch(urlStraight);
  }
});

FaceGestures.isLeanedRight(face).monitor().subscribe(function(changedValue) {
	if (changedValue.newValue) {
    Diagnostics.log('Right Face!');
    Networking.fetch(urlRight);
	} else{
    Networking.fetch(urlStraight);
  }
});

FaceGestures.isLeanedBack(face).monitor().subscribe(function(changedValue) {
	if (changedValue.newValue) {
    Diagnostics.log('Forward Face!');
    Networking.fetch(urlStraight);
	} else{
    Networking.fetch(urlStop);
  }
});

FaceGestures.hasEyebrowsRaised(face).monitor().subscribe(function(changedValue) {
	if (changedValue.newValue) {
    Diagnostics.log('Eyebrow Raised!');
    Networking.fetch(urlReverse);
  } else
  {
    Networking.fetch(urlStop);
  }
});

FaceGestures.hasEyebrowsFrowned(face).monitor().subscribe(function(changedValue) {
	if (changedValue.newValue) {
    Diagnostics.log('Eyebrow Frowned!');
    Networking.fetch(urlForward);
  } else
  {
    Diagnostics.log('Eyebrow Normal!');
    Networking.fetch(urlStop);
  }
});


FaceGestures.hasMouthOpen(face).monitor().subscribe(function(changedValue) {
	if (changedValue.newValue) {
    Diagnostics.log('Mouth open!');
    Networking.fetch(urlForward);
	} else {
    Diagnostics.log('Mouth closed!');
    Networking.fetch(urlStop);
	}
});

Credits

Ron Dagdag

Ron Dagdag

47 projects • 438 followers
Microsoft MVP award / Lead Software Engineer / Augmented Reality. Developer Passionate to learn about Robotics, VR, AR, ML, IOT

Comments