VEX Functions Sensors

From ROBOTC API Guide
Revision as of 17:01, 30 April 2012 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


For more examples and explanations, head over to PIC Sensors Overview page!


Color Key
Function:
Variable:


ifiInterruptPorts

word ifiInterruptPorts[tSensors sensor]
(word) This array is used by the "sensor and motor setup" wizard to map a regular "sensor" port with an interrupt port. This is only used for the two types of sensors (sonar sensors and quadrature encoders) that are interrupt based. All the other sensors are non-interrupt based. Both of these sensors use two digital I/O pins; one of which must be a interrupt pin.


Parameter Explanation Data Type
sensor A sensor port or name tSensors


// No sample code yet.  Feel free to add it!


nAnalogChannelCount

int ifiInterruptPorts
(int) Internal variable used by the "motor and sensor setup" wizard. Contains the number of analog channels on a VEX. The remaining channels will be treated as digital sensors.


// No sample code yet.  Feel free to add it!


SensorBoolean

const word SensorBoolean[tSensors sensor]
(word) This returns a true or false reading from the sensor. (Mostly used by Touch sensors).


Parameter Explanation Data Type
sensor A sensor port or name tSensors


while(SensorBoolean[touchSensor]) // Loop while robot's bumper/touch sensor is pressed in
{
   motor[rightMotor] = 63;   // Right motor is run at half (63) power forward
   motor[leftMotor]  = 63;   // Left motor is run at half (63) power forward
}


SensorRaw

word SensorRaw[tSensors sensor]
(word) This array value will return the "raw" (un-normalized) value of a sensor. Usually this is the raw A-D converted value, which is an analog value between 0 to 1023.


Parameter Explanation Data Type
sensor A sensor port or name tSensors


if(SensorRaw[lightSensor] > 512) // If the Raw Value of the Light Sensor is greater than 512:
{
   motor[rightMotor] = 63;   // Right motor is run at half (63) power forward
   motor[leftMotor]  = 63;   // Left motor is run at half (63) power forward 
}


SensorType

TSensorTypes SensorType[tSensors sensor]
(TSensorTypes) The SensorType array is used to specify what type of sensor is connected to a certain port. Most users should not have to use this functionality and should use the Motors and Sensor Setup instead.


Parameter Explanation Data Type
sensor A sensor port or name tSensors


SensorType[sonarSensor] = sensorSonar;  // set 'SonarSensor' to be of type sensorSonar (the Motors and 
                                        // sensors Setup screen does this for you in the background)


SensorValue

word SensorValue[tSensors sensor]
(word) This array value returns the value of the sensor in a normalized fashion. Rather than returning a raw value of 0 to 1023, ROBOTC will interpret the data from the "SensorType" and return a more accurate representation of the sensor's data. An example of this is the Light Sensor, which will return a percentage value from 0 to 100.


Parameter Explanation Data Type
sensor A sensor port or name tSensors


while(SensorValue(touchSensor) == 0) //Loop while robot's bumper/touch sensor isn't pressed in
{
   motor[rightMotor] = 63;   // Right motor is run at half (63) power forward
   motor[leftMotor]  = 63;   // Left motor is run at half (63) power forward
}