1 / 16

Dr. S. Ahmadi Class 4

The George Washington University Department of ECE ECE 1010 - Intro: Electrical & Computer Engineering. Dr. S. Ahmadi Class 4. Class Outline. Programming Left/Right Turn Capabilities for the Robot Light Sensor Applications. Turning.

halsted
Download Presentation

Dr. S. Ahmadi Class 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The George Washington University Department of ECE ECE 1010 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4

  2. Class Outline Programming Left/Right Turn Capabilities for the Robot Light Sensor Applications

  3. 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 forward @ 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 forward @ 80%. motor(3, -80); // Motor 3 goes backward @ 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() ; • } FOR LOOP WHILE 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. 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.

More Related