Download presentation
Presentation is loading. Please wait.
Published byChristopher Kelley Modified over 7 years ago
1
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4
2
Class Outline Programming Left/Right Turn Capabilities for the Robot
Light Sensor Applications
3
(Before going on, let’s make robot go forward and backwards first!)
Turning (Before going on, let’s make robot go forward and backwards first!) 20 - Minutes
4
Implementing Turning Number of different ways to turn:
1. Turn only one motor on, and leave it running for ‘X’ amount of seconds. X is determined by experimenting with your particular robot. motor(1, 80); // Turning motor 1 80%. sleep(X);
5
Turning continued… 2. One motor forward, opposite motor backwards, and then leave for X seconds. motor(1, 80); // Motor 1 goes 80%. motor(3, -80); // Motor 3 goes 80%. sleep(X); // X determined experimentally by // programmers/designers. Although not as efficient, you can also turn by having both motors going in the same direction, but at different speeds.
6
Calculating the time, X Write a short program to make a robot turn, using one of the mentioned techniques. Put X = 2.0, and run the program. See how much the robot turns. Change the value of X accordingly. If turn is much greater then 90 degrees, lessen the time, X. If it is smaller, put a larger time. Keep repeating until your robot executes a near perfect 90 degree turn.
7
Loops
8
2 Different Types of Loops
To repeat a group of commands until a condition is no longer true, we use a WHILE loop To repeat a group of commands a predefined # of times, we use a FOR loop Examples: while (side_button()==0) { beep(); } for (int count=0; count<=4; count++) { beep() ; } WHILE LOOP FOR LOOP
9
Block Diagram For a Right Turn
Go Forward Turn Right? No Yes Turn Right
10
Flow Chart to Code for Turning Right
while (true) { // go forward motor ( 1, 100 ) ; motor ( 3, 100 ) ; // should we turn right? if ( analog(4) > 200 ) // turn RT, until off black tape ao() ; while (analog(4) > 200) motor (3, 100) ; } Go Forward Turn Right? No Yes Turn Right Flow Chart C Code Implementation of Flow Chart
11
Block Diagram For a Right Turn or Left Turn
Go Forward Right turn? Left turn? No No Yes Yes Turn Right Turn Left
12
Block Diagram for a Complete System
Go Forward Right turn? Left turn? No No Yes Yes No Turn Left Turn Right Left turn? Yes STOP
13
Sample Program int main() { int sensor1, sensor3, Flag=1;
printf("Press Start button to begin:"); while(side_button()==0); // Waits for start button to be pressed. while(Flag==1) sensor1=analog(4); // Reads the signal coming from analog port 4. sensor3=analog(6); // Reads the signal coming from analog port 6. motor(1, 10); // GO FORWARD. motor(3, 10);
14
if(sensor1>200) // RIGHT TURN?? { // If Yes then….
if(sensor3>200) // …LEFT TURN?? { // ao(); // Flag=0; // If YES then STOP!!! } else // Right turn = yes BUT Left turn = no, then... { ao(); sleep(2.0); while(analog(4)>200) // Turn RIGHT!! motor(3,100);
15
motor(1,100); else if(sensor3>200) // LEFT TURN???? { ao();
sleep(2.0); while(analog(6)>200) // TURN LEFT motor(1,100); }
16
U-Turn Making the robot U-turn, and go back along the path to the starting point. This can be carried out in the following way: After sensing a black surface on BOTH light sensors, the robot stops, and then starts to rotate in either direction. The robot rotates until the first sensor senses the black line, it CONTINUES rotating, but stops once the second sensor detects the black line. Once the rotation has been completed, the robot moves along the line in the same way as in the main part of the project until it reaches the start line.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.