You are on page 1of 27

Programming - Motion

Intro to Robotics
Motors and Sensors Setup
The first thing we need to do is
tell ROBOTC that we have
motors on our robot.

Choose ROBOT , then MOTORS


AND SENSORS SETUP.
Motors and Sensors Setup
You will notice that
there are THREE
tabs. One for Motors,
Analog Sensors, and
Digital Sensors.

Choose the Motors


Tab.

In port 2 “Name” type


in Rmotor and for
ports 3 type in
Lmotor.

Then select MOTOR


EQUIPPED from the
type drop down
menu.
Click APPLY , then OK.
Motor Command
The motor command tells the robot to run a motor at a
given power level. The example below sets the motor
on port 3 to run at full power forwards. Remember,
every command ends with a semicolon.
Wait Command

The comment wait1Msec tells the robot to wait


before it executes the next command, for a
given time in milliseconds. The value in
parenthesis is the amount of time you want
the robot to wait. 3000Ms is equal to 3
seconds.
Let’s Begin

You will notice that at the top there are PRAGMA statements. These are
automatically generated configuration statements and will ALWAYS be at
the very top of the program.
Let’s compile
If it asks you to save, call it
motion lesson 1.

WHAT HAPPENED?
Compile Errors
Errors have different
colors and are displayed
next to the code line
number where there is a
problem. Here we see a
problem in line 9.

Errors are explained in a little bit more detail below. If you have no errors, then the
program compiled correctly.
Compiled Correctly
Attaching to a PC
Use a USB cable to
connect the robot to
the PC. It is often an
ORANGE cable.

Turn the Cortex on.


Check the platform type
Check the download method
Compile and download

Possible errors:
•Cortex power on? If not, RobotC may ask you to turn on the battery.
•Can’t find the COM port? If not, unplug the USB cable with the cortex
powered on, then re-insert and try again.
What happened????
Motors and Sensors Setup
Motors and Sensors Setup

Check here! (or port 3?)

RobotC will make the


change in the
#PRAGMA statement.
Modify this code. Since we
are moving at half power lets
double our time.
Modify the code, then compile and download. Note what happens.
Modify the code below, then compile and download each time. Note
what happens.
Manual Straightening
To compensate for the differences between the motors, we
could either speed up the slower motor or slow down the
faster one. Let’s slow down the faster one.
Save your code

Save the code with a filename you will


remember in your MY DOCUMENTS folder.
Challenge

Using what you have learned, write a program


that will allow you navigate the labyrinth in
the arena. You MUST use comments to
explain in the code what you are doing. Place
group member names in the comments at the
bottom of the code.

You might also like