1 / 50

Boe-Bots!

Boe-Bots!. COMP417 Instructor: Philippe Giguère. Introducing Boe-bots. Simple two-wheeled robot differential drive. Manufactured by parallax inc. www.parallax.com (for support/driver etc.) Great for rapid prototyping and teaching That’s why we are using them!. Components.

kina
Download Presentation

Boe-Bots!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Boe-Bots! COMP417 Instructor: Philippe Giguère

  2. Introducing Boe-bots • Simple two-wheeled robot • differential drive. • Manufactured by parallax inc. www.parallax.com (for support/driver etc.) • Great for rapid prototyping and teaching • That’s why we are using them!

  3. Components • Pair of continuous rotation servos with wheels. • Demo board

  4. Components (cont.) • Microprocessor (Javelin stamp) • Sensors • Batteries, chassis, etc…

  5. The “brain”: Javelin Stamp • Small computer on a 24 pin mini-board. • Own power-supply. • 32k of non-volatile EEPROM. • 32k of RAM. • 15 input/output pins: • to control motors/sensors.

  6. The “brain”: Javelin Stamp • Interprets a subset of Java. • 8000 instructions/seconds. • Virtual Peripherals (VP): • serial communication, • PWM (pulse-width modulation), • timer, etc.

  7. Javelin Stamp block diagram

  8. Javelin Stamp Java Limitations • Single Thread • Replaced by “background objects”. • No garbage collection • Use static variables. • Beware of unwanted object creation: • System.out.println(a+b); • Use StringBuffer object instead of String for significant amount of text.

  9. Javelin Stamp Limitations • Subset of primitive data types: • No float/double/long! • Subset of Java libraries. • No abstract type interface. • One dimensional arrays.

  10. Javelin Stamp Integrated Development Environment (IDE) • Runs on Microsoft Windows. • Compile, download code to board and remotely debug. • Need a serial port/or USB version of board. • USB does not work completely: cannot do debugging. • Bi-directional serial message between board and PC • System.out.println() • Terminal.getChar() (doesn’t work on USB) • Check www.parallax.com/javelin/downloads.asp for latest and greatest version

  11. First Example! • Example HelloWorld.java public class HelloWorld { public static void main() { System.out.println("Hello World!"); } }

  12. CPU object • Central to I/O with sensors/motors, low-level functions, communication. • Dozens of methods: • delay(int period) • readPin(int portPin) • writePin(int portPin, boolean value) • count(int timeout, int portPin, boolean edge) • pulseIn(int timeout, int portPin, boolean pinState) • pulseOut(int length, int portPin) • shiftIn(int dataPortPin, int clockPortPin, int bitCount, int mode) • etc..

  13. CPU.delay() • CPU.delay(int period) is similar to sleep(); • Program will pause during that time. • period: the length of time to delay for, measured in 95.48 ms units • CPU.delay(1) sleep for ~ 0.1 ms • CPU.delay(10473) sleep for 1 s

  14. CountDown.java import stamp.core.*; public class CountDown { static int myVar; public static void main() { System.out.println("Commencing Countdown:"); CPU.delay (10000); for(myVar = 10; myVar >= 1; myVar--) { CPU.delay(2000); System.out.println(myVar); } System.out.println("Liftoff!"); } }

  15. A little bit of electronics: resistor • Resists current: • Symbol • Resistor values are color coded.

  16. LED: Light Emitting Diode • A diode a one-way valve: it lets current flow one direction but not the other way. • Made of semi-conductor material. • Emits at a single color.

  17. LED: Light Emitting Diode • Always needs a resistor in series! Typically operate LEDs between 5-20 mA. (in our case ~5 mA: max on all 15 pins is 90 mA). Note: Vdd = +5V, Vss = ground

  18. CPU.writePin(pin,value) • A pin can act like a switch: • CPU.writePin(CPU.pins[13],true) • Connects to Vdd (+5V) • CPU.writePin(CPU.pins[13],false) • Connects to Vss (ground)

  19. CPU.readPin(pin) • A pin can also read a logic voltage: CPU.readPin(CPU.pins[13]) (Note: CPU.pins[13] == CPU.pin13)

  20. Breadboard Area

  21. Circuit for testing readPin/writePin When Push button pressed: P1 = 0V When Push button released: P1 = +5V Without pull-up, voltage would be “floating” when released: random fluctuations.

  22. readPin/writePin • Example ButtonLED.java import stamp.core.*; public class ButtonLED { static boolean P0 = true; public static void main() { while(true) { if (CPU.readPin(CPU.pins[1]) == false) { P0 = !P0; CPU.writePin(CPU.pins[0],P0); CPU.delay(1000); } else { CPU.writePin(CPU.pins[0],true); } } } }

  23. De-bouncing • When a push button is pressed, contact fluctuates for tens of ms. • De-bouncing is ignoring changes for x ms. • (see Button object for more info)

  24. Bouncing example import stamp.core.*; public class ButtonBounce { static boolean P0 = true; public static void main() { while(true) { if (CPU.readPin(CPU.pins[1]) == false) { P0 = !P0; CPU.writePin(CPU.pins[0],P0); } } } }

  25. PWM object(Pulse Width Modulation) • PWM object generates a pulse train as a background object.

  26. PWM object • PwmLed.java import stamp.core.*; public class PwmLed { static PWM BlinkLed = new PWM(CPU.pin0,32767,32767); public static void main() { while(true) { if (CPU.readPin(CPU.pins[1]) == false) { // If button pressed BlinkLed.update(32767,32767);//32767*8.68uS = 0.28s } else { BlinkLed.update(12000,12000); // Blink Fast } } } }

  27. Servo Commands • Servos on Boe-bots use analog signal to encode rotation rate. • Command is send every 20 ms. • High-level duration encodes command: • Neutral if high = 1.5 ms • CW rotation if < 1.5 ms • CCW rotation if > 1.5 ms

  28. Servo Commands

  29. PWM object with servo import stamp.core.*; public class PwmOneServo { final static int SWITCH = CPU.pin1; static PWM ServoL = new PWM(CPU.pin12,173,2304); public static void main() { while(true) { if (CPU.readPin(SWITCH) == false) { // If button pressed ServoL.update(173-30,2304); // 173 is 1.5 ms } // 2304 is 20 ms else { ServoL.update(173+30,2304); } } } } • PwmOneServo.java

  30. Timer object • Timer is another background object. • Used to keep track of time. • 32-bit timer with 8.68 ms resolution. • Can have more than one Timer. • .mark() to “mark” a timer • .timeout() to check if a timer expired.

  31. Timer object import stamp.core.*; public class SimpleTimer { public static void main() { Timer t1 = new Timer(); // timer for first LED Timer t2 = new Timer(); // timer for second LED boolean led0=false; boolean led2=false; t1.mark(); // Start timer t1 t2.mark(); // Start timer t2 while (true) { if (t1.timeout(200)) { led0=!led0; CPU.writePin(CPU.pin0,led0); t1.mark(); } if (t2.timeout(500)) { led2 = !led2; CPU.writePin(CPU.pin15,led2); t2.mark(); } } } } SimpleTimer.java

  32. Timer + PWM object • Using Timer and PWM, it becomes easy to create motion commands. • e.g. go left 2 seconds, then straight 5 seconds, then right 3 seconds. • ServoExample.java

  33. HM55B Magnetic Compass • Using two Hall-effect magnetometers, localizes the magnetic north. • When used indoor, not very precise: steel beams. • Uses HM55B_compass.java with pinout on diagram.

  34. CompassExample.java import stamp.math.*; import stamp.core.*; import stamp.peripheral.sensor.compass.*; public class CompassExample { static int angle; static HM55B_compass compass; // Compass module final static int LED_LEFT = CPU.pin15; // Red LED final static int LED_RIGHT = CPU.pin0; // Red LED public static void main() { while (true) { angle = compass.measure(); if (angle < -5) { CPU.writePin(LED_LEFT,false); CPU.writePin(LED_RIGHT,true); } else if (angle > 5) { CPU.writePin(LED_LEFT,true); CPU.writePin(LED_RIGHT,false); } else { // Points north CPU.writePin(LED_LEFT,false); CPU.writePin(LED_RIGHT,false); } System.out.println(angle); } } }

  35. Trigonometry:Trig.java • Implements fixed-point precision sin,cos,tan.

  36. Fixed-point computation:UnsignedIntMath.java • Used by Trig.java. • Implements fixed-point computation • Format is I.F (Integer + Fraction)

  37. Infra-red detector • Infra-red LED • Sends a small burst @ 38.5kHz • Infra-red receiver • Detects burst @ 38.5kHz

  38. IrTest.java import stamp.core.*; public class IrTest { static PWM emitter = new PWM(CPU.pin2,1,4); // IR LED static boolean result; public static void main() { while(true) { emitter.start(); // Send an infrared signal CPU.delay(10); result = CPU.readPin(CPU.pin3); CPU.writePin(CPU.pin0,result); emitter.stop(); CPU.delay(1000); } } }

  39. Range Measurement with IR • With frequency at which the IR receiver is less sensitive distance duration of receiver pulse. • IrRange.java • Tends to be noisy: • Have to average/filter over a few samples.

  40. IrTestRange.java import stamp.core.*; import stamp.peripheral.sensor.IrRange.*; public class IrTestRange { final static int IR_LED_RIGHT = CPU.pin2; // IR LED final static int IR_RCVR_RIGHT = CPU.pin3; // IR receiver static IrRange RangeR = new IrRange(IR_RCVR_RIGHT,IR_LED_RIGHT); public static void main() { while (true) { int r; // We sample the range measurements r = RangeR.measure(); // And output it on the screen System.out.println(r); CPU.delay(1000); // Need to sleep between samples } } }

  41. Sonar modulePING))) • Range - 2cm to 3m • Uses only one I/O pin • Burst Frequency - 40 kHz for 200 ms

  42. PING))) sonar code example

  43. Extra goodie : PING))) motorized brackets • We have ordered also motorized PING))) brackets. • Available as an option to teams .

  44. PING))) bracket in action

  45. Piezoelectric “buzzer” • Can generate sound at low power. • Use Freqout object to drive a pin. • Can be useful to do a single beep at start of main() • detects spurious resets.

  46. Buzzer.java import stamp.core.*; public class Buzzer { static Freqout myBuzzer = new Freqout(CPU.pin4); static int frequency; public static void main() { myBuzzer.start(); while (true) { for (frequency=20;frequency<2000;frequency+=15) { myBuzzer.setFrequency(frequency); CPU.delay(500); } } } }

  47. Recap of important methods • System.out.println() to print on PC. • CPU.delay(period) to pause. • CPU.pin0 - CPU.pin15 to identify pin. • CPU.read(pin)to read value of a pin. • CPU.write(pin,value)to output +5V, 0V. • PWM object to create a pulse train for servos. • Timer object to have timing in program.

  48. Recap of I/O • Servo motor to move robot. • Push-button. • LED/Buzzer for debugging online. • Magnetic compass for orientation. • Infrared for obstacle detection/distance. • PING))) Sonar module for obstacle as well.

  49. Extra info • When batteries are low, the processor will reset when servos are activated. • Libraries are installed by creating the proper directories in parallax.

  50. Extra info • Instruction manual is on parallax website • www.parallax.com/javelin/downloads.asp • Code example + libraries + extra instructions available on course web page: www.cim.mcgill.ca/~dudek/417/notes/Boebot.html

More Related