Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wall Encounter By www.owlnet.rice.edu Made easy by Dwayne Abuel.

Similar presentations


Presentation on theme: "Wall Encounter By www.owlnet.rice.edu Made easy by Dwayne Abuel."— Presentation transcript:

1 Wall Encounter By www.owlnet.rice.edu Made easy by Dwayne Abuel

2 Psuedo Code This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off.

3 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ Setting up the commands by initializing. The set up here is giving values to each named item or VARIABLE, for example, “TRUE = 1”. These setup the condition to which a robot will function. This will help slim down the program and cut on the tedious task of typing it all in. Also, this is so that you don’t have to go back and keep looking at what port things are plugged into. Just remember the named item. RIGHT_MOTOR_PORT is a named item or VARIABLE. 1 is a value assigned to RIGHT_MOTOR_PORT. Int is a command to initialize something.

4 Wall Encounter void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ Open bracket to contain program. There may be several packets to contain commands which will be separated with open and close brackets. Start of program begins with VOID main (). Close bracket to contain program.

5 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ RIGHT_MOTOR_PORT, Do you see where it was used? LEFT_MOTOR_PORT, Do you see where it was used? WALL_SENSOR_PORT, Do you see where it was used?

6 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ AO or “All Off” turns off all motors on all ports. Sleep is a timer command and does not put the robot to sleep, rather it allows for something to be timed.

7 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ Initializing computer with selected.

8 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */

9 Wall Encounter /*This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ Wait one second after hit. All motors off. HIT!

10 Wall Encounter /* This program makes the robot move forward until it hits a wall, wait one second, reverse for 3 seconds, then turn off. */ /* CONSTANT DECLARATIONS */ int WALL_SENSOR_PORT = 2; /* use input 6 for this sensor */ int LEFT_MOTOR_PORT = 0; /* use motor port 2 */ int RIGHT_MOTOR_PORT = 1; /* use motor port 2 */ int TRUE = 1; int FALSE = 0; /* PROGRAM CODE */ void main() { forward(LEFT_MOTOR_PORT); forward(RIGHT_MOTOR_PORT); while (!digital(WALL_SENSOR_PORT)); /* This will check to see if sensor switch is depressed. When it's not pressed, the robot will continue forward. */ ao(); /* turn motors off */ sleep(1.0); /* motors off for 1 second before reversing */ reverse(LEFT_MOTOR_PORT); reverse(RIGHT_MOTOR_PORT); sleep(3.0); /* motors go in reverse for 3 seconds */ ao(); /* turn both motors off */ } /* end of main */ Reverse for 3 sec. All motors turn off.


Download ppt "Wall Encounter By www.owlnet.rice.edu Made easy by Dwayne Abuel."

Similar presentations


Ads by Google