do you want to build a robot

29
Do you want to build a robot? Anna Gerber

Upload: anna-gerber

Post on 29-Jan-2018

169 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Do you want to build a robot

Doyouwanttobuildarobot?

AnnaGerber

Page 2: Do you want to build a robot

RobotDesignArobotisanautonomoussystemthatsensesandrespondsto,oractsuponthephysicalworld

Page 3: Do you want to build a robot

Sensors(Inputse.g.ultrasonicsensor)

Control(Microcontrolleror

Single-Board-Computer)

Actuators(Outputse.g.motors)

PowerChassis

Page 4: Do you want to build a robot

JSRobotics

• http://johnny-five.io/• https://www.espruino.com/• https://tessel.io/• https://docs.particle.io/reference/javascript/• https://cylonjs.com/• http://jerryscript.net/• http://mujs.com/• http://duktape.org/

Page 5: Do you want to build a robot

Selectinghardware

• Johnny-FivesupportsArduino,RaspberryPi,Tessel,Particle,BeagleBone,andmore

Page 6: Do you want to build a robot

Johnny-Five• OpenSourceJavaScriptRoboticsFrameworkforNode.jshttps://github.com/rwaldron/johnny-five• CommunicateswithmicrocontrollerslikeArduinousingtheFirmata protocol• Runson-boarddevicesthatcanrunNode.jse.g.RaspberryPi,BeagleBone Black,viaI/OPlugins

Page 7: Do you want to build a robot

SetupRaspberryPiZeroW(headless)

• InstallRaspbian:• https://www.raspberrypi.org/documentation/installation/installing-images/README.md

• Createafilenamedwpa_supplicant.conf onthemicroSDcard:network={

ssid="campjs"psk="morecoffee"

}

• Addafilenamedssh (contentsdon’tmatter)ontherootofthemicroSDcardtoenableSSHonboot

Page 8: Do you want to build a robot

ConnecttotheRaspberryPi

• Rpi usesmDNS soconnecttothePioverSSH:• ssh [email protected]• Defaultpasswordisraspberry• (Makesureyouchangethis)

• Raspbian comeswithnode.js installedbutifyouareusingsomethingelse,installnode• Thenusenpm toinstallthedependencies:

• npm installserialport• npm installjohnny-fiveraspi-io

Page 9: Do you want to build a robot

RaspberryPiGPIO

• SoldersomeheadersontotheRaspberryPiZeroWfortheGPIOpins• Peripheralcomponents(e.g.sensors,actuators)attachviathesepins• 3.3Vlogic• InJohnny-Fivethepinsarenamed"P[header]-[pin]”e.g.P1-7

Page 10: Do you want to build a robot

Breadboard• Usetoprototypecircuitswithoutsolderingbypluggingincomponentsandjumperwires• Numberedrowsareconnected• Somehavepowerrailsalongthesides

Page 11: Do you want to build a robot

AttachanLEDusingaBreadboard

Page 12: Do you want to build a robot

WritingJohnny-Fiveprograms

1. CreateaJavaScriptfile(e.g.blink.js)onthePi2. Edititusingatexteditor3. Requirethejohnny-fivelibraryandraspi-io librariesintoandsetupthe

boardobjectusingtheIO/Plugin

const raspi = require('raspi-io');const five = require('johnny-five');const board = new five.Board({io: new raspi()

});

Page 13: Do you want to build a robot

Readyevent

• Whentheboardisreadyforourcodetostartinteractingwithitandtheattachedsensorsandactuators,itwilltriggerareadyevent

board.on('ready', () => {// code for sensors, actuators goes here

});

Page 14: Do you want to build a robot

LED

• CreateanLedinstance

// attach LED on pin 7const led = new five.Led('P1-7');

// call strobe function to blink once per secondled.strobe(1000);

• Wecanchangetheparametertothestrobefunctiontochangethespeed:Thisinputvalueisprovidedinmilliseconds

Page 15: Do you want to build a robot

LEDblinkprogram

const raspi = require('raspi-io');const five = require('johnny-five');const board = new five.Board({

io: new raspi()}); board.on('ready', () => {

// LED attached to RPi pin 7 (GPIO4)const led = new five.Led('P1-7');

led.strobe(500); });

Page 16: Do you want to build a robot

Inputs- Sensors

• Environmentalconditions (e.g.temperature,humidity)•Magnetic(e.g.halleffectsensor)• Light(e.g.photoresistor)• Sound(e.g.microphone,piezo)•Movement/position(e.g.accelerometer,tiltswitch)• UserInput(e.g.button)

Page 17: Do you want to build a robot

InputsPHOTORESISTORResistance changesdependingontheamountof ambient light

TILTSWITCHDetectorientation

PUSHBUTTONAlso knownasmomentaryswitch

PIEZOELEMENTDetectvibrations orknocks

TEMPERATURESENSORRead theambienttemperature

Page 18: Do you want to build a robot

Outputs

• Light&Displays(e.g.LED,LCDscreen)• Sound(e.g.Piezo buzzer)•Movement(e.g.Servo,DCMotor,Solenoid)• Relays

Page 19: Do you want to build a robot

OutputsPIEZOELEMENTApulseofcurrentwillcauseittoclick.Astreamofpulseswillcauseittoemitatone.

RGBLEDWeareusingCommonCathodeRGBLEDs.Thelongerleadisthecommonleadwhichconnectstoground.ThethreeotherleadsareforRed,GreenandBluesignal

9GHOBBYSERVOAbox containingamotorwithgearstomakeitpositionable from0to180degrees.

Page 20: Do you want to build a robot

Digitalvs Analog

• Digital• discretevalues(0or1)• Examples:tiltsensor,pushbutton

• Analog• continuousvalues• typicallyvaluesforanalogsensorsareconstrainedwithinarangee.g.0– 255,0– 1023

• Example:photoresistor

• Somecomponentssupportbothdigitalandanalog

Page 21: Do you want to build a robot

REPL

• Read,Eval,PrintLoop• Aconsoleforreal-timeinteractionwiththecode• ExposeourvariablestotheREPLtoenableinteractivecontrol:

board.on('ready', () => {// LED attached to RPi pin 7 (GPIO4)const myLed = new five.Led('P1-7');

myLed.strobe(500);board.repl.inject({

led: myLed});

});

Page 22: Do you want to build a robot

ControllingtheLEDviatheREPL

• AttheREPLprompttypecommandsfollowedbyenter• Try:

• stop,• on,• off,• toggle,• strobee.g:>>led.stop()

Page 23: Do you want to build a robot

Buttons

const button=newfive.Button("P1-11");const led=newfive.Led("P1-7");

button.on("down",(value)=>{led.on();});button.on(”up",(value)=>{led.off();});

http://johnny-five.io/api/button/

Page 24: Do you want to build a robot

Servos

const myServo =newfive.Servo("P1-35");

board.repl.inject({servo:myServo

}); myServo.sweep();

board.wait(5000,()=>{myServo.stop();myServo.center();

});

Page 25: Do you want to build a robot

PWM

• PulseWidthModulation• Produceanalogoutputviadigitalpins• Insteadofonoroff,asquarewaveissenttosimulatevoltagesbetween0V(off)and5V(on)• Usedtocontrolmotors,fadeLEDs etc

Page 26: Do you want to build a robot

Piezo

const piezo=newfive.Piezo("P1-32");let val = 0; board.loop(200,function(){if (val ^= 1) { //Playnotea4for1/5secondpiezo.frequency(five.Piezo.Notes["a4"],200);

}});

Page 27: Do you want to build a robot

Motors

const leftMotor = new five.Motor({

pins: {pwm: "P1-35", dir: "P1-13"},

invertPWM: true

});

const rightMotor = new five.Motor({

pins: {pwm: "P1-32", dir: "P1-15"},

invertPWM: true

});

leftMotor.forward(150);

rightMotor.forward(150);

SeeJohnny-FivemotorAPIhttp://johnny-five.io/api/motor/

Page 28: Do you want to build a robot

Node-RED

Page 29: Do you want to build a robot

• Anna’sblog:http://crufti.com• http://johnny-five.io/• Node-ARDX(examplesforArduino):http://node-ardx.org

Readmore