 #### Robots Got Talent

##### Prelab questions:

1. The song my robot will sing is 32 total notes long. The notes are to be selected at random, as is the duration of each note.

2. My robot will draw a bow tie by going back and forth across the white board. The basis of this algorithm is that the robot is in a while loop until it has completed the bowtie.

3. The surprise portion of my performance is that after one of the two main segments, my robot starts to run off, and an obstacle avoiding algorithm is started. This runs for the length of 5 total 180 degree turns for the robot, at which point Blimpie "surrenders".

4. The general structure of the performance is randomized, as the program can choose any one of the three components to go first, and then it will continuously select at random amongst the remaining two, and then it will have the remaining portion go last.

My video can be found at this this link

My code follows: ``` #include #include #include #include #include using namespace std; int main(int argc, char ** argv) { int selector; bool stagefright = false; bool drawing = false; bool singing = false; bool running = false; bool finish = false; connect("/dev/tty.Fluke2-01C7-Fluke2"); robot.beep(0.2,990); cout << "The battery level is: " << endl; cout << robot.getBattery() << endl; cout << "Welcome to the Robot talent show" << endl; selector = rand() % 3 + 1; while(!finish) { if(selector == 1) { if(stagefright){ cout << "Slowly, Blimpie recovers from his traumatic experience" << endl; } cout << "The song portion. Performing an original piece is Blimpie" << endl; int noteNum; int beatNum; for(int i = 1; i < 32; i++) //Randomly Generated Song, 32 Notes { noteNum = rand() % 7 + 1; beatNum = rand() % 4; if(noteNum == 1) { //A robot.beep(beatNum*0.5,880.00); cout << "A, " ; } else if(noteNum == 2) { //B robot.beep(beatNum*0.5,987.77); cout << "B, " ; } else if(noteNum == 3) { //C robot.beep(beatNum*0.5,1046.50); cout << "C, "; } else if(noteNum == 4) { //D robot.beep(beatNum*0.5,1174.66); cout << "D, " ; } else if(noteNum == 5) { //E robot.beep(beatNum*0.5,1318.51); cout << "E, "; } else if(noteNum == 6) { //F robot.beep(beatNum*0.5,1396.91); cout << "F, " ; } else if(noteNum == 7) { //G robot.beep(beatNum*0.5,1567.98); cout << "G, " ; } } stagefright = false; if(!drawing && !running) { selector = rand () % 2 + 2; } else if(drawing && !running) { selector = 3; } else if(!drawing && running) { selector = 2; } singing = true; if(singing && drawing && running) { finish = true; } } else if(selector == 2) { int counter = 0; if(stagefright){ cout << "Slowly, Blimpie recovers from his traumatic experience" << endl; } cout << "Blimpie will now be crafting a beautiful work of art" << endl; while(counter < 4) { //Drawing of a bowtie robot.forward(1,0.05); robot.turnLeft(1,.733/9); robot.forward(1,0.05); robot.turnLeft(1,.733); robot.forward(1,2); //Crossed page robot.turnRight(1,.733); robot.forward(1,0.05); robot.turnRight(1,.733/9); robot.forward(1,0.05); robot.turnRight(1,.733); robot.forward(1,2); //Crossed page robot.turnRight(1,.733); robot.forward(1,0.05); robot.turnRight(1,.733/9); robot.forward(1,0.05); robot.turnRight(1,.733); robot.forward(1,2); //Crossed page robot.turnLeft(1,.733); counter ++; } stagefright = false; if(!singing && !running) { selector = 3; } else if(!singing && running) { selector = 1; } else if(singing && !running) { selector = 3; } drawing = true; if(singing && drawing && running) { finish = true; } } else if(selector == 3) { int turnaround; cout << "Suddenly, Blimpie got stage fright! Run, Blimpie, run away!" << endl; for(int i = 1; i < 5; i++) { //Surprise portion, Blimpie runs away from obstacles he encounters while(turnaround < 6) { if(robot.getObstacle("center") < 6400) { robot.getObstacle("center"); robot.beep(0.2,990); robot.forward(1,1); } else if(robot.getObstacle("center") == 6400) { cout << "RUN AWAY!!!" << endl; robot.turnLeft(1,1.53); turnaround ++; cout << 6 - turnaround << endl; if(turnaround == 6) { cout << "I surrender" << endl; } } } } stagefright = true; if(!singing && !drawing) { selector = rand() % 2 + 1; } else if(!singing && drawing) { selector = 1; } else if(singing && !drawing) { selector = 2; } running = true; if(running && drawing && singing) { finish = true; } } } disconnect(); return 0; } ```
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees