diff options
Diffstat (limited to 'libraries/Robot_Control/examples/explore')
11 files changed, 1390 insertions, 0 deletions
| diff --git a/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino b/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino new file mode 100644 index 0000000..794479e --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino @@ -0,0 +1,134 @@ +/* Robot Logo + + This sketch demonstrates basic movement of the Robot.  + When the sketch starts, press the on-board buttons to tell  + the robot how to move. Pressing the middle button will  + save the pattern, and the robot will follow accordingly.  + You can record up to 20 commands. The robot will move for  + one second per command. +  + This example uses images on an SD card. It looks for + files named "lg0.bmp" and "lg1.bmp" and draws them on the + screen. + + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library + +int commands[20];  //  array for storing commands + +void setup() { +  // initialize the Robot, SD card, and display  +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); + +  // draw "lg0.bmp" and "lg1.bmp" on the screen +  Robot.displayLogos(); +} + +void loop() { +   +  Robot.drawBMP("intro.bmp", 0, 0);  //display background image +   +  iniCommands(); // remove commands from the array +  addCommands(); // add commands to the array +   +  delay(1000); // wait for a second +   +  executeCommands(); // follow orders +   +  Robot.stroke(0,0,0); +  Robot.text("Done!", 5, 103); // write some text to the display +  delay(1500); // wait for a moment +} + +// empty the commands array +void iniCommands() { +  for(int i=0; i<20; i++) +    commands[i]=-1; +} + +// add commands to the array +void addCommands() { +  Robot.stroke(0,0,0); +  // display text on the screen +  Robot.text("1. Press buttons to\n add commands.\n\n 2. Middle to finish.", 5, 5); +   +  // read the buttons' state +  for(int i=0; i<20;) {  //max 20 commands +    int key = Robot.keyboardRead(); +    if(key == BUTTON_MIDDLE) {  //finish input +      break; +    }else if(key == BUTTON_NONE) {  //if no button is pressed  +      continue; +    } +    commands[i] = key; // save the button to the array +    PrintCommandI(i, 46); // print the command on the screen +    delay(100); +    i++; +  } +} + +// run through the array and move the robot +void executeCommands() { +  // print status to the screen +  Robot.text("Excuting...",5,70); +   +  // read through the array and move accordingly +  for(int i=0; i<20; i++) { +    switch(commands[i]) { +      case BUTTON_LEFT: +        Robot.turn(-90); +        break; +      case BUTTON_RIGHT: +        Robot.turn(90); +        break; +      case BUTTON_UP: +        Robot.motorsWrite(255, 255); +        break; +      case BUTTON_DOWN: +        Robot.motorsWrite(-255, -255); +        break; +      case BUTTON_NONE: +        return; +    } +    // print the current command to the screen +    Robot.stroke(255,0,0); +    PrintCommandI(i, 86); +    delay(1000); +     +    // stop moving for a second +    Robot.motorsStop(); +    delay(1000); +  } +} + +// convert the button press to a single character +char keyToChar(int key) { +  switch(key) { +    case BUTTON_LEFT: +      return '<'; +    case BUTTON_RIGHT: +      return '>'; +    case BUTTON_UP: +      return '^'; +    case BUTTON_DOWN: +      return 'v'; +  } +} + +// display a command +void PrintCommandI(int i, int originY) { +  Robot.text(keyToChar(commands[i]), i%14*8+5, i/14*10+originY); +} + diff --git a/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino b/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino new file mode 100644 index 0000000..58de253 --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino @@ -0,0 +1,73 @@ +/* Robot Line Follow + + This sketch demonstrates the line following capabilities + of the Arduino Robot. On the floor, place some black  + electrical tape along the path you wish the robot to follow. + To indicate a stopping point, place another piece of tape + perpendicular to the path. + + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library + +long timerOrigin; // used for counting elapsed time + +void setup() { +  // initialize the Robot, SD card, display, and speaker  +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); +  Robot.beginSpeaker(); + +  // show the logots on the TFT screen +  Robot.displayLogos(); +   +  Robot.drawBMP("lf.bmp", 0, 0); // display background image + +  Robot.playFile("chase.sqm");  // play a song from the SD card +   +  // add the instructions +  Robot.text("Line Following\n\n place the robot on\n the track and \n see it run", 5, 5); +  Robot.text("Press the middle\n button to start...", 5, 61); +  Robot.waitContinue(); + +  // These are some general values that work for line following  +  // uncomment one or the other to see the different behaviors of the robot +  // Robot.lineFollowConfig(11, 5, 50, 10); +  Robot.lineFollowConfig(14, 9, 50, 10); +   +  //set the motor board into line-follow mode +  Robot.setMode(MODE_LINE_FOLLOW);   +   +  // start +  Robot.fill(255, 255, 255); +  Robot.stroke(255, 255, 255); +  Robot.rect(0, 0, 128, 80); // erase the previous text +  Robot.stroke(0, 0, 0); +  Robot.text("Start", 5, 5); +   +  Robot.stroke(0, 0, 0); // choose color for the text +  Robot.text("Time passed:", 5, 21); // write some text to the screen +   +  timerOrigin=millis(); // keep track of the elapsed time +   +  while(!Robot.isActionDone()) {  //wait for the finish signal +    Robot.debugPrint(millis()-timerOrigin, 5, 29);  // show how much time has passed +  } +   +  Robot.stroke(0, 0, 0);   +  Robot.text("Done!", 5, 45); +} +void loop() { +  //nothing here, the program only runs once. Reset the robot  +  //to do it again! +} diff --git a/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino b/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino new file mode 100644 index 0000000..3574b01 --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino @@ -0,0 +1,179 @@ +/* Disco Bot + + This sketch shows you how to use the melody playing  + feature of the robot, with some really cool 8-bit music.  + Music will play when the robot is turned on, and it  + will show you some dance moves. + + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library + +/* Dancing steps: +  S: stop +  L: turn left +  R: turn right +  F: go forward +  B: go backwards + +  The number after each command determines how long  +  each step lasts. Each number is 1/2 second long. + +  The "\0" indicates end of string +*/ +char danceScript[] = "S4L1R1S2F1B1S1\0";  + +int currentScript = 0; // what step are we at + +int currentSong = 0; // keep track of the current song +static const int SONGS_COUNT = 3; // number of songs + +// an array to hold the songs +char musics[][11] = { +  "melody.sqm", +  "menu.sqm", +  "chase.sqm", +}; + +// variables for non-blocking delay +long waitFrom; +long waitTime = 0; + +void setup() { +  // initialize the Robot, SD card, display, and speaker  +  Robot.begin(); +  Robot.beginSpeaker(); +  Robot.beginSD(); +  Robot.beginTFT(); +  +  // draw "lg0.bmp" and "lg1.bmp" on the screen +  Robot.displayLogos(); +   +  // Print instructions to the screen +  Robot.text("1. Use left and\n right key to switch\n song", 5, 5); +  Robot.text("2. Put robot on the\n ground to dance", 5, 33); + +  // wait for a few soconds +  delay(3000); +   +  setInterface(); // display the current song +  play(0);  //play the first song in the array +   +  resetWait();  //Initialize non-blocking delay +} + +void loop() { +  // read the butttons on the robot +  int key = Robot.keyboardRead(); +   +  // Right/left buttons play next/previous song +  switch(key) { +    case BUTTON_UP: +    case BUTTON_LEFT: +      play(-1);  //play previous song +      break; +    case BUTTON_DOWN: +    case BUTTON_RIGHT: +      play(1);  //play next song +      break; +  } +   +  // dance! +  runScript(); +} + +// Dancing function +void runScript() {  + if(!waiting()) { // if the previous instructions have finished +   // get the next 2 commands (direction and duration) +    parseCommand(danceScript[currentScript], danceScript[currentScript+1]); +    currentScript += 2; +    if(danceScript[currentScript] == '\0') // at the end of the array +      currentScript = 0; // start again at the beginning + } +} + +// instead of delay, use this timer +boolean waiting() { +  if(millis()-waitFrom >= waitTime) +    return false; +  else +    return true; +} + +// how long to wait +void wait(long t) { +  resetWait(); +  waitTime = t; +} + +// reset the timer +void resetWait() { +  waitFrom = millis(); +} + +// read the direction and dirstion of the steps +void parseCommand(char dir, char duration) {  +  //convert the scripts to action +  switch(dir) {  +    case 'L': +      Robot.motorsWrite(-255, 255); +      break; +    case 'R': +      Robot.motorsWrite(255, -255); +      break; +    case 'F': +      Robot.motorsWrite(255, 255); +      break; +    case 'B': +      Robot.motorsWrite(-255, -255); +      break; +    case 'S': +      Robot.motorsStop(); +      break; +  } +  //You can change "500" to change the pace of dancing +  wait(500*(duration-'0')); +} + +// display the song +void setInterface() { +  Robot.clearScreen(); +  Robot.stroke(0, 0, 0); +  Robot.text(musics[0], 0, 0); +} + +// display the next song +void select(int seq, boolean onOff) { +  if(onOff){//select +    Robot.stroke(0, 0, 0); +    Robot.text(musics[seq], 0, 0); +  }else{//deselect +    Robot.stroke(255, 255, 255); +    Robot.text(musics[seq], 0, 0); +  } +} + +// play the slected song +void play(int seq) { +  select(currentSong, false); +  if(currentSong <= 0 && seq == -1) {  //previous of 1st song? +    currentSong = SONGS_COUNT-1;  //go to last song +  } else if(currentSong >= SONGS_COUNT-1 && seq == 1) {  //next of last? +    currentSong = 0;  //go to 1st song +  } else { +    currentSong += seq;  //next song +  } +  Robot.stopPlayFile(); +  Robot.playFile(musics[currentSong]); +  select(currentSong, true);  //display the current song +} diff --git a/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino b/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino new file mode 100644 index 0000000..a7a7315 --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino @@ -0,0 +1,70 @@ +/* Robot Compass + + The robot has an on-board compass module, with + which it can tell the direction the robot is  + facing. This sketch will make sure the robot  + goes towards a certain direction.  +  + Beware, magnets will interfere with the compass + readings. + + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +// include the robot library +#include <ArduinoRobot.h> + +int speedLeft; +int speedRight; +int compassValue; +int direc = 180;  //Direction the robot is heading + +void setup() { +  // initialize the modules +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); +  Robot.displayLogos(); +} + +void loop() {  +  // read the compass orientation +  compassValue = Robot.compassRead(); +   +  // how many degrees are we off +  int diff = compassValue-direc; +   +  // modify degress  +  if(diff > 180) +    diff = -360+diff; +  else if(diff < -180) +    diff = 360+diff; +     +  // Make the robot turn to its proper orientation +  diff = map(diff, -180, 180, -255, 255); +   +  if(diff > 0) { +    // keep the right wheel spinning,  +    // change the speed of the left wheel  +    speedLeft = 255-diff; +    speedRight = 255; +  } else { +    // keep the right left spinning, +    // change the speed of the left wheel    +    speedLeft = 255; +    speedRight = 255+diff; +  } +  // write out to the motors +  Robot.motorsWrite(speedLeft, speedRight); + +  // draw the orientation on the screen +  Robot.drawCompass(compassValue); +} diff --git a/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino b/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino new file mode 100644 index 0000000..1359f8d --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino @@ -0,0 +1,166 @@ +/* Robot Inputs + + This sketch shows you how to use the on-board  + potentiometer and buttons as inputs.  + + Turning the potentiometer draws a clock-shaped  + circle. The up and down buttons change the pitch,  + while the left and right buttons change the tempo.  + The middle button resets tempo and pitch. + + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +// default tempo and pitch of the music +int tempo = 60; +int pitch = 1000; + +void setup() { +  // initialize the Robot, SD card, speaker, and display  +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSpeaker(); +  Robot.beginSD(); + +  // draw "lg0.bmp" and "lg1.bmp" on the screen   +  Robot.displayLogos(); + +  // play a sound file   +  Robot.playFile("Melody.sqm"); +} + +void loop() { +  // check the value of the buttons +  keyDown(Robot.keyboardRead()); + +  // check the value of the pot +  drawKnob(Robot.knobRead()); +} + +// Draw the basic interface +void renderUI() { +  //fill the buttons blank +  Robot.fill(255, 255, 255);       +  Robot.rect(53, 58, 13, 13); // left +  Robot.rect(93, 58, 13, 13); // right +  Robot.rect(73, 38, 13, 13); // up +  Robot.circle(79, 64, 6); // middle +  Robot.rect(73, 78, 13, 13); // down +  Robot.circle(26, 116, 18); // knob + +  //draw the vertical bargraph +  int fullPart=map(pitch, 200, 2000, 0, 58);  //length of filled bargraph +  Robot.fill(255, 255, 255);         +  Robot.rect(21, 30, 13, 58-fullPart); +  Robot.fill(0, 0, 255);         +  Robot.rect(21, 88-fullPart, 13, fullPart); //58-fullPart+30 + +  //draw the horizontal bargraph +  fullPart = map(tempo, 20, 100, 0, 58);  // length of filled bargraph +  Robot.fill(255, 190, 0);   +  Robot.rect(53, 110, fullPart, 13); +  Robot.fill(255, 255, 255);         +  Robot.rect(53+fullPart, 110, 58-fullPart, 13); +} + +void keyDown(int keyCode) { +  // use a static int so it is persistent over time +  static int oldKey; +  switch(keyCode) { +    case BUTTON_LEFT: +      //left button pressed, reduces tempo +      tempo -= 5; +      if(tempo < 20) tempo = 20; //lowest tempo 20 +      Robot.fill(255,190,0); + +      Robot.rect(53, 58, 13, 13); +      break; +    case BUTTON_RIGHT: +      //right button pressed, increases tempo +      tempo += 5; +      if(tempo > 100) tempo = 100; //highest tempo 100 +      Robot.fill(255,190,0); +      Robot.rect(93, 58, 13, 13); +      break; +    case BUTTON_UP: +      //up button pressed, increases pitch +      pitch += 120; +      if(pitch > 2000) pitch = 2000; +      Robot.fill(0, 0, 255); + +      Robot.rect(73, 38, 13, 13); +      break; +    case BUTTON_DOWN: +      //down button pressed, reduces pitch +      pitch -= 120; +      if(pitch < 200){ +        pitch = 200;   +      } +      Robot.fill(0, 0, 255); + +      Robot.rect(73, 78, 13, 13); +      break; +    case BUTTON_MIDDLE: +      //middle button pressed, resets tempo and pitch +      tempo = 60; +      pitch = 1000; +      Robot.fill(160,160,160); + +      Robot.circle(79, 64, 6); +      break; +    case BUTTON_NONE: +      //Only when the keys are released(thus BUTTON_NONE is +      //encountered the first time), the interface will be  +      //re-drawn. +      if(oldKey != BUTTON_NONE){   +        renderUI(); +      } +      break; +  } +  if(oldKey != keyCode) { +    // change the song's tempo +    Robot.tempoWrite(tempo); +    // change the song's pitch +    Robot.tuneWrite(float(pitch/1000.0)); +  } +  oldKey = keyCode; +} + +void drawKnob(int val) { +  static int x = 0, y = 0, val_old = 0; +  // radian number, -3.14 to 3.14 +  float ang = map(val, 0, 1023, -PI*1000, PI*1000) / 1000.0; + +  // erase the old line   +  if (val_old != val) { +    Robot.stroke(255, 255, 255); +    Robot.line(26, 116, x, y); +  } +   +  // the following lines avoid a glitch in the TFT library +  // that seems to appear when drawing a vertical line  +  if (val < 1011 && val > 265 || val < 253) {  +    //a bit math for drawing the hand inside the clock +    x = 16*sin(ang)+26; +    y = 16*cos(ang)+116; +  }  +  if (val > 265 && val < 253) { +    x = 10; y = 116;  +  }     +  if (val >= 1011) { +    x = 27; y = 100;  +  }     +  Robot.stroke(0, 0, 0); +  Robot.line(26, 116, x, y);  +  val_old = val; +} diff --git a/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino b/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino new file mode 100644 index 0000000..c571b3a --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino @@ -0,0 +1,103 @@ +/* 6 Wheel Calibration + + Use this sketch to calibrate the wheels in your robot.  + Your robot should drive as straight as possible when  + putting both motors at the same speed. + + Run the software and follow the on-screen instructions.  + Use the trimmer on the motor board to make sure the  + robot is working at its best! + Circuit: + * Arduino Robot +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // inport the robot librsry +// import the utility library +// a description of its funtionality is below +#include <utility/RobotTextManager.h>  + +// arrays to hold the text for instructions +char script1[] ="Wheel Calibration"; +char script2[] ="1. Put Robot on a\n flat surface"; +char script3[] ="2. Adjust speed with the knob on top"; +char script4[] ="3. If robot goes\n straight, it's done"; +char script5[] ="4. Use screwdriver\n on the bottom trim"; +char script6[] ="- Robot turns left,\n screw it clockwise;"; +char script7[] ="- Turns right, screw it ct-colockwise;"; +char script8[] ="5. Repeat 4 until\n going straight"; + +int speedRobot;  //robot speed +int calibrationValue; //value for calibrate difference between wheels + +void setup(){ +  //necessary initialization sequence +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); +   +  // left and top margin for displaying text +  // see below for a description of this +  textManager.setMargin(5,5); +  // write all instructions at once +  writeAllscript(); +   +} +void loop(){ +  //Control the robot's speed with knob on top +  int speedRobot=map(Robot.knobRead(),0,1023,-255,255); +  Robot.motorsWrite(speedRobot,speedRobot); + +  //read value of the pot on motor baord,to clibrate the wheels +  int calibrationValue=map(Robot.trimRead(),0,1023,-30,30); +  // print the values to the screen +  Robot.debugPrint(calibrationValue,110,145); +  delay(40); + +} + +void writeAllscript(){ +  //prints 8 scripts one after another +  textManager.writeText(0,0,script1); +  textManager.writeText(1,0,script2); +  textManager.writeText(3,0,script3); +  textManager.writeText(5,0,script4); +  textManager.writeText(7,0,script5); +  textManager.writeText(9,0,script6); +  textManager.writeText(11,0,script7); +  textManager.writeText(13,0,script8); +} + +/** +textManager mostly contains helper functions for  +R06_Wheel_Calibration and R01_Hello_User. + +  textManager.setMargin(margin_left, margin_top): +    Configure the left and top margin for text +    display. The margins will be used by  +    textManager.writeText(). +    Parameters: +      margin_left, margin_top: int, the margin values +      from the top and left side of the screen. +    Returns: +      none +     +  textManager.writeText(line,column,text): +    Display text on the specific line and column.  +    It's different from Robot.text() which +    uses pixels for positioning the text. +    Parameters: +      line:int, which line is the text displayed. Each line +        is 10px high. +      column:int,  which column is the text displayed. Each +        column is 8px wide. +      text:a char array(string) of the text to be displayed. +    Returns: +      none +*/ diff --git a/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino b/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino new file mode 100644 index 0000000..9832d29 --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino @@ -0,0 +1,78 @@ +/* Runaway Robot + + Play tag with your robot! With an ultrasonic  + distance sensor, it's capable of detecting and avoiding + obstacles, never bumping into walls again! +   + You'll need to attach an untrasonic range finder to TK1. + + Circuit: + * Arduino Robot + * US range finder like Maxbotix EZ10, with analog output +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +// include the robot library +#include <ArduinoRobot.h> + +int sensorPin = TK1;  // pin is used by the sensor + +void setup() { +  // initialize the Robot, SD card, and display +  Serial.begin(9600); +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); +  Robot.displayLogos(); +   +  // draw a face on the LCD screen +  setFace(true); +} + +void loop() { +  // If the robot is blocked, turn until free +  while(getDistance() < 40) {  // If an obstacle is less than 20cm away +    setFace(false); //shows an unhappy face +    Robot.motorsStop(); // stop the motors +    delay(1000); // wait for a moment +    Robot.turn(90); // turn to the right and try again +    setFace(true); // happy face +  } +  // if there are no objects in the way, keep moving +  Robot.motorsWrite(255, 255);  +  delay(100); +} + +// return the distance in cm +float getDistance() { +  // read the value from the sensor +  int sensorValue = Robot.analogRead(sensorPin); +  //Convert the sensor input to cm. +  float distance_cm = sensorValue*1.27; +  return distance_cm;   +} + +// make a happy or sad face +void setFace(boolean onOff) { +  if(onOff) { +    // if true show a happy face +    Robot.background(0, 0, 255); +    Robot.setCursor(44, 60); +    Robot.stroke(0, 255, 0); +    Robot.setTextSize(4); +    Robot.print(":)"); +  }else{ +    // if false show an upset face +    Robot.background(255, 0, 0); +    Robot.setCursor(44, 60); +    Robot.stroke(0, 255, 0); +    Robot.setTextSize(4); +    Robot.print("X("); +  } +} diff --git a/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino new file mode 100644 index 0000000..fda21cb --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino @@ -0,0 +1,123 @@ +/* 08 Remote Control + + ******************* + *** + ***This example code is in an experimental state. + ***You are welcome to try this with your robot, + ***and no harm will come to it. We will provide a + ***detailed description of an updated version of this + ***in a future update + *** + *** For this example to work you need: + *** + *** - download and install the IR-Remote library by Ken Shirriff + ***   to be found at https://github.com/shirriff/Arduino-IRremote + *** - get a Sony remote control + *** + *** This example will be updated soon, come back to the Robot + *** page on the Arduino server for updates!! + *** + ******************* +  + If you connect a IR receiver to the robot,  + you can control it like you control a TV set.  + Using a Sony compatiable remote control,  + map some buttons to different actions.  + You can make the robot move around without  + even touching it! + + Circuit:  + * Arduino Robot + * Connect the IRreceiver to TDK2 + * Sony compatible remote control + + based on the IRremote library + by Ken Shirriff + http://arcfn.com +  + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +// include the necessary libraries +#include <IRremote.h> +#include <ArduinoRobot.h> + +// Define a few commands from your remote control +#define IR_CODE_FORWARD 0x2C9B +#define IR_CODE_BACKWARDS 0x6C9B +#define IR_CODE_TURN_LEFT 0xD4B8F +#define IR_CODE_TURN_RIGHT 0x34B8F + +int RECV_PIN = TKD2; // the pin the IR receiver is connected to +IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object +decode_results results; // container for received IR codes + +void setup() { +  // initialize the Robot, SD card, display, and speaker  +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); + +  // print some text to the screen +  Robot.stroke(0, 0, 0); +  Robot.text("Remote Control code:", 5, 5); +  Robot.text("Command:", 5, 26); +  irrecv.enableIRIn(); // Start the receiver +} + +void loop() { +  // if there is an IR command, process it +  if (irrecv.decode(&results)) { +    processResult(); +    irrecv.resume(); // resume receiver +  } +} + +void processResult() { +  unsigned long res = results.value; +  // print the value to the screen +  Robot.debugPrint(res, 5, 15); + +  if(res == IR_CODE_FORWARD || res == IR_CODE_BACKWARDS || res == IR_CODE_TURN_LEFT || res == IR_CODE_TURN_RIGHT) { +    Robot.fill(255, 255, 255); +    Robot.stroke(255, 255, 255); + +    Robot.rect(5, 36, 55, 10); +  } +  switch(results.value){ +    case IR_CODE_FORWARD: +      Robot.stroke(0, 0, 0); +      Robot.text("Forward", 5, 36); +      Robot.motorsWrite(255, 255); +      delay(300); +      Robot.motorsStop(); +      break; +    case IR_CODE_BACKWARDS: +      Robot.stroke(0, 0, 0); +      Robot.text("Backwards", 5, 36); +      Robot.motorsWrite(-255, -255); +      delay(300); +      Robot.motorsStop(); +      break; +    case IR_CODE_TURN_LEFT: +      Robot.stroke(0, 0, 0); +      Robot.text("Left", 5, 36); +      Robot.motorsWrite(-255, 255);  +      delay(100); +      Robot.motorsStop(); +      break; +    case IR_CODE_TURN_RIGHT: +      Robot.stroke(0, 0, 0); +      Robot.text("Right", 5, 36); +      Robot.motorsWrite(255, -255);  +      delay(100); +      Robot.motorsStop(); +      break; +  } +} + diff --git a/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino b/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino new file mode 100644 index 0000000..a43348c --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino @@ -0,0 +1,159 @@ +/* Picture Browser + + You can make your own gallery/picture show with the  + Robot. Put some pictures on the SD card, start the  + sketch, they will diplay on the screen.  +  + Use the left/right buttons to navigate through the  + previous and next images.  +  + Press up or down to enter a mode where you change  + the pictures by rotating the robot. +  + You can add your own pictures onto the SD card, and  + view them in the Robot's gallery! + + Pictures must be uncompressed BMP, 24-bit color depth,  + 160 pixels wide, and 128 pixels tall. +  + They should be named as "picN.bmp". Replace 'N' with a  + number between 0 and 9. + + The current code only supports 10 pictures. How would you  + improve it to handle more? + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library + +const int NUM_PICS = 4;  //Total number of pictures in Gallery + +// name the modes +const int CONTROL_MODE_KEY = 0; +const int CONTROL_MODE_COMPASS = 1; + +char buffer[] = "pic1.bmp";  // current file name +int i = 1;  // Current gallery sequence counter +int mode = 0;  // Current mode + +// text to display on screen +char modeNames[][9] = { "keyboard", "tilt    " }; + +void setup() { +  // initialize the Robot, SD card, display, and speaker  +  Robot.beginSD(); +  Robot.beginTFT(); +  Robot.begin(); +   +  // draw "lg0.bmp" and "lg1.bmp" on the screen   +  Robot.displayLogos(); +   +  // draw init3.bmp from the SD card on the screen +  Robot.drawBMP("init3.bmp", 0, 0); + +  // display instructions +  Robot.stroke(0, 0, 0); +  Robot.text("The gallery\n\n has 2 modes, in\n keyboard mode, L/R\n key for switching\n pictures, U/D key\n for changing modes", 5, 5); +  delay(6000); +  Robot.clearScreen(); +  Robot.drawBMP("pb.bmp", 0, 0); +  Robot.text("In tilt mode,\n quickly tilt the\n robot to switch\n pictures", 5, 5); +  delay(4000); +} + +void loop() { +  buffer[3] = '0'+i;// change filename of the img to be displayed +  Robot.drawBMP(buffer, 0, 0); // draw the file on the screen +  // change control modes +  switch(mode) {  +    case CONTROL_MODE_COMPASS: +      compassControl(3); +      break; +    case CONTROL_MODE_KEY: +      keyboardControl(); +      break; +  } +  delay(200); +} + +void keyboardControl() { +  //Use buttons to control the gallery +  while(true) { +    int keyPressed = Robot.keyboardRead(); // read the button values +    switch(keyPressed) { +      case BUTTON_LEFT:  // display previous picture +        if(--i < 1) i = NUM_PICS; +        return; +      case BUTTON_MIDDLE:  // do nothing +      case BUTTON_RIGHT:  // display next picture +        if(++i > NUM_PICS) i = 1; +        return; +      case BUTTON_UP:  // change mode +        changeMode(-1); +        return; +      case BUTTON_DOWN:  // change mode +        changeMode(1); +        return; +    } +  } +} + +// if controlling by the compass +void compassControl(int change) { +  // Rotate the robot to change the pictures +  while(true) { +    // read the value of the compass +    int oldV = Robot.compassRead(); +     +    //get the change of angle +    int diff = Robot.compassRead()-oldV; +    if(diff > 180) diff -= 360; +    else if(diff < -180) diff += 360; +     +    if(abs(diff) > change) { +      if(++i > NUM_PICS) i = 1; +      return; +    } +     +    // chage modes, if buttons are pressed +    int keyPressed = Robot.keyboardRead(); +    switch(keyPressed) { +      case BUTTON_UP: +        changeMode(-1); +        return; +      case BUTTON_DOWN: +        changeMode(1); +        return; +    } +    delay(10); +  } +} + +// Change the control mode and display it on the LCD +void changeMode(int changeDir) { +  // alternate modes +  mode += changeDir; +  if(mode < 0) {  +    mode = 1; +  } else if(mode > 1) +    mode=0; +     +  // display  the mode on screen   +  Robot.fill(255, 255, 255);   +  Robot.stroke(255, 255, 255); +  Robot.rect(0, 0, 128, 12); +  Robot.stroke(0, 0, 0); +  Robot.text("Control:", 2, 2); +  Robot.text(modeNames[mode], 52, 2); +  delay(1000); +} + diff --git a/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino b/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino new file mode 100644 index 0000000..48044db --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino @@ -0,0 +1,124 @@ +/* Robot Rescue + + In this example, the robot enters the line following mode and + plays some music until it reaches its target. Once it finds the  + target, it pushes it out of the track. It then returns to the  + track and looks for a second target. + + You can make the robot push as many objects as you want to, just + add more to calls to the rescue function or even move that code + into the loop. + + Circuit: + * Arduino Robot + * some objects for the robot to push + * a line-following circuit + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library + +void setup(){ +  // initialize the Robot, SD card, display, and speaker  +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSD(); +  Robot.beginSpeaker(); +  +  // draw "lg0.bmp" and "lg1.bmp" on the screen  +  Robot.displayLogos(); + +  // display the line following instructional image from the SD card +  Robot.drawBMP("lf.bmp", 0, 0); + +  // play the chase music file +  Robot.playFile("chase.sqm"); + +  // add the instructions +  Robot.text("Rescue\n\n place the robot on\n the rescue track\n pushing the\n obstacles away", 5, 5); +  Robot.text("Press the middle\n button to start...", 5, 61); +  Robot.waitContinue(); + +  // start +  Robot.fill(255, 255, 255); +  Robot.stroke(255, 255, 255); +  Robot.rect(0, 0, 128, 80); // erase the previous text +  Robot.stroke(0, 0, 0); +  Robot.text("Start", 5, 5); +   +  // use this to calibrate the line following algorithm +  // uncomment one or the other to see the different behaviors of the robot +  // Robot.lineFollowConfig(11, 5, 50, 10); +  Robot.lineFollowConfig(14, 9, 50, 10); +   +  // run the rescue sequence   +  rescueSequence(); +  Robot.text("Found obstacle", 5, 12); +  // find the track again +  goToNext(); +  Robot.text("Found track", 5, 19); +  // run the rescue sequence a second time +  rescueSequence(); +  Robot.text("Found obstacle", 5, 26); +   +  // here you could go on ... +  +  // write status on the screen +  Robot.stroke(0, 0, 0); +  Robot.text("Done!", 5, 25); +} + +void loop(){ +  //nothing here, the program only runs once. +} + +// run the sequence +void rescueSequence(){ +  //set the motor board into line-follow mode +  Robot.setMode(MODE_LINE_FOLLOW);   +   +  while(!Robot.isActionDone()){  // wait until it is no longer following the line +  } +  delay(1000); + +  // do the rescue operation +  doRescue(); +  delay(1000); +} + +void doRescue(){ +  // Reached the endline, engage the target +  Robot.motorsWrite(200,200); +  delay(250); +  Robot.motorsStop(); +  delay(1000); + +  // Turn the robot  +  Robot.turn(90); +  Robot.motorsStop(); +  delay(1000); +   +  // Move forward +  Robot.motorsWrite(200,200); +  delay(500); +  Robot.motorsStop(); +  delay(1000); +   +  // move backwards, leave the target +  Robot.motorsWrite(-200,-200); +  delay(500); +  Robot.motorsStop(); +} + +void goToNext(){ +  // Turn the robot  +  Robot.turn(-90); +  Robot.motorsStop(); +  delay(1000); +} diff --git a/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino b/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino new file mode 100644 index 0000000..90fbfff --- /dev/null +++ b/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino @@ -0,0 +1,181 @@ +/* Hello User + + Hello User! This sketch is the first thing you see  + when starting this robot. It gives you a warm welcome,  + showing you some of the really amazing abilities of  + the robot, and make itself really personal to you.  + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles +  + This example is in the public domain + */ + +#include <ArduinoRobot.h> // include the robot library +// include the utility function for ths sketch +// see the details below +#include <utility/RobotTextManager.h>   + +char buffer[20];//for storing user name + +void setup(){ +  //necessary initialization sequence +  Robot.begin(); +  Robot.beginTFT(); +  Robot.beginSpeaker(32000); +  Robot.beginSD(); + +  // show the logos from the SD card +  Robot.displayLogos(); +   +  // play the music file +  Robot.playFile("menu.sqm"); + +  // clear the screen +  Robot.clearScreen(); +   +  // From now on, display different slides of  +  // text/pictures in sequence. The so-called +  // scripts are strings of text stored in the +  // robot's memory +   +  // these functions are explained below +   +  //Script 6 +  textManager.writeScript(5, 4, 0);  +  textManager.writeScript(9, 10, 0); +  Robot.waitContinue(); +  delay(500); +  Robot.clearScreen(); + +  //Script 7 +  textManager.writeScript(6, 4, 0); +  textManager.writeScript(9, 10, 0); +  Robot.waitContinue(); +  delay(500); +  Robot.clearScreen(); + +  //Script 8 +  // this function enables sound and images at once +  textManager.showPicture("init2.bmp", 0, 0); +   +  textManager.writeScript(7, 2, 0); +  textManager.writeScript(9, 7, 0); +  Robot.waitContinue(); +  delay(500); +  Robot.clearScreen(); + +  //Script 9 +  textManager.showPicture("init3.bmp", 0, 0); +  textManager.writeScript(8, 2, 0); +  textManager.writeScript(9, 7, 0); +  Robot.waitContinue(); +  delay(500); +  Robot.clearScreen(); + +  //Script 11 +  textManager.writeScript(10, 4, 0); +  textManager.writeScript(9, 10, 0); +  Robot.waitContinue(); +  delay(500); +  Robot.clearScreen(); + +  //Input screen +  textManager.writeScript(0, 1, 1); +  textManager.input(3, 1, USERNAME); +   +  textManager.writeScript(1, 5, 1); +  textManager.input(7, 1, ROBOTNAME); + +  delay(1000); +  Robot.clearScreen(); +   +  //last screen +  textManager.showPicture("init4.bmp", 0, 0); +  textManager.writeText(1, 2, "Hello"); +  Robot.userNameRead(buffer); +  textManager.writeText(3, 2, buffer); + +  textManager.writeScript(4,10,0); + +  Robot.waitContinue(BUTTON_LEFT); +  Robot.waitContinue(BUTTON_RIGHT); +  textManager.showPicture("kt1.bmp", 0, 0); +} + +void loop(){ +  // do nothing here +} + + +/** +textManager mostly contains helper functions for  +R06_Wheel_Calibration and R01_Hello_User. + +The ones used in this example: +  textManager.setMargin(margin_left, margin_top): +    Configure the left and top margin for text +    display. The margins will be used for  +    textManager.writeText(). +    Parameters: +      margin_left, margin_top: the margin values +      from the top and left side of the screen. +    Returns: +      none +     +  textManager.writeScript(script_number,line,column): +    Display a script of Hello User example.  +    Parameters: +      script_number: an int value representing the  +        script to be displayed. +      line, column: in which line,column is the script +        displayed. Same as writeText(). +    Returns: +      none +   +  textManager.input(line,column,codename): +    Print an input indicator(">") in the line and column, +    dispaly and receive input from a virtual keyboard, +    and save the value into EEPROM represented by codename +    Parameters: +      line,column: int values represents where the input +        starts. Same as wirteText(). +      codename: either USERNAME,ROBOTNAME,CITYNAME or +        COUNTRYNAME. You can call Robot.userNameRead(), +        robotNameRead(),cityNameRead() or countryNameRead() +        to access the values later. +    Returns: +      none; +   +  textManager.writeText(line,column,text): +    Display text on the specific line and column.  +    It's different from Robot.text() as the later +    uses pixels for positioning the text. +    Parameters: +      line:in which line is the text displayed. Each line +        is 10px high. +      column:in which column is the text displayed. Each +        column is 8px wide. +      text:a char array(string) of the text to be displayed. +    Returns: +      none +       +    textManager.showPicture(filename, x, y): +      It has the same functionality as Robot.drawPicture(), +      while fixing the conflict between drawPicture() and  +      sound playing. Using Robot.drawPicture(), it'll have +      glitches when playing sound at the same time. Using +      showPicture(), it'll stop sound when displaying  +      picture, so preventing the problem. +      Parameters: +        filename:string, name of the bmp file in sd +        x,y: int values, position of the picture +      Returns: +        none   +     +*/ | 
