1 / 11

Touch Sensors in Electrical & Computer Engineering: Programming and Applications

Learn to utilize touch sensors in robotics projects. Write an IC program for intelligent robot turning. Includes code examples and classwork exercises for practical application.

rdexter
Download Presentation

Touch Sensors in Electrical & Computer Engineering: Programming and Applications

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. Touch Sensors • Is a type of digital sensor: - Returns a 0 if NOT hit - Returns a 1 if HIT - As with any digital sensor, it is either “ON” or “OFF” - Digital sensors connect to digital ports (7-15) on the “lower deck” of the handyboard (see diagram of the handyboard on the next slide)

  3. Digital Ports

  4. Touch Sensor • Digital sensor • Connect to digital ports 8-15 on the KIPR Link • Access with functiondigital(port#) • 1 indicates switch is closed • 0 indicates switch is open

  5. Utilizing the touch sensor to help robot turn intelligently • Write an IC program that does the following: • runs forward for an unspecified amount of time • detects a “hit” using a digital sensor attached to the front of the robot and then backs up (for x seconds --- you decide what number is best for x – HINT use a variable!) • Download and run

  6. Simple Example To Use Bumpers // Program to make a robot go forward. // If hit detected, go backwards for 4 seconds. int main() { while( a_button()==0 ){ } // Waits for user to press start button. while(1) { motor (1,70); // Turn on motor 1, @ 3% of speed. motor (3,70); // Turn on motor 3, @ 3% of speed. if ( digital(13)==1 ) // Check sensor connected to port { motor (1, -70); // Turn on motor 1, @ 3% of speed in opposite direction. motor (3, -70); // Turn on motor 1, @ 3% of speed in opposite direction. sleep(4); } return 0 }

  7. Classwork • AA1FB int main() { fd(0); fd(2); sleep(3); bk(0); bk(2); sleep(3); ao(); }

  8. Classwork • AA2Sen int main(){ while(1){ printf("Sensor reading : %d\n", analog10(0)); msleep(500); } return 0; }

  9. Classwork • AA3FSenB_once int main(){ intcolor_threshold = 200; while(1){ if(analog10(0) > color_threshold&& analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } • bk(0); • bk(2); • sleep(2); • ao(); • return 0; • }

  10. Classwork • AA4FSenB_loop int main(){ intcolor_threshold = 200; while(1){ while(1){ if(analog10(0) > color_threshold && analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } bk(0); bk(2); sleep(2); ao(); msleep(100); } return 0; }

  11. Classwork • AA5SenB_three int main(){ intcolor_threshold = 200; int n = 1; while(n <= 3){ while(1){ if(analog10(0) > color_threshold && analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } bk(0); bk(2); sleep(2); ao(); n = n+1; msleep(100); } return 0; }

More Related