Old Spice

My Robot About Me Lab 1 Part 1 Lab 1 Part 2 Lab 1 Part 3 Lab 1 Part 4 Lab 1 Part 5 "Old Spice" Lab 1 Part 6 "Robot Behaviors" Lab 1 Part 7 "Robot Games" Lab 1 part 8 "Alien Code - Pre-Lab in Download" Lab 1 part 9 "HCI Project - Pre-Lab in Download"


My Robot


About Me


Lab 1 part 1 - Drawing - Group: Henry, Danzel, Jon, and Kushaan

Lab 1 part 2 - Sensors - Group: Kevin Yang, Josh Cheng, Tanner Zigrang


My Sensor Readings

Lights (left, center, right) 64773,64633,65265
Line Sensor 0,0
IR Sensors 1,1
Fluke Sensors 0,0,0
Battery 7.33987

Josh Chung:

Lights (left, center, right) 65322, 65192, 65284
Line Sensor 1,0
IR Sensors 1,1
Fluke Sensors 0,0,0
Battery 7.19688

Kevin Yang:

Lights (left, center, right) 65151, 65288, 65056
Line Sensor 1,0
IR Sensors 1,1
Fluke Sensors 0,0,0
Battery 7.33987

Tanner Zigrang:

Lights (left, center, right) 65403, 65281, 65283
Line Sensor 1,0
IR Sensors 1,1
Fluke Sensors 0,0,0
Battery 7.33987

Kevin Yang Josh Chung Tanner Zigrang

Lab 1 part 3 - Sensors & If, While, and For Statements

 
#include 
#include 
#include 
#include 

using namespace std;
	
int main(int argc, char **argv) {
	connect("/dev/tty.Fluke2-022C-Fluke2");
	double centerObstacle = robot.getObstacle("center");
	double battery = robot.getBattery();
	cout << battery << endl;
	cout << robot.getLine()[0] << "," << robot.getLine()[1] << endl;  //shows your on smooth surface or not 0 is smooth
	cout << robot.getLight("left") << "," << robot.getLight("center") << "," << robot.getLight("right") << endl; //shows how far in front object is in front
   	cout << robot.getIR()[0] << "," << robot.getIR()[1] << endl; //gets whats behind, detects long range
	while (battery >= 6.1) {
       	battery = robot.getBattery();
       	if (centerObstacle == 0) {
       		robot.forward(1, 1);
           	centerObstacle = robot.getObstacle("center");
        } else {
           	for (int n=1; n<=10; n++) {
                robot.rotate(5);
            }
           	centerObstacle = robot.getObstacle("center");
			disconnect();
			return 0;
		}
	}
} 

Lab 1 part 4 - Fibonacci


#include 
#include 

//Function to compile: g++ `myro-cpp-config --cflags --libs` Fibonacci.cpp -o Driver -I/opt/X11/include

using namespace std;

//Returns fibonacci segment
int fibonacci(int n) {
	//error
	if (n <= 0) {
		return -1;
	//If number is 1 or 2 it returns 1
	} else if (n == 1 || n == 2) {
		return 1;
	//If number is 3 or above, it adds first two values together
	} else {
		return fibonacci(n-2) + fibonacci(n-1);
	}
}

//Calculates time needed for robot to complete quarter circle
double calculateTimetoDraw(int radius) {
	double timeToDraw = radius * (1.15);
	return timeToDraw;
}

//Calculates rotation needed for robot to complete quarter circle
double calculateRotationSpeed(int radius) {
	double rotation = ((radius-1) * 1.0)/radius;
	cout << rotation << endl;
	return rotation;
}

//Draws a quarter circle with a length radius
void drawQuarterCircle(int radius) {
	double time = calculateTimetoDraw(radius);
	double rotationSpeed = calculateRotationSpeed(radius);
	//cout << rotationSpeed << endl;
	//Moves robot for a time at a certain rotation
	while(timeRemaining(time)) {
		robot.motors(rotationSpeed, 1);
	}
	robot.stop();
}

//Asks user for number of segments user wants in Fibonacci Spiral
int askNumberOfSegments() {
	cout << "How many segments of a Fibonacci Spiral should I draw?" << endl;
	string input = "";
	cin >> input;
	//converts string to integer
	return atoi(input.c_str());
}

//Creates Fibonacci Image using scribbler
int main(int argc, char *argv[]) {
	connect("/dev/tty.Fluke2-024D-Fluke2");
	
	//Puts number of segments inputed by user into variable
	int numberOfSegments = askNumberOfSegments();
	
	//Runs Fibonacci sequence for number of segments and draws quarter circle
	for (int i =1; i <= numberOfSegments; i++) {
		drawQuarterCircle(fibonacci(i));
	}
	disconnect();
	return 0;
}

Lab 1 part 5 - Video Performance Talent Show of Old Spice

Video Performance Old Spice Code Download Link

Pre-Lab

1.	The song will be the whistle from Old Spice.  It will come after the robot drawing.

2.	My robot will draw “HELLO LAdIES” and will be executed after the robot tests many of the sensors.

3.	The robot dances by making different lines forward and backward depending on whether an obstacle is in the way and a random number of circles of random radii.

4.	My algorithm will be divided into draw(), songOldSpice(), and surprise().  It will use all the sensors in order to complete the assignment.


#include 
#include 
#include 

using namespace std;

// Travel in a straight line for distance inches
void travelStraightForward(double distance) {
	// set up your robot’s speed
	double inchesPerSec = 1;
	// Travel in a straight line for distance inches
	robot.forward(1, distance/inchesPerSec);
}

//Travel in a straight line for distance inches
void travelStraightBack(double distance) {
	// set up your robot’s speed
		double inchesPerSec = 1;
		// Travel in a straight line for distance inches
		robot.backward (1, distance/inchesPerSec);
}

// Spin 90 degrees right
void ninetyDegreeTurnRight() {
	robot.turnRight(1, .8);
}

//Spin 90 degrees left
void ninetyDegreeTurnLeft() {
	robot.turnLeft(1, .8);
}

//Draws H starting from bottom left corner
void drawH() {
	ninetyDegreeTurnLeft();
	travelStraightForward(1.0);
	travelStraightBack(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	travelStraightBack(1.0);
	ninetyDegreeTurnRight();
}


//Draws E starting from bottom left corner
void drawE() {
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	travelStraightBack(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	travelStraightBack(0.5);
	ninetyDegreeTurnLeft();
	travelStraightBack(1.0);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
}

//Draws L starting from bottom left corner
void drawL() {
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(1.0);
	travelStraightBack(1.0);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.1);
	travelStraightBack(0.1);
	ninetyDegreeTurnRight();
	
}

//Draws O starting from bottom left corner
void drawO() {
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(1.0);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(1.0);
	ninetyDegreeTurnLeft();
	travelStraightBack(0.5);
	travelStraightForward(0.5);
}

//Draws space starting from bottom left corner
void space() {
	travelStraightForward(1.5);
}

//Draws A starting from bottom left corner
void drawA() {
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	travelStraightBack(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(1.0);
	ninetyDegreeTurnLeft();
}

//Draws D starting from bottom left corner
void drawD() {
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	travelStraightBack(1.0);
	ninetyDegreeTurnRight();
	travelStraightBack(0.5);
	travelStraightForward(0.5);
}

//Draws I starting from bottom left corner
void drawI() {
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.1);
	travelStraightBack(0.1);
	ninetyDegreeTurnRight();
	travelStraightForward(0.2);
	ninetyDegreeTurnLeft();
	travelStraightForward(1.0);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.2);
	travelStraightBack(0.5);
	travelStraightForward(0.2);
	ninetyDegreeTurnLeft();
	travelStraightForward(1.0);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.2);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.1);
	travelStraightBack(0.1);
	ninetyDegreeTurnRight();
}


//Draws S starting from bottom left corner
void drawS() {
	travelStraightForward(1.0);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnLeft();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(0.5);
	ninetyDegreeTurnRight();
	travelStraightForward(1.0);
}

//Draws HELLO LADIES
void drawHelloLadies() {
	drawH();
	drawE();
	drawL();
	drawL();
	drawO();
	space();
	drawL();
	drawA();
	drawD();
	drawI();
	drawE();
	drawS();
}

//Plays Old Spice Whistle
//E E B E C# E F# E
void songOldSpice() {
	robot.beep(0.1, 659.26);
	robot.beep(0.1, 659.26);
	robot.beep(0.1, 987.77);
	robot.beep(0.1, 659.26);
	robot.beep(0.1, 554.37);
	robot.beep(0.1, 659.26);
	robot.beep(0.1, 739.99);
	robot.beep(0.2, 659.26);
} 

//Calculates time needed for robot to complete circle
double calculateTimetoDraw(int radius) {
	double timeToDraw = radius * (3.15);
	return timeToDraw;
}

//Calculates rotation needed for robot to complete circle
double calculateRotationSpeed(int radius) {
	double rotation = ((radius-1) * 1.0)/radius;
	//cout << rotation << endl;
	return rotation;
}

//Draws Circle ends at starting point
void drawCircle(int radius) {
	double time = calculateTimetoDraw(radius);
	double rotationSpeed = calculateRotationSpeed(radius);
	//cout << rotationSpeed << endl;
	//Moves robot for a time at a certain rotation
	while(timeRemaining(time)) {
		robot.motors(rotationSpeed, 1);
	}
	robot.stop();
}


//Draws a random number of circles and lines of random sizes, then makes a random number of beeps
//of random frequencies
void surprise() {
	double centerObstacle = robot.getObstacle("center");
	for(int i =1; i <= (3+(rand() % 10)); i++) {
		if (centerObstacle == 1) {
			travelStraightBack(rand() % 2);
			drawCircle(rand() % 2);
		} else {
		drawCircle(rand() % 2);
		travelStraightForward(rand() % 2);
		}
	}
	for(int i =1; i <= (3+(rand() % 10)); i++) {
		robot.beep(.2, 261.63 + (10*(rand() % 5)));
	}
}

//Runs Talent Show: Draws Hello Ladies, beeps OldSpice whistle, and draws random stuff
int main(int argc, char **argv) {
	//Connects to robot
	connect("/dev/tty.Fluke2-02B3-Fluke2");
	//robot.setName("Old Spice");
	//cout << "Hello, Ladies my name is " << robot.getName() << "!\n";
	
	cout << "Hello, Ladies my name is Old Spice" << endl;
	
	double battery = robot.getBattery();
	double surfaceSmoothness = robot.getLine()[0];
	double howFarInFront = robot.getLight("center");
	double backObstacle = robot.getIR()[0];
	cout << "Now look at your man now back to me, now back at your man, now back to me, now at the grounds smoothness.  It is: " << endl; 
	cout << surfaceSmoothness << endl;
	cout << "smooth. Interesting... Sadly your man isn't me, but if he stopped using ladies scented body wash and switched to Old Spice, he could tell you how far in front an obstacle was.  It is: " << endl;
	cout << howFarInFront << endl;
	cout << "Amazing! Behind me my sensors read: " << endl;  
	cout << backObstacle << endl;
	cout << "Now, Look down, back up, where are you? You're on a boat with the man your man could smell like. What's in your hand, back at me. I have it, it's an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I'm on a horse." << endl;
	//Text from: http://lybio.net/old-spice-the-man-your-man-could-smell-like/commercials/
	//I DO NOT OWN ANY OF TEXT IN QUOTATIONS OR THE WHISTLE FREQUENCIES!
	//ALL RIGHTS IN TEXT GO TO Old Spice
	//ENJOY!
	
	if (battery >= 6.1) {
		drawHelloLadies();
		songOldSpice();
		surprise();
	}
	
	//Disconnects from robot
	disconnect();
	//Ends function
	return 0;
}	

Lab 1 part 6 - Robot Behaviors

Code Download Link

Group: Jery Webb, Mike Ciesielka, Kristen McNeal

Code:

#include 
#include 

using namespace std;

//Initializes Ambient
double Ambient;
//Normalizes light to value between 0 and 1
double normalize(int v) {
	if (v > Ambient) { 
		v = Ambient;	
	}
	return 1.0 - v/Ambient;
}

//Alive function moves faster under brighter light
void alive() {
	Ambient = robot.getLight("center");
	while (true) {
			int L = robot.getLight("center");
			robot.forward(normalize(L));
	}
}

//Coward function moves away from light
void coward() {
	Ambient = (robot.getLight("left") + robot.getLight("center") + robot.getLight("right"))/3;
	while (true) {
		int L = robot.getLight("left");
		int R = robot.getLight("right");
		cout << "Right" << R << endl;
		cout << "Left" << L << endl;
		robot.motors((-1)*normalize(R), (-1)*normalize(L));
	}
}

//Aggressive function moves towards light
void aggressive() {
	Ambient = (robot.getLight("left") + robot.getLight("center") + robot.getLight("right"))/3;
	while (true) {
		int L = robot.getLight("left");
		int R = robot.getLight("right");
		cout << "Right" << R << endl;
		cout << "Left" << L << endl;
		robot.motors((-1)*normalize(L), (-1)*normalize(R));
	}
}

//Love function goes straight until light hits, then moves toward light
void love() {
	Ambient = (robot.getLight("left") + robot.getLight("center") + robot.getLight("right"))/3;
	while (true) {
		int L = robot.getLight("left");
		int R = robot.getLight("right");
		cout << "Right" << R << endl;
		cout << "Left" << L << endl;
		robot.motors((-1)*(1-normalize(R)), (-1)*(1-normalize(L)));
	}
}

//Explorer function goes straight until light hits, then move away from light then keeps going
void explorer() {
	Ambient = (robot.getLight("left") + robot.getLight("center") + robot.getLight("right"))/3;
	while (true) {
		int L = robot.getLight("left");
		int R = robot.getLight("right");
		cout << "Right" << R << endl;
		cout << "Left" << L << endl;
		robot.motors((-1)*(1-normalize(L)), (-1)*(1-normalize(R)));
	}
}

//Runs functions
int main(int argc, char **argv) {
	int num = 0;
	connect("/dev/tty.Fluke2-0247-Fluke2");
	cout << "Enter 1 for Alive behavior" << endl;
	cout << "Enter 2 for Coward behavior" << endl;
	cout << "Enter 3 for Aggressive behavior" << endl;
	cout << "Enter 4 for Love behavior" << endl;
	cout << "Enter 5 for Explorer behavior" << endl;
	cin >> num;
	if (num==1) {
		alive();
	} else if (num==2) {
		coward();
	} else if (num==3) {
		aggressive();
	} else if (num==4) {
		love();
	} else if (num==5) {
		explorer();
	} else {
		cout <<"Input Error" << endl;
	}
	disconnect();
	return 0;
}

Lab 1 part 7 "Robot Games"

Prelab: 1. For the robot opening ceremony, we will use the W,A,S, and D keys to move the robot around. The F key will be used to stop the robot, and the P key will have the robot sing the fight song. No sensors will be used for this exercise because all of the robot's commands will be given manually through the keyboard. 2. For the line drawing event, the robot is moves backwards, since the line sensors are located near the back of the robot; this allows for more precise movements. Inside a while-loop, the robot continuously checks to see what value each line sensor is returning, and it feeds these values into the robot.move() function. By treating the left line sensor as a negative value and the right line sensor as positive, and adding them together to form the ROTATE_SPEED of the robot, the robot will move straight if both sensors detect a line(-1+1=0), left if only the left sensor detects a line(-1+0=-1) and right if only the right sensor detects a line(0+1=1). The robot moves slowly to prevent veering too far off the line, and in the case that neither sensors detect a line, it will quickly move backwards in order to try to find the line again. Write a description of your robot’s Maze Solving ability. What is your algorithm and sensors used for this event? Maze algorithm: the robot moves forward until it gets to a certain distance from the wall. Then it turns right and checks or an obstacle. If there is no obstacle, it moves forward. If there is, it turns 180 degrees and continues straight. 3. Write a description of your robot’s Fastest Drawer behavior. What is your algorithm and/or sensors used for this event? My algorithm is travel straight forward sixtyTurnLeft, travelStraightForward, sixtyTurnLeft, travelStraightForward, sixtyTurnLeft, travelStraightBack, sixtyTurnRight, smallTriangleLeft, sixtyTurnRight, travelStraightBack, sixtyTurnLeft, travelStraightForward, sixtyTurnLeft, smallTriangleRight, sixtyTurnLeft, travelStraightForward, sixtyTurnLeft, travelStraightBack, sixtyTurnLeft, travelStraightBack, sixtyTurnRight, travelStraightForward, sixtyTurnLeft, travelStraightForward, sixtyTurnRight, travelStraightBack for long distance, sixtyTurnRight, travelStraightForward for long distance. 4. Structuring Code: Have separate functions controlling each behavior. Called on by user input.


Kevin Yang Josh Chung Tanner Zigrang

Code Download Link

Lab 1 part 7 "USAR Project"

Code Download Link

Lab 1 part 8 "Alien Code - Pre-Lab in Download"

Code Download Link

Lab 1 part 9 "HCI Project - Pre-Lab in Download"

Code Download Link

Valid XHTML 1.0 Transitional!Valid CSS!

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