torstai 13. maaliskuuta 2014

I decided to use Arduino example code Disco Bot for my embedded systems project. Code will be modified. Disco Bot code plays a melody with the robot, by playing back some sound files. You can choose between three melodies specially composed for the Arduino Robot using the buttons on the control board. If you have uploaded your own sounds to SD card you can also play them by adding to code. Once you get the music you like, put the robot on the floor and it will dance for you. By pressing left/right button you can switch music. If you're not satisfied with the dancing moves, change the example to make it dance differently by modifying the line "Char danceScript []="S4L1R1S2F1B1S1\0". Letters meanings are: S: stop, L: turn left, R: turn right, F: go forward, B: go backwards. The number after each command shows how long it lasts. 1 = 500ms, 2=1000ms, 3=1500ms, and so forth. Heres a video about Arduino Robot with Disco Bot code:





Today (27.3.), I modified the robot´s original danceScript, removed some sound files from the code and switched printed texts to my own texts. I tried to get the robot to make in the shape of square figure. I couldn´t get that exactly right because of many reasons. The main reason was that the robot´s wheels weren´t calibrated wery well. When I put the robot to go forward it tilted to right all the time. Well, the main important was that I got my own texts in to the robot´s screen and playing the sounds that I wanted. I also modified the speed of the robot a little bit slower because the robot hit many times to walls and chairs. After I slowed the speed the robot worked quite well. And finally heres the original part of the code that has not been modified and after that the same part with modified:

|____________________________________________________________________________||                                                                                                                                     |

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

char musics[][11] = {
  "melody.sqm",
  "menu.sqm",
  "chase.sqm",
};

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);

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;
  }

|____________________________________________________________________________||                                                                                                                                     |

char danceScript[] = "S1F2R1B1L1\0";

int currentScript = 0; // what step are we at

int currentSong = 0; // keep track of the current song
static const int SONGS_COUNT = 1; // number of songs

char musics[][11] = {
  "menu.sqm",
};

  Robot.text("Muokattu discobotti", 0, 10);
  Robot.text("Koodi by J-P Keskinen", 0, 20);
  Robot.text("Laita robot lattialle", 0, 30);

void parseCommand(char dir, char duration) {
  //convert the scripts to action
  switch(dir) {
    case 'L':
      Robot.turn(-90);
      delay(1000);
      break;
    case 'R':
      Robot.turn(90);
      delay(1000);
      break;
    case 'F':
      Robot.motorsWrite(150, 150);
      delay(1000);
      break;
    case 'B':
      Robot.motorsWrite(150, 150);
      delay(1000);
      break;
    case 'S':
      Robot.motorsStop();
      break;
  }

|____________________________________________________________________________||                                                                                                                                     |

Ei kommentteja:

Lähetä kommentti