The George Washington University Department of ECE ECE 002

advertisement
The George Washington University
Electrical & Computer Engineering Department
ECE 002
Dr. S. Ahmadi
Class 2
Agenda
• Review of Robot Building and Motor Control
– Handyboard connections
– Attaching a motor and controlling it
• Brief Review of 2 Analog Light Based Sensors
– Light Sensor & IR “Top Hat” Sensor
– Review of how to program using sensors
• Introduction to Project #1
–
–
–
–
Description
Obstacle course diagram
Pictures of previous year robot designs
Optional portion of project
Review of Robot Building and
Motor Control
(for students who are new to ECE 001 & ECE 002)
Hardware Components
HANDY-Board
(Interface to motors)
RJ-11 Cable
(Connection btwn Handyboard
& Serial Port Interface)
Serial Port Interface
(Interface between
Handyboard & Robot)
AC Adapter
(Provides power to Serial
Port Interface & Handyboard)
Serial Port Cable
(Connects “Serial Port Interface Board” to back of PC)
HANDY-Board Layout
LCD Screen
(for output from your ROBOT)
ON/OFF Button
Download Connector
(Connect Serial Port Interface Board
to Handy-board here)
Ports 0,1,2,3 for MOTORs
(Connect a wire from
Port 0 to your LEFT motor
And another wire
from Port 2 to your RIGHT motor)
I LOVE ECE001!
Building a Robot Chassis
• Using the Legos provided, construct a small chassis
capable of carrying the load of the handy-board.
• Attach motors to chassis.
• Attach a gear to the motor, as shown on the following
page (figure 1).
• Put a gear and wheel combination on an axle.
• Align two gears as shown in figure 2.
Attaching Gear/Axle to Chassis
Figure 1
Connecting Motor to Gears
Figure 2
Wire Connections From Motors to
Handy-Board
Figure 3
Procedure to Attach and Test
Motors on Robot
1.
2.
3.
4.
5.
6.
7.
8.
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.
Sample Motor program
void main()
{
printf("Press START to test motors\n");
while(!start_button()); // wait for start button press
fd(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);
}
Analog Sensor Review
Analog Sensors
• Outputs a range of integer values, depending on
the input signal that is 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,
also known as the 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 an obstacle
• A high value indicates dark light or far
proximity from an obstacle
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 1 Overview
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 student 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
Diagram of Robot with Light Sensor
• When RIGHT sensor
senses black line
turn right (and
vice-versa)
Left LIGHT Sensor
RO BOT
Right LIGHT Sensor
Some Sample Robots
Some Sample Robots (cont)
Some Sample Robots (cont)
Some Sample Robots (cont)
Optional Portion of Project
• As an optional objective, we wish to make 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.
Main Functions of 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 forward
» ‘s’<0 reverse
– 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(x) ; // reads input from an analog sensor on port x
– Digital(x) ; // reads input from a digital sensor on port x
– sonar() ; // read input from the analog sonar sensor
Download