robotc for vex cortex llano estacado roboraiders frc team 1817

Post on 03-Jan-2016

47 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

ROBOTC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817. Humans and Machines. Machines are built to perform useful tasks. The way a Machine works depends entirely on the way the Human build it. - PowerPoint PPT Presentation

TRANSCRIPT

06/2012 Tanya Mishra 1

ROBOTC for VEX CortexLlano Estacado RoboRaiders

FRC Team 1817

08/2012 Tanya Mishra 2

Humans and Machines Machines are built to perform useful tasks. The way a Machine works depends entirely on the way

the Human build it. Since Machines and Robots need a medium of

communication, a language called “Programming Language” is used.

EASYC, ROBOTC, C++, C all are programming languages.

The instructions in the language are called “Programs” and the human that writes the instructions is called the “Programmer”.

08/2012 Tanya Mishra 3

Task of Programmer: Understand Problem, Find a solution, Write a program to solve the problem in the required Programming language.

Task of Machine: Follow the program provided. A ROBOT is a Machine.

08/2012 Tanya Mishra 4

Planning and Behavior

Behavior: Action the Robot has to take. Big Behavior: Solving a maze Small Behavior: Turn Left, Move Forward, etc. Big Behavior is made up of Smaller Behaviors. Plan a Solution to the problem. Break down the plan into detailed smaller steps. Each step is a behavior the robot needs to follow. Sequence of these steps in English is called “pseudo-

code”.

08/2012 Tanya Mishra 5

08/2012 Tanya Mishra 6

“Flow charts” are a visual representation of the program flow.

Start and End: “Rounded Rectangles”. They contain the word “Start” or “End”, but can be more specific such as “Power Robot Off” or “Stop All Motors”.

Actions: “Rectangles”. They act as basic commands and process steps.

Decision blocks: “Diamonds”. These typically contain Yes/No questions. Based on the choice, the next step is determined.

08/2012 Tanya Mishra 7

08/2012 Tanya Mishra 8

Introduction to C Programming

EasyC is based on the the principles of C Programming.

We will cover the following concepts:

1. Basic Components of a C Program

2. Data Types and Variables

2. Conditional operators

3. Control Structures and Loops

4. Methods and Functions

08/2012 Tanya Mishra 9

A Basic C Program

#include<stdio.h> // Header File

void main(void) // Main function

{

// Body of the main function

}

Header file: Includes all the required words and instructions needed to write a program

Main function: Execution starts from here Body: stepwise Instructions to the Robot

08/2012 Tanya Mishra 10

Each Instruction to the robot is also called a “Statement”.

When the list of instruction is send to the VEX cortex, it read them from top to bottom and left to right.

Different Commands use different paired Punctuations such as “[]” “{}” “()”

“{..}” defines a body of one or more instructions. Also called a “Compound Statement”.

Every instruction in the body ends with a “;”. It shows the end of a instruction.

08/2012 Tanya Mishra 11

Comments are for the programmer to understand what a particular statement does.

Two kinds of comments:

1. // This is a one line comment

2. /* This is a more than one line

Comment.*/ C language is case sensitive: Upper and lower

cases are considered different.

08/2012 Tanya Mishra 12

Data types and Variables A “Variable” is a place to store a value. A variable has a “Type” and a “Name” “Type” deals with the type of Data the variable

will hold.

Type of Data:

Int: Whole Numbers. Positive, Negative, Zero

float(Floating Point): Decimal Point Numbers. Positive and Negative.

String: Text. Letters, Spaces and characters.

08/2012 Tanya Mishra 13

char(Characters): Single characters

bool(Boolean): True and False values

Declare a variable: int Age;

float Score;

string Name;

char Grade;

bool Pass;

08/2012 Tanya Mishra 14

Assign a variable: Age = 18;

Score = 90.5;

Name = “William”;

Grade = 'A';

Pass = True;

Declare and assign: int Age = 18;

float Score = 90.5;

string Name = “William”;

char Grade = 'A';

bool Pass = True;

08/2012 Tanya Mishra 15

Variable Naming Rules: A variable name can not have spaces in it. A variable name can not have symbols in it. A variable name can not start with a number. A variable name can not be the same as an

existing reserved word.

Scope of a Variable: Local variables: Within a certain block of code

or function. Cannot be accessed outside. Global variables: Can be accessed anywhere

in the code.

08/2012 Tanya Mishra 16

Using Variables in a print to screen function:

When printing a variable on the screen, the following syntax is used:

Print to screen function(“%type”,Variable);

Signed : + and - , unsigned: - , short: less range , long : more range

08/2012 Tanya Mishra 17

Conditional Operators Comparison operators

Relational Operator Example

> (Greater Than) 7 > 5

>= (Greater Than or Equal To) 7 >= 5 , 7 >= 7

< (Less Than) 5 < 7

<= (Less Than or Equal To) 5 < 7 , 7<=7

== (Equal To) 7 == 7

!= (Not Equal To) 7 != 5

= (Assignment Operator) number = 7

08/2012 Tanya Mishra 18

Logical operators:

Boolean Truth TableJoining two or more statements using “And” and “Or”

A: Its a Sunny Day

B: My Car is working

Can I go out?(A and B)

Can I go out?(A or B)

Yes Yes Yes Yes

Yes No No Yes

No Yes No Yes

No No No No

08/2012 Tanya Mishra 19

And : &&

Or : ||

Not : !

A B !A A && B A || B

True True False True True

True False False False True

False True True False True

False False True False False

08/2012 Tanya Mishra 20

Control Structures and LoopsControl Structure

IF statements:if(condition)

{

Instructions, if “condition” is True

}

08/2012 Tanya Mishra 21

IF-ELSE Statements:if(condition)

{

// Instructions, if “condition” is true

}

else

{

// Instructions, if “condition” is false

}

08/2012 Tanya Mishra 22

ELSE-IF Statements:if(condition1)

{

// Instructions, if “condition 1” is true

}

else if(condition 2)

{

// Instructions, if “condition 2” is true

}

else

{

// Instructions, if “condition 1” and “condition 2” are false

}

08/2012 Tanya Mishra 23

Switch Statements:switch(expression) //expression can only be an “int” or “char”

{

case Value-1:

// Instructions, if expression = Value-1

break;

case Value-2:

// Instructions, if expression = Value-2

break;

default:

// Instructions, if expression does not match any Value

}

08/2012 Tanya Mishra 24

Example:

char Grade = 'A';

switch(Grade)

{

case A:

Your Grade is A;

break;

case B:

Your Grade is B;

break;

default:

This is the default choice

}

08/2012 Tanya Mishra 25

Loops While loops:

while(condition)

{

// Instructions, if “condition” is true

}Note: Control Structures execute only once. On the other hand, while

loops execute continuously until the condition is false.

If the condition in the loop is always true, the loop never ends. Such a loop is called an “Infinite Loop”.

A loop will end only when the condition is false or there is a “break” statement.

08/2012 Tanya Mishra 26

Example:int count = 0; //Initialization

while(count <= 2) //Condition

{

PrintToScreen(“ I have %d apple \n”, count);

count = count + 1; //Increment

}

Output: I have 0 apple

I have 1 apple

I have 2 apple

08/2012 Tanya Mishra 27

For Loop:

for(initialization; condition; increment)

{

// Instructions, If “condition” is true

}

Similar to a while loop except that the initialization and increment are all together.

Note: Initialization is done only when the loop first starts. After that it is skipped.

08/2012 Tanya Mishra 28

Example:int count;

for(count =0; count <= 2; count = count +1)

{

PrintToScreen(“ I have %d apple \n”, count);

}

Output: I have 0 apple

I have 1 apple

I have 2 apple

Note: \n is called new lines. It prints the next sentence in a new line.

08/2012 Tanya Mishra 29

Methods and function

Functions are named sections of code that can be called from other sections of code.

Also called subroutines. Every executable statement in C must live in a

function. Functions have a Data type, name and input

values. Input values are called Parameters. They are

the values you want the function to work with.

08/2012 Tanya Mishra 30

The function definition specifies the “return value” and the “parameters” of the function:

<data type> FunctionName(<param1>, <param2>, ...)

{

<function body>

<return type>

}

Return type and Data type should be of the same kind.

Return type is “void” if nothing is to be returned.

Parameters is “void” if nothing is to be passed in.

08/2012 Tanya Mishra 31

Example:

int addition(int x, int y)

{

int z;

z = x+ y;

return z;

}

void main(void)

{

addition(2, 3);

}

08/2012 Tanya Mishra 32

Some Useful termsCompiler: Turns C program into the machine

language for the controller.

Loader: Loads the machine language output of the compiler (along with other stuff) into the robot controller.

Machine Language: What the robot controller actually understands. Found in .HEX files.

10110100

11100101

00001011

06/2012 Tanya Mishra 33

Download ROBOTC

Download Link: ROBOTC for CORTEX and PIC

www.robotc.net->Download->ROBOTC 3.0 for CORTEX and PIC

or

http://www.robotc.net/download/cortex/

06/2012 Tanya Mishra 34

ROBOTC Rulestask main()

{

motor[port3] = 127;

wait1Msec(3000);

}

Important words are highlighted. Uppercase and Lowercase matters. White spaces and tabs are for programmer convenience Sentences or Instructions are separated by semicolon. Instructions are read from T – B and L-R.

06/2012 Tanya Mishra 35

Error Messages

Compiler analyzes your programs to identify syntax errors, capitalization and spelling mistakes, and code inefficiency (such as unused variables).

Errors: Major issues. misspelled words, missing semicolons, and improper syntax. Errors are denoted with a Red X.

Warnings: Minor issues. These are usually incorrect capitalization or empty, infinite loops. Warnings are denoted with a Yellow X.

06/2012 Tanya Mishra 36

Information: ROBOTC will generate information messages when it thinks you have declared functions or variables that are not used in your program. These messages inform you about inefficient programming. Information messages are denoted with a “White X”.

06/2012 Tanya Mishra 37

System Configurations “Firmware” is a piece of software that accessing

the operating system in the processor enabling it to perform its task.

Update firmware to make sure it is compatible with the ROBOTC and latest Vex Hardware

Update Firmware on Cortex: Cortex Micro controller is the “Brain”

06/2012 Tanya Mishra 38

It has two separate processors inside:

1. User Processor : Handles all ROBOTC programming instructions.

2. Master Processor: Handles all lower level operations like Motor Control and VexNet Communication.

Make sure you have the following first:

1. A USB A-A cable.

2. A charged robot battery

3. The cortex Powered Off

4. Latest version of ROBOTC installed on PC

06/2012 Tanya Mishra 39

Step 1: Connect Cortex and PC

using A-A cable. Step 2: Turn Cortex ON. Step 3: Go to ROBOTCRobot->Platform Type->Innovation First(IFI)->Vex 2.0 Cortex

06/2012 Tanya Mishra 40

Step 4: View->Select Communication Port->USB wired Cable or Vex Robotics COMM Port (if Cortex recognized) otherwise Automatic

Step 5: Robot->Download Firmware->Automatically update Vex Cortex

06/2012 Tanya Mishra 41

Update Firmware on Joystick: Make sure you have the following first:

1. A USB A-A cable.

2. Latest version of ROBOTC installed on PC Step 1: Connect Joystick and PC

using A-A cable. Step 2: Go to ROBOTCRobot->Platform Type->Innovation First(IFI)->Vex 2.0 Cortex

06/2012 Tanya Mishra 42

Step 4: View->Select Communication Port->USB wired Cable or Vex Robotics COMM Port (if Cortex recognized) otherwise Automatic

Step 5: Robot->Download Firmware->Automatically update VexNET Joystick

06/2012 Tanya Mishra 43

Download Firmware when: You start using a particular Vex Cortex or

VexNET Joystick You update a newer version of ROBOTC.

06/2012 Tanya Mishra 44

Download Sample Program

Step 1: Go to ROBOTCFile->Open Sample Program->Training Samples->Motor port 3

forward.c

06/2012 Tanya Mishra 45

Before Downloading, make sure: Your cortex and VexNet remote control are

paired and equipped with VexNet USB keys. Batteries connected to remote control and

cortex. Robot propped up. Orange programming kit connecting PC and

remote control. Turn on Remote Control and Robot. Robot and VexNet status lights should blink

green on both remote control and Robot.

06/2012 Tanya Mishra 46

Step 2: View->preferences->Detailed Preferences->Platform: Vex 2.0 Cortex and Communication Port: Prolific USB-Serial Comm port.

Step 3: Robot->Vex Cortex Communication Mode->VexNet or USB

06/2012 Tanya Mishra 47

Step 4: Robot->Compile and Download Program

Step 5:Debugger Window->Start

06/2012 Tanya Mishra 48

Motorstask main()

{

motor[port3] = 127;

motor[port2] = 127;

wait1Msec(3000);

}

Running this program makes the Robot spin because the motors on the robot are mirrored. So making the motor on port2 move forward in the code, makes it move in reverse in real time.

06/2012 Tanya Mishra 49

Reverse Motor Polarity: Robot->Motors and Sensors Setup->Motors

tab-> Port 2 reversed check box is checked.

06/2012 Tanya Mishra 50

#pragma config(Motor, port2, , tmotorNormal, openLoop, reversed)

The “pragma” statement contains configuration information from the motors and sensors settings and should only be changed from the window.

06/2012 Tanya Mishra 51

The Motors and Sensor Window can also be opened by double clicking on the pragma statement.

Motors and Sensor Window: Name: Name of the Motor eg. leftMotor, rightMotor

Type : Motor Equipped or Type of Motor

Reversed: Checked if Motor needs to be reversed.

task main()

{

motor[leftMotor] = 127;

motor[rightMotor] = 127;

wait1Msec(3000);

}

06/2012 Tanya Mishra 52

06/2012 Tanya Mishra 53

Assigning Positive power Values(127) on both motors makes the robot go forward.

Lower speed of robot by assigning values less than full power(127).

Assigning negative power values(-127) on both motors makes the robot go reverse.

Assigning zero power values(0) on both motors makes the robot stay in place.

Turning of Motors

06/2012 Tanya Mishra 54

Point Turn: Turn in place (-63 and 63)

Swing Turn: Making one motor on and the other off makes the robot swing around the stationary wheels. (0 and 63)

06/2012 Tanya Mishra 55

Sometimes the power assigned in the code to the motors does not reach the motors. Reasons: friction or construction. Manual adjustments to the power levels.

task main()

{

//Makes the robot go forward at half speed for 2 seconds.

motor[leftMotor] = 63;

motor[rightMotor] = 63;

wait1Msec(2000);

//Makes the Robot turn left in place for 0.7 seconds.

motor[leftMotor] = -63;

motor[rightMotor] = 63;

wait1Msec(700);

}

06/2012 Tanya Mishra 56

Shaft Encoders/Rotation Sensor

Manual adjustments of power are not same for all robots and as the battery power drains, the robot is move shorter distances.

Shaft Encoders are used to control how far the Robot Moves.

Number of counts per Revolution on a axle mounted through the encoder center.

Max 360 up for forward movements and 360 down for reverse movements.

06/2012 Tanya Mishra 57

ROBOTC->File->Open Sample Program->Shaft Encoder->Forward for Distance.c

06/2012 Tanya Mishra 58

06/2012 Tanya Mishra 59

Encoders need to be set to zero before you use them.

On the Cortex Micro controller, the Analog and Digital Ports are used to connect sensors.

In Motors and Sensors setup: Digital Port, Sensor Name and Sensor Type Naming Conventions: No special Characters,

No spaces and Not a reserved word in ROBOTC.

Both Encoder wired on the Right and Left side of the robot must be in neighboring ports.

06/2012 Tanya Mishra 60

06/2012 Tanya Mishra 61

Clear the encoders for better consistency and precision on your robots movements.

06/2012 Tanya Mishra 62

Sensor Debug Window: In order to see the values in the encoders as

the robot runs, we can use the debugger window.

Compile and Download the program. Press “continuous” on the debugger window

instead of “start”. Robot->Debugger Windows->Sensors Scroll down and find your encoders in the list. Press “start” on the debugger window to start

your robot and watch the values change.

06/2012 Tanya Mishra 63

06/2012 Tanya Mishra 64

Forward movement and Turning: Not controlled by power or time but rotation

counts.

06/2012 Tanya Mishra 65

Joystick Mapping

Vex Remote control provides you with two joysticks (each having a x- axis and y-axis), eight buttons on the front and four additional buttons on the top.

06/2012 Tanya Mishra 66

The remote control sends streams of data to the Robot over the VexNet.

The Vertical motion of the joysticks on the remote control range from +127 to -127, where +127 is full power forward, 0 is stop and -127 is full power reverse.

To access the values in the joystick in ROBOTC, we use the following command:

vexRT[channel Number]

VexRT is short for Vex Remote Transmitter. The channel number for each input is shown on

the remote.

06/2012 Tanya Mishra 67

For example, the right joystick's vertical motion is on channel 2.

vexRT[ch2]

Pairing each motor with each joystick we can make the robot move forward, turn or go in reverse.

motor[port number] = vexRT[channel number]

06/2012 Tanya Mishra 68

Sample Program:ROBOTC->file->Open Sample Program->Remote Control->Dual

Joystick Control.c

06/2012 Tanya Mishra 69

06/2012 Tanya Mishra 70

Limiting the range of power from [127, -127] to half power [63,-63] to achieve accurate movements.

Similarly, many other possible mapping combinations are possible.

06/2012 Tanya Mishra 71

Timers

Timers are like “Stopwatches”. Used in competition to know how long the robot

has been working. Four Timers provided in ROBOTC: T1 , T2, T3

and T4.ClearTimer(TimerName)

This command resets the Timer to 0 and immediately starts counting again.

06/2012 Tanya Mishra 72

To check the elapsed time on the Timer T1, we use the following command:

time1[T1]

It returns the elapsed time in milliseconds. To check elapsed time in 10 milliseconds or

100 milliseconds, the commands are:

time1[T1], time10[T1], or time100[T1]

06/2012 Tanya Mishra 73

Thus, to make your robot unresponsive for 90 seconds:

06/2012 Tanya Mishra 74

Buttons Mapping

The 8 buttons on front of the remote control are divided into two groups and the four buttons on top are also divided into two groups. The group number is written next to the numbers.

06/2012 Tanya Mishra 75

Unlike joysticks, the buttons have two values: 1 when pressed and 0 when released.

VexRT[Btn Group# Direction],

where Direction = U(Up), D(Down), L(Left), R(Right)

For example, to access the Down button on Group 7 (Left side buttons on the remote):

VexRT[Btn 7 D]

06/2012 Tanya Mishra 76

To make your robot respond to user control on a button press:

06/2012 Tanya Mishra 77

Sensor Configuration

Vex Cortex allows us to incorporate various sensors on the robot which provides valuable sensor feedback for intelligent decision making.

There are 8 Analog Sensor ports for sensors like Line Follower, Accelerometer and Potentiometer.

There are 12 Digital Sensor ports for sensors like the limit switch, Shaft Encoder and Ultrasonic Rangefinder.

06/2012 Tanya Mishra 78

06/2012 Tanya Mishra 79

These sensors are configured in the same way we have configured motors and shaft encoders before.

The ROBOTC Motors and Sensors setup allows you to setup these sensors depending on if it is a Digital or Analog Sensor.

If you are unsure of the type of sensor being Analog or Digital, you can see it in the drop down menus in the Motor and Sensor Setup.

06/2012 Tanya Mishra 80

Limit Switch: Limit Switch is a Digital Sensor(0 and 1) and is

plugged into the Digital port 6 on the Cortex. When pressed, it provides a sensor value 1,

when released, it provides a sensor value 0.SensorValue[Limit switch name]

06/2012 Tanya Mishra 81

Potentiometers: A potentiometer is a Analog Sensor and is

plugged into port 6 of the Analog board on the cortex.

It measures rotation between 0 to 250 (not 360 due to internal mechanical stops) degrees and return value ranging from 0 to approximately 4095.

06/2012 Tanya Mishra 82

The values returned by the Potentiometers can be seen using the Sensor Debug Window that we used with the Shaft encoders.

SensorValue[Potentiometer name]

06/2012 Tanya Mishra 83

Ultrasonic Range Finder Ultrasonic Range Finder allows us to sense

obstacles in the path of the robot and avoid bumping into them.

06/2012 Tanya Mishra 84

It measures distance to the obstacle using sound waves. It calculates the Distance depending on how long it takes for the sound wave to bounce back.

Distance = Speed * Time / 2

Digital Sensor and connections on the Cortex are as follows:

06/2012 Tanya Mishra 85

Motors and Sensor Setup: Choose type depending on what distance scale

you want: cm or mm or inch

06/2012 Tanya Mishra 86

According to the program, till the distance to the obstacle is greater than 25 cm, the robot will move forward. As soon as it is 25 cm away from the obstacle, to robot will stop.

06/2012 Tanya Mishra 87

Sometimes the echo of the sound wave does not reach the range finder on soft surfaces like a sweater or certain surfaces such as a slope deflect the wave in another direction.

In the debugger window, we can see that when the sonar does not detect any sound, the sensor value if set to -1.

06/2012 Tanya Mishra 88

If the sonar value will be -1, the condition in the code will always be false and the robot will not move when no obstacle is detected.

To make the robot move forward when no obstacle is detected, the condition needs to be changed.

06/2012 Tanya Mishra 89

Line Tracking Sensors

Below is shown a set of three Line tracking Sensors. Line tracking sensors work on the bases of Infrared Light. Each sensor has an Infrared LED and an Infrared Light sensor.

06/2012 Tanya Mishra 90

The LED emits light and the sensor detects the amount the light reflected back.

Light Surfaces = Low Sensor Reading Dark Surfaces = High Sensor Reading

06/2012 Tanya Mishra 91

The cortex gives a Sensor reading from 0 to 4095. The value does not correspond to any unit of measurement.

Thus it is important to take care of lighting conditions around the robot and the height at which the sensors are placed in order to determine the threshold of reading.

06/2012 Tanya Mishra 92

Motors and Sensor Setup:

06/2012 Tanya Mishra 93

Calculate Threshold Values (Example): Leaving the task main() empty, if we run the

robot on a light surface, we get the the following values in the Sensor Debugger Window:

For Dark Surfaces we get the following values:

06/2012 Tanya Mishra 94

Light Surface Average Value:

Average = 165 + 167 + 160 = 492 /3 = 164

Dark Surface Average Value:

Average = 2795 + 2821 + 2837 = 8453 / 3 = 2817.66 ~ 2818

Threshold Value:

164 + 2818 = 2982 / 2 = 1491

06/2012 Tanya Mishra 95

Using all three sensors allows us to detect the line as well as border of the line, corners and intersections, which is not possible if you use just one line tracking sensor.

06/2012 Tanya Mishra 96

Sample Program:File->Open Sample Program->VEX2->Training Samples->Simple

Line Tracking.c

06/2012 Tanya Mishra 97

06/2012 Tanya Mishra 98

We can see that the motor value pairs of 0 and 40 cause the robot to make sharp swings as it steers itself on to the line. This causes waste of energy. To simplify, use pairs of motor values close enough lie 20 and 40.

For sharp turns and curves on the lines, we can optimize the motor values, shaft encoder rotation counts and threshold values to work together in order to perfect the different sections of the path.

06/2012 Tanya Mishra 99

Tips on Line Tracking: Break the entire path into sections depending

on how the line curves. Instead of programming the entire path at once,

implement and test each section one after another.

The behaviour in each section will almost eb the same. The only difference will be the values of the motors, encoders or threshold. This can be achieved by implementing a LineTracking() function with different parameter values!

06/2012 Tanya Mishra 100

Reserved words

Motors

Motor control and some fine-tuning commands. motor[output] = power;

The VEX has 8 motor outputs: port1, port2... up to port8. The VEX supports power levels from -127 (full reverse) to 127 (full forward). A

power level of 0 will cause the motors to stop.

bMotorReflected[output] = 1; (or 0;)

06/2012 Tanya Mishra 101

Timing

The VEX allows you to use Wait commands to insert delays into your program. It also supports Timers, which work like stopwatches; they count time, and can be reset when you want to start or restart tracking time elapsed.

wait1Msec(wait_time);

Maximum wait_time is 32768Msec, or 32.768 seconds.

06/2012 Tanya Mishra 102

wait10Msec(wait_time);

Maximum wait_time is 32768, or 327.68 seconds.

time1[timer]

It returns the current value of the referenced timer as an integer. The maximum amount of

time that can be referenced is 32.768 seconds The VEX has 4 internal timers: T1, T2, T3, and T4.

time10[timer]

The maximum amount of time that can be referenced is 327.68 seconds.

06/2012 Tanya Mishra 103

time100[timer]

The maximum amount of time that can be referenced is 3276.8 seconds.

ClearTimer(timer);

This resets the referenced timer back to zero seconds.

SensorValue(sensor_input)

SensorValue is used to reference the integer value of the specified sensor port. Values will correspond to the type of sensor set for that port. The VEX has 16 analog/digital inputs: in1, in2... to in16

06/2012 Tanya Mishra 104

Type of Sensor Digital/Analog? Range of Values

Touch Digital 0 or 1

Reflection (Ambient) Analog 0 to 1023

Rotation (Older Encoder) Digital 0 to 32676

Potentiometer Analog 0 to 1023

Line Follower (Infrared) Analog 0 to 1023

Sonar Digital -2, -1, and 1 to 253

Quadrature Encoder Digital -32678 to 32768

Digital In Digital 0 or 1

Digital Out Digital 0 or 1

06/2012 Tanya Mishra 105

Sounds

The VEX can play sounds and tones using an external piezoelectric speaker attached to a motor port.

PlayTone(frequency, duration);

This plays a sound from the VEX internal speaker at a specific frequency (1 = 1 hertz) for a specific length (1 = 1/100th of a second).

06/2012 Tanya Mishra 106

Radio Control

ROBOTC allows you to control your robot using input from the Radio Control Transmitter.

BvexAutonomousMode = <value>;

Set the value to either 0 for radio enabled or 1 for radio disabled (autonomous mode). You can also use “true” for 1 and “false” for 0.

vexRT[joystick_channel]

This command retrieves the value of the specified channel being transmitted.

06/2012 Tanya Mishra 107

If the RF receiver is plugged into Rx 1, the following values apply:

Control Port Joystick Channel Possible Values

Right Joystick, X-axis

Ch1 -127 to 127

Right Joystick, Y-axis

Ch2 -127 to 127

Left Joystick, Y-axis

Ch3 -127 to 127

Left Joystick, X-axis

Ch4 -127 to 127

Left Rear Buttons Ch5 -127, 0, or 127

Right Rear Buttons

Ch6 -127, 0, or 127

If the RF receiver is plugged into Rx 1, the following values apply:

If the RF receiver is plugged into Rx 2, the following values apply:

06/2012 Tanya Mishra 108

Control Port Joystick Channel Possible Values

Right Joystick, X-axis

Ch1Xmtr2 -127 to 127

Right Joystick, Y-axis

Ch2Xmtr2 -127 to 127

Left Joystick, Y-axis

Ch3Xmtr2 -127 to 127

Left Joystick, X-axis

Ch4Xmtr2 -127 to 127

Left Rear Buttons Ch5Xmtr2 -127, 0, or 127

Right Rear Buttons

Ch6Xmtr2 -127, 0, or 127

bVexAutonomousMode = false; //enable radio control while(true) {

motor[port3] = vexRT[Ch3]; //right joystick, y-axis //controls the motor on port 3 motor[port2] = vexRT[Ch2]; //left joystick, y-axis //controls the motor on port 2

}

06/2012 Tanya Mishra 109

Reference

VEX Cortex Video Trainer using ROBOTC[http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/index.html]

ROBOTC : A C Programming language for Robotics

[http://www.robotc.net/]

top related