Professional Documents
Culture Documents
Class/Period:
Date:
Overview:
In this activity, you will connect your robot to your computer. You will learn about
PWM control of motors, deadbanding, and will write your first easyC program.
Duration:
90 minutes
Materials:
Qty
Description
Programming Module
easyC
Procedures:
2.3.1: Safety Considerations
When using the components related to programming, special safety
considerations are appropriate. Static discharge can be fatal to sensitive
electronic components, even if the amount of current is too small for you to feel
with your fingers.
If you must handle an electronic chip or exposed circuit board, always take steps
to ground yourself before you even touch it. This can be done by touching a
grounded metal chassis.
Even momentary connection to the wrong device, or plugging something in
backwards or shifted can cause permanent and expensive damage to a precious
device. With cables and connectors, it is always best to look twice and plug
once. In other words, think, read, and understand what youre doing before
plugging something in. The try-it-and-see-what-happens approach may be
suitable for some things, but not for delicate electronic parts.
Always check the polarity of the connector. If you have to force it, something is
not right. STOP, LOOK, THINK and ASK!
Finally, if something is getting hot, smelling toasty or smoking, shut down the
power right away and investigate. Be careful not to burn yourself looking for the
culprit. Electronics can get extremely hot with no visible warning.
Before making any connections to your Vex controller, make sure that it is turned
OFF. This step is necessary to protect against accidental damage resulting from
voltage discharges.
If you wish to instead use an RS-232 port (serial connection), then use a doubleended RS-232 cable instead of the USB adapter.
The other end of this cable should be plugged into your programming module.
Connect the programming module to your Vex controller. Use the 6-conductor
cable with the modular plugs at both ends.
Caution: Do not try to plug the RC receiver into this port. The RC receiver uses a
standard 4-conductor cable and plug. If you do manage to jam the plug into the
Serial port, you will cause physical damage to the jack, and may release a wild
jolt of electricity into the delicate Vex controller.
Since there is no way to be absolutely sure what program the controller holds,
you must guard against the case when the first instruction of the program directs
the motors to turn without user input. Lift the driving wheels off of the table
surface. If you built a handle into the top of your BaseBot, this will be easy.
Otherwise, you need to either turn it upside down, or set it on a book or similar
object so that its wheels are able to spin freely.
Open easyC.
To make the robot do anything, you need to download a program to it. EasyC
contains a special program you can download to your controller that allows you
to communicate directly with it via the programming cable. This program is called
the On-Line window. Once loaded into your controller, this utility allows you to
manually control motors and toggle digital outputs. It also displays what is
coming in from the inputs.
You will use the On-Line Window frequently during this course to test motors,
verify operation, and read inputs. Before you can use any of the controls on this
panel, you must first perform the following two operations:
Verify communications between your PC's COM port and the Vex
controller.
Verify Communications
To verify that you are using the correct COM port on your computer:
1
2
You must close the On-Line Window to change the COM port. Open the On-Line
Window again from the options menu in the loader.
A progress bar appears. It moves first to the left, as it erases the currently loaded
program, then to the right as it downloads the On-Line Code.
If you do not see the progress bar, check all your connections and try again.
If you see an error message , determine and correct what caused it and try again
Verify Connections
Look at the top of your Vex Controller, particularly at the MOTORS bank.
Observe that the connectors, or ports, are numbered 1 through 8, and that there
are two motors plugged in (probably in ports 1 & 2). Make a note in your
engineering notebook as to which motor ports are in use.
From now on it will be up to you to adjust your motor connections as needed for
each example. For now you will just be using the first two ports, but you should
get in the habit of checking the motor connections each time you download a
new program. Some examples may require the left motor to be in port 1, and
others the right. Get in the habit of checking!
Now, using the On-Line window, grab and move a motor slider left and right with
your mouse observing what happens. Move the slider gradually in one direction
and then the other and record your observations in your engineering notebook.
At any time you may press Set all to Neutral to move all the controls back to the
center OFF position.
Questions
Note the speed and direction of each motor in relation to the position of the slider
both right and left of center. Try many different positions for each slider. Record
your observations in your engineering notebook
Question 1
Question 2
Question 3
center?
Which way do the wheels turn if both sliders are set left of
Question 4 In this case, would you expect your robot to move straight
ahead, go backwards, or turn? Test your theory and record your findings.
Motor 2
Question 5 Compare the performance of the two motors. How are they the
same? How are they different?
Question 6 If you could hook up a joystick that generates PWM to the
motors, how would you expect the motors to behave near the center
position of the joystick?
Question 7 If your two motors had very different dead band values, what
effect would this have if you tried to make the robot go straight and slow?
How about straight and fast?
In the Function Blocks panel, easyC conveniently groups the objects you can
use in your programs. These categories are Inputs, Outputs, Program Flow, RC
Control and User Functions. To open any of these categories, click on the plus
sign to the left of the category, or double-click on the category name.
In time, you will become familiar with each of these. Soon you will find and use
the Motor Module and Wait blocks in your own program.
The controller sends commands out to devices such as motors. Thus, you
would logically expect to find the motors in the Outputs category. The standard
easyC object for controlling a PWM motor is called Motor Module. Find it.
Click on the Motor Module, hold your mouse button down, and drag it to the block
diagram somewhere BEGIN and END. You can click the Start button in the
viewer to start a video of this process. Release the mouse button. You will then
see a Motor Module window similar the one shown below.
In this window, you can specify the motor number and the PWM value. You can
also include optional comments. For your convenience, three specific PWM
values are predefined for you:
Stop (127)
You can select any other value you want between 0 and 255 by click on User
Value. In this blank field, you can specify a number, a constant or a variable.
10
For now, select Motor 1 and Counter-clockwise, and then hit OK.
Notice that the SetMotor block is now inserted into the code, and that the parameters
are 1 and 0 (Motor 1, PWM 0), just as you instructed. If you want to change these
values, double-click on the icon and the Motor Module window will reappear.
If you make an error, you may right-click on any block, select Delete, and then try
again. Later you will learn easier ways to edit your programs.
11
Be sure your robot's wheels are off the ground. Some programs are not
well-behaved enough to wait for user input, but immediately begin to run
once download is complete.
Click Yes.
When you select this function, easyC will compile and build your program. When
the compilation is finished, you will be shown a dialog box that asks whether you
are ready to download. Do not click Yes until you are sure that your robots
wheels are off the ground. Some programs are not well-behaved enough to wait
for user input, but immediately begin to run once download is complete.
If there are syntax errors in your program, they will be described in the message
window at the bottom of the screen. Also, the code block where the error is found
will automatically be highlighted. Read it carefully. It takes time to get familiar
with the language of error messages.
12
Connect the right motor to port 1, and the left motor to port 2.
Questions
Question 9 Notice that there is a Wait statement at the beginning of the
program. What do you think this does?
Question 10 What will happen if it is removed? Try it. Record your
observations in your engineering notebook.
13