330 likes | 418 Views
The George Washington University Department of ECE ECE 1010 Intro: Electrical & Computer Engineering. Introducing Handyboard/Interface and Set-up Continuation of Programming Skills Connecting Handyboard Making sure connections are fine Introduction to analog sensors Dr. S. Ahmadi Week 2.
E N D
The George Washington University Department of ECE ECE 1010Intro: Electrical & Computer Engineering • Introducing Handyboard/Interface and Set-up • Continuation of Programming Skills • Connecting Handyboard • Making sure connections are fine • Introduction to analog sensors Dr. S. Ahmadi Week 2
Outline • PART I • Programming Exercises • Connecting Handyboard • Hands-on Programming • Starting IC Program (Downloading Firmware) • Running Programs • PART II • Introduction to Analog Sensors • Project Description
Hardware Components Handyboard (Interface to motors) RJ-11 Cable (Connection btwn Handyboard & Serial Port Interface) Serial Port Interface (Interface between Handyboard & PC) AC Adapter (Provides power to Serial Port Interface & Handyboard) Serial Port Cable (25pin to 9pin) (Connects “Serial Port Interface Board” to back of PC)
Handyboard Layout LCD Screen (for output from your ROBOT) ON/OFF Button I LOVE ECE001! Download Connector (Connect Serial Port Interface Board to Handy-board here) Ports 0,1,2,3 for MOTORs (Connect a wire from Port 1 to your LEFT motor And another wire from Port 3 to your RIGHT motor)
Connecting the Handyboard • Connect RJ-11 Cord (Phone Cord) to the “Serial Port Interface” and Handy Board. • Connect “Serial Port Interface” to PC via Serial Cord • Start “Interactive C” on PC
Running Interactive C: • Start Menu >> Programs >> Interactive C 4.0
Initially on running the program, you have to choose the hardware you’re going to be working with. Click on the “Handyboard” option.
* Depending on how you connected the Serial Port Interface, choose either com1 or com2, and then “Connect Now”
Overview of Interaction Window Download program to Controller. Stop program currently being run. Run program that is currently in the Controller’s Memory. Single Instruction Entry (Interaction Area)
BASIC HANDYBOARD HOOKUP PROCEDURE • Connect Handy-board to computer. • Turn the Handy-board on. • Open your Interactive C software. Make sure the computer is talking to the controller. • After connecting handy-board, type “beep();” in the interactive window. • If you hear a ‘beep’, your connections are correct.
This is just a simple test, to make sure your connections are correct. • In the single instruction entry, simply type “beep();”. • The command should then be displayed in the History area, and the “Handy-board”should emit a beep.
Start a new File by pressing the “New” button at the top left hand corner of the screen.
Running the same program as the previous example in a new file. • Any program that is written in a new file has to be encapsulated by a main function, as shown, so that the controller knows what to run first. • Inside the actual Main, type the set of commands you wish to run, in this case, “beep();”. • Save the program, and then press the download button. • “Run Main” -> if nothing went wrong, your “Handyboard” should beep. • Note that unlike writing a single command in the Interaction window, programs written in a new file must first be downloaded to the controller’s memory.
If the IC Software does not detect any errors in your program, it should download without any problems. If there is an error, it will not download, but should tell you where the error occurred.
Sample Beeping Program /* Program to beep 20 times continuously. */ void main() { int count=0; while(count<=20) { beep(); count=count+1; // Incrementing counter } } • Extra: Wait half a second between beeps.
Motor control commands • DC motor control commands • fd (n);Rotate motor ‘n’ forward • bk(n); Rotate motor ‘n’ backwards. • motor(n, s); move motor ‘n’ at speed ‘s’ • ‘s’ range: -100 ~ +100 • ‘s’>0 forward • ‘s’<0 reverse • off(n); turn off motor ‘n’ • ao(); turn off all motors
Motor Exercise Procedure • Attach the two motors to the connector wires. Next, attach the wire plugs to Handyboard ports. • Turn the Handyboard on. • Open your Interactive C software. Make sure the computer is talking to the controller. • In interactive window, type “fd(1);” • After making sure motor connected correctly, type “off(1);” • Turn on motor 1 using the motor(n,x) command. • Make motor 1 alternate between a forward and backward direction. • You can change the speed of your motors. For example motor(1,100) means motor 1 is turning at 100 or full speed.
Motor Control: Exercise #1 • Exercise #1: Motor speed control • write IC program to run one motor in three different speeds. • Turn motor #1 on • drive in slow speed for 3 seconds • drive in medium speed for 5 seconds • drive in high speed for 3 seconds • Stop motor
Sample Motor Program (Exercise #2) void main() {printf("Press START to test motors\n"); while(start_button() == 0); //wait until start button is pressedfd(1); // Motor in port 1 go forward sleep(2.0); // Sleep for 2 seconds.bk(1); // Motor in port 1 go backward sleep(2.0);off(1); //turn motor in port 1 off fd(3); // Motor in port 3 go forward sleep(2.0);bk(3); // Motor in port 3 go backward sleep(2.0);off(3); }
Charging The Handyboard • Charging the Handyboard takes 14 hours, after which it can be left in the power indefinitely. • Zapping the Handyboard fully charges it in 4 hours, but it must not be left in power after charging is complete. • Note: Students will be responsible for charging their groups Handyboard.
SUMMARY of Main Functions from Week 2 • fd (n); Rotate motor ‘n’ forward • bk(n); Rotate motor ‘n’ backwards. • motor(n, s); move motor ‘n’ at speed ‘s’ • ‘s’ range: -100 ~ +100 • ‘s’ > 0 – motor moves forward • ‘s’ < 0 – motor reverses/moves backward • off(n); turn off motor ‘n’ • ao(); turn off all motors • sleep(x); // Delays execution of next statement for ‘x’ secs. • msleep(x); // Delays execution of next statement for ‘x’ millisecs. • beep(); // Causes the handy-board to Beep.
Analog Sensors • Outputs a range of integer values. • Range depends on the signal being sensed. • The main analog ports are ports 2 – 6, and ports 20 – 23. • Actual ports that should be used will depend on the sensor being used. • The three main analog sensors that we will be using are the Light Sensor, the Optical Rangefinder Sensor and the Ultrasonic Sensor (aka Sonar). • In today’s project, only the light sensor will be utilized.
Analog Sensor 1: Light Sensor • The light sensor included in the kit, can “sense” lightness and darkness. • Connect to analog ports 2-6 or 20-23 • Access with function analog(port#) • Analog values range from 0 - 255. • A low value indicates bright light or close proximity to a light source • A high value indicates dark light or far proximity from a light source Enlarged Light Sensor
Analog Sensor 2: IR Reflectance Sensor “Top Hat” • The IR sensor included in the kit, can also “sense” lightness and darkness like the light sensor • Connect to analog ports 2-6 or 20-23 • Access with function analog(port#) • Low values indicate bright light, light color, or close proximity • High values indicate low light, dark color, or distance of several inches • Sensor has a reflectance range of about 3 inches Enlarged IR Sensor
Light Sensor Sample Code /* Program that measures the reads from the light sensor and displays its output values continuously. */ void main() { int color=0; printf(“\n Light Sensor Sample Program"); while(!start_button()); // Press Start Button while(1) // Continue infinitely { sleep(0.5); color = analog(6); // Read “lower deck” analog port 6 printf(“\n Color is %d”, color); // if near 0 – WHITE // if near 255 - BLACK } }
Project Description • The aim of this project is to design a robot that moves along a given path, from the Start point, towards the Finish line. • The thick black line acts as the guide for the robot to follow. • As an optional element to the project, after reaching the finish line, the robot should turn around, and go back along the path it came to the starting point. • Robot will be judged on smoothness of journey, and robot design. • It is the students’ responsibility to make sure that the Handy Board is fully charged • Each group will have one chance to demonstrate their project to the judges. Therefore, fully test your project before demonstration.
Project #1 - Route 2m 2m Finish Start 2m 2m