The VEX is equipped with 16 sensor ports. These can be either analog (e.g. voltage level from a photocell detecting light intensity) or digital (e.g. a touch or switch sensor). Analog sensors should be connected to lower numbers ports and digital sensors connected to higher numbered ports. This is restriction in the VEX hardware where analog sensors are assigned ports 1 to N where N is the total number of ports.<br />

+

+

There are a variety of functions and variables used for configuring these ports and accessing their values.<br />

+

+

Configuring sensors can be complicated. ROBOTC has a built-in wizard that can be used to configure the VEX sensors. The wizard contains a number of PC windows that allow you to set the following fields for the sensor:

+

+

*The variable name that you want to assign to the sensor. Using a name like “leftBumper” makes for a more readable program than IN3!

if(SensorValue(lineFollower) < 950) // if the lineFollower sensor reads a value less than 950:

+

−

{

+

−

// turn left:

+

−

motor[port2] = 50; // motor on port 2 is run at power level 50

+

−

motor[port3] = 0; // motor on port 3 is stopped at power level 0

+

−

}

+

−

else // lineFollower sensor reads a value greater than or equal to 950:

+

−

{

+

−

motor[port2] = 0; // motor on port 2 is stopped at power level 0

+

−

motor[port3] = 50; // motor on port 3 is run at power level 50

+

−

}

+

−

}

+

−

}

+

−

</syntaxhighlight>

+

−

|-

+

−

|}

+

|-

|-

|

|

+

:'''Touch'''- Returns a digital value. A "1" means a closed circuit and a "0" means an open circuit.

−

=== Gyro ===

+

:'''Rotation''' - A digital sensor that returns a counter value keeping track of how many "counts" the encoder has seen. This sensor will increment regardless of direction. The VEX rotation sensor uses this type of sensor.

−

[[File:vex_gyro.png]]

+

−

<br />

+

−

As the Gyro is turned, the values it returns are in '''tenths of degrees''', positive and negative. Thus, a SensorValue of 3600 equals 360 degrees, or one full rotation. When the sensor is mounted horizontally, counter-clockwise movements will return values from 0 to -3600; clockwise movements will return values from 0 to 3600. Once the gyro completes one full revolution, the sensor value will “roll-over” to 0 by default (for example: …3597, 3598, 3599, 3600, 0, 1, 2, 3,…). To change the “roll-over” point, un-comment line 33 (from the code below) and change the value of “SensorFullCount” from 3600 to the desired value (7200, 18000, ect)

+

−

''For more information on the Gyro sensor, check out the ROBOTC blog post: [http://www.robotc.net/blog/2011/10/13/programming-the-vex-gyro-in-robotc/ Programming the VEX Gyro in ROBOTC].''

+

:'''SONAR''' - Returns an analog value in inches (i.e. a value of 20 means 20 inches away). A value of "-1" means the sensor does not receive a "reflection". The sonar sensor requires the "Input" wire to be attached the interrupt port int1 or int2 to function properly.

−

<br />

+

−

{|

+

:'''Quadrature Encoder''' - A digital sensor that returns a counter value keeping track of how many "counts" the encoder has seen. This sensor will increment when traveling in the forward of direction and decrement when traveling in the reverse direction.The Quadrature Encoder requires one of the input wires be attached the interrupt port "int3" through "int6" to function properly.

//Completely clear out any previous sensor readings by setting the port to "sensorNone"

+

−

SensorType[in8] = sensorNone;

+

−

wait1Msec(1000);

+

−

//Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it

+

−

SensorType[in8] = sensorGyro;

+

−

wait1Msec(2000);

+

−

+

−

//Adjust SensorScale to correct the scaling for your gyro

+

−

//SensorScale[in8] = 260;

+

−

//Adjust SensorFullCount to set the "rollover" point. 3600 sets the rollover point to +/-3600

+

−

//SensorFullCount[in8] = 3600;

+

−

+

−

//Specify the number of degrees for the robot to turn (1 degree = 10, or 900 = 90 degrees)

+

−

int degrees10 = 900;

+

−

+

−

//While the absolute value of the gyro is less than the desired rotation...

+

−

while(abs(SensorValue[in8]) < degrees10)

+

−

{

+

−

//...continue turning

+

−

motor[rightMotor] = 25;

+

−

motor[leftMotor] = -25;

+

−

}

+

−

+

−

//Brief brake to stop some drift

+

−

motor[rightMotor] = -5;

+

−

motor[leftMotor] = 5;

+

−

wait1Msec(250);

+

−

}

+

−

</syntaxhighlight>

+

−

|-

+

−

|}

+

−

|-

+

−

|

+

−

+

−

=== Accelerometer ===

+

−

[[File:vex_accel.png]]

+

−

<br />

+

−

Returns an analog value between 0 and 1023. Each Accelerometer Sensor has 3 cables, X, Y, and Z. The ports you attach them to don't have to be in any particular order ''(however you WILL need to use 3 ports)''.

Revision as of 16:09, 8 March 2012

The VEX is equipped with 16 sensor ports. These can be either analog (e.g. voltage level from a photocell detecting light intensity) or digital (e.g. a touch or switch sensor). Analog sensors should be connected to lower numbers ports and digital sensors connected to higher numbered ports. This is restriction in the VEX hardware where analog sensors are assigned ports 1 to N where N is the total number of ports.

There are a variety of functions and variables used for configuring these ports and accessing their values.

Configuring sensors can be complicated. ROBOTC has a built-in wizard that can be used to configure the VEX sensors. The wizard contains a number of PC windows that allow you to set the following fields for the sensor:

The variable name that you want to assign to the sensor. Using a name like “leftBumper” makes for a more readable program than IN3!

Contents

Analog Sensors

Raw Value - Returns an analog value between 0 and 1023 - Used for testing new sensors or reading raw data from sensors.

Reflection - Returns an analog value between 0 and 1023.

Line Follower - Returns an analog value between 0 and 1023.

Digital Sensors

There are 5 main types of Analog Sensors for the VEX PIC:

Touch- Returns a digital value. A "1" means a closed circuit and a "0" means an open circuit.

Rotation - A digital sensor that returns a counter value keeping track of how many "counts" the encoder has seen. This sensor will increment regardless of direction. The VEX rotation sensor uses this type of sensor.

SONAR - Returns an analog value in inches (i.e. a value of 20 means 20 inches away). A value of "-1" means the sensor does not receive a "reflection". The sonar sensor requires the "Input" wire to be attached the interrupt port int1 or int2 to function properly.

Quadrature Encoder - A digital sensor that returns a counter value keeping track of how many "counts" the encoder has seen. This sensor will increment when traveling in the forward of direction and decrement when traveling in the reverse direction.The Quadrature Encoder requires one of the input wires be attached the interrupt port "int3" through "int6" to function properly.

Digital In - This will make the sensor port act as just a digital input, very similar to a touch sensor.

Digital Out - This will cause the sensor port to send out a digital high ("1") signal. Useful for using the controller to power 5V devices.