You are on page 1of 13

2.

3 Activity: Programming the Vex Controller


Name:

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

Vex Controller in a BaseBot

Programming Module

Fully charged battery pack

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

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.

2.3.2: Connect to the Vex Programming Module


If your computer has an available USB port, connect the USB connector on your
USB to RS232 adapter into your PC.

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

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.

2.3.3: Using easyC


Position your BaseBot so that it cannot launch itself off the table. You may prop it
up on a stand or set it upside-down.
Push the power switch into its ON position. The "BATT POWER" light on the
other end of the case should be illuminated. If not, check your battery connection,
and confirm that the battery pack has been charged.
On-Line Code

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

To access the On-Line Code:

Click Build & Download and then select On-Line Window .

The On-Line Window opens.

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.

Download the On-Line Code to your controller.

These steps will be described in the following pages.

REC 2.3 Activity: Programming the Vex Controller


Instructions

Verify Communications
To verify that you are using the correct COM port on your computer:
1
2

Open the Start menu and select Control Panel


Double-click System to open the System Properties dialog box (located in
the Performance and Maintenance category of Windows XP)
3 Select the Hardware tab
4 Click the Device Manager button
5 Double-click Ports (COM & LPT)
6 Note on which COM port the prolific USB to Serial Comm port is located
on your system. Write this number down. This is the port easyC will use
to send code to your robot. (This port will only appear while your
programming module is connected to the computer).
Note: This is not necessarily the same port you used before.
As long as you continue to use the same port on your computer, your port
number should not change, and you will not need to repeat this procedure
Select COM Port
In the Port Setting menu of the IFI/Intelitek Loader, select that same COM port
number.

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

Download On-Line Code


Caution: Any time you download a program to your BaseBot, it may move
unexpectedly. Be sure the wheels are off the surface.

Click the Download On-Line Code button .

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

REC 2.3 Activity: Programming the Vex Controller


Instructions

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

What happens near the center position of each slider?

Question 2

Can you repeat the behavior of the motors?

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

2.3.4: Deadbanding with the On-Line Window


Unless there is a loose connection in your system, the behavior of your motors is
reasonably predictable. You have probably already noticed some weird behavior
in the area close to the center position. You may even have heard some squeals
or whistling sounds coming from the motors.
The range of values where the motor seems to be trying to move but remains still
is called the dead band. This behavior is typical of most PWM motors. When the
PWM is precisely 127 (the value for STOP) there is no power going to the
motors.
As this value moves farther from 127, more power is gradually supplied to the
motor. However, the very smallest amounts of power may not be sufficient to
overcome the initial internal friction in the motor. This friction may come from the
gears, bearings and any other parts connected to the motor.
The degree to which you can vary the PWM away from 127, and still get no
motion is the amount of dead banding in the system. A chart modified to reflect
dead banding is shown below.

Collecting and Analyzing Data


Using the On-Line window and the two motors in your BaseBot, fill in the chart
shown below.
Motor 1
1

Lowest number at which there is no motion:

127 minus the value in row 1=

Highest number at which there is no motion:

The value in row 3 minus 127=

Rows 2 + Row 4 = Width of deadband:

REC 2.3 Activity: Programming the Vex Controller


Instructions

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?

2.3.5: Programming with easyC


Just as the On-Line code is a program that can control your motors, you can
write programs of your own that make the motors move.
Close the On-Line window. From the easyC menu bar select File, and then New
Project, or from the toolbar select . You will now see a generic program
framework ready to accept your code.

REC 2.3 Activity: Programming the Vex Controller


Instructions

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:

Full speed clockwise (255)

Stop (127)

Full speed counter-clockwise (0)

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

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.

2.3.6: Example Block Program


In the same fashion as above, select, drag and edit Wait blocks and Motor
Module blocks to create the program shown below:

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

11

Question 8 Analyze this program. What do you expect it to do? Record


your predictions in your engineering notebook.

2.3.7: Compile Download and Run the Sample Program


Select File and then Save Project, or click on the Save icon in the toolbar. Save
your program to a folder and under a name that relates to what it does. For
example, you could name this program 2.3.6.
Tip: You should always save your work before moving on to the next step, such
as testing.
Tip: Develop a naming system for your files so that you can quickly determine
what the program is designed to do. Discuss strategies with your partner (if you
have one) or with your teacher.
Build & Download

Locate the Build and Download icon.


Tip: When your mouse pointer is over the button, "Build & Download" is
displayed as tooltip text.
When you select this function, easyC will compile and build your program.
This function can also be accessed by pushing the [F7] key, or by
selecting Build & Download from the Build & Download menu.

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 Build and Download.


When the compilation is finished, you will be shown a dialog box that asks
whether you are ready to download.

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.

REC 2.3 Activity: Programming the Vex Controller


Instructions

12

If your program downloaded successfully, you may run it repeatedly by turning


your Vex controller off and back on. This is called power cycling or a hardware
reset.

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.

2.3.8: Print out your records


If you have access to a printer, select File and then Select and Print Flow
Chart. Print out a copy of your entire program for your robotics binder.
Question 11 Run the program several times. Does it do the same thing
each time? Record your observations in your engineering notebook.

2.3.9: Return to Origin


Edit your program by adding steps to the bottom after the stop motor commands.
In the new code, make the robot move in the opposite direction at the same
speed for the same period of time. Save the new version, compile and download
to the robot.
Question 12 Test the program. Does the robot return to the same place as
it started? Record your observations and findings. As before, if you are
able, print a copy for your robotics binder.

2.3.10: Restore the Default Code


Since the robot has been custom programmed, it should be restored to its normal
or default condition. From the Build & Download menu, select Download
Default Code, click on Yes and allow it to finish. Confirm that you are able to
control the robot with your radio joystick as before.

REC 2.3 Activity: Programming the Vex Controller


Instructions

13

You might also like