Difference between revisions of "VEX2 Sensors Overview"

From ROBOTC API Guide
Jump to: navigation, search
Line 41: Line 41:
 
|
 
|
 
=== Light ===
 
=== Light ===
[[File:Vex reflection.png]]
+
|-
 +
|
 +
 
 +
=== Potentiometer ===
 +
[[File:Vex pot.png]]
 
<br />
 
<br />
The Light sensor, also known as the Reflection sensor, returns values ranging between 0 and 4095.  0 is the lightest reading and 4095 is the darkest.
+
Returns an analog value between 0 and 4095 ''(although mechanical stops my limit the values to between 5 and 4092)''.
 
<br />
 
<br />
  
Line 50: Line 54:
 
   |
 
   |
 
<syntaxhighlight lang="ROBOTC">
 
<syntaxhighlight lang="ROBOTC">
#pragma config(Sensor, in1,    lineFollower,   sensorLineFollower)
+
#pragma config(Sensor, in1,    potentiometer, sensorPotentiometer)
 
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
 
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
  
Line 60: Line 64:
 
   while(true)                    // infinite loop:
 
   while(true)                    // infinite loop:
 
   {
 
   {
     if(SensorValue(lineFollower) < 950) // if the lineFollower sensor reads a value less than 950:
+
     clearLCDLine(0);                                  // clear the top VEX LCD line
     {
+
     clearLCDLine(1);                                  // clear the bottom VEX LCD line
      // turn left:
+
   
      motor[port2] = 50; // motor on port 2 is run at power level 50
+
    setLCDPosition(0,0);                             // set the VEX LCD cursor the first line, first space
      motor[port3] = 0;   // motor on port 3 is stopped at power level 0
+
    displayNextLCDString("Potentiometer:");           // display "Potentiometer:" on the top line
     }
+
      
     else  // lineFollower sensor reads a value greater than or equal to 950:
+
     setLCDPosition(1,0);                              //set the VEX LCD cursor the second line, first space
     {
+
     displayNextLCDNumber(SensorValue(potentiometer)); // display the reading of the potentiometer sensor
      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
+
    wait1Msec(50);                                   // wait 50 milliseconds to help display properly
    }
+
 
   }
 
   }
 
}
 
}
Line 78: Line 81:
 
|-
 
|-
 
|
 
|
 
+
=== Line Follower ===
=== Potentiometer ===
+
[[File:Vex reflection.png]]
[[File:Vex pot.png]]
+
 
<br />
 
<br />
Returns an analog value between 0 and 4095 ''(although mechanical stops my limit the values to between 5 and 4092)''.
+
The Light sensor, also known as the Reflection sensor, returns values ranging between 0 and 4095.  0 is the lightest reading and 4095 is the darkest.
 
<br />
 
<br />
  
Line 89: Line 91:
 
   |
 
   |
 
<syntaxhighlight lang="ROBOTC">
 
<syntaxhighlight lang="ROBOTC">
#pragma config(Sensor, in1,    potentiometer, sensorPotentiometer)
+
#pragma config(Sensor, in1,    lineFollower,   sensorLineFollower)
 
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
 
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
  
Line 99: Line 101:
 
   while(true)                    // infinite loop:
 
   while(true)                    // infinite loop:
 
   {
 
   {
     clearLCDLine(0);                                  // clear the top VEX LCD line
+
     if(SensorValue(lineFollower) < 950) // if the lineFollower sensor reads a value less than 950:
     clearLCDLine(1);                                  // clear the bottom VEX LCD line
+
     {
   
+
      // turn left:
    setLCDPosition(0,0);                             // set the VEX LCD cursor the first line, first space
+
      motor[port2] = 50; // motor on port 2 is run at power level 50
    displayNextLCDString("Potentiometer:");           // display "Potentiometer:" on the top line
+
      motor[port3] = 0;   // motor on port 3 is stopped at power level 0
      
+
     }
     setLCDPosition(1,0);                              //set the VEX LCD cursor the second line, first space
+
     else  // lineFollower sensor reads a value greater than or equal to 950:
     displayNextLCDNumber(SensorValue(potentiometer)); // display the reading of the potentiometer sensor
+
     {
   
+
      motor[port2] = 0;   // motor on port 2 is stopped at power level 0
    wait1Msec(50);                                   // wait 50 milliseconds to help display properly
+
      motor[port3] = 50; // motor on port 3 is run at power level 50
 +
    }
 
   }
 
   }
 
}
 
}
Line 114: Line 117:
 
   |-
 
   |-
 
   |}
 
   |}
|-
 
|
 
=== Line Follower ===
 
 
|-
 
|-
 
|
 
|

Revision as of 18:37, 15 February 2012

Main >> CORTEX >> Sensors Overview


For ROBOTC CORTEX Sensor functions, check out the CORTEX Sensor Functions page!

The VEX 2.0 Cortex is equipped with 20 sensor ports. There are 8 Analog Sensor Ports and 12 Digital Sensor Ports. Note that unlike the VEX - PIC microcontroller, all Analog sensors must be in Analog ports, while all Digital sensors must be in Digital 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 2.0 Cortex 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 'dgtl3'!
  • The port that the sensor is connected to.
  • The type of sensor – touch, quadrature encoder, sonar, line follower, etc.



Analog Sensors

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

Light

Potentiometer

Vex pot.png
Returns an analog value between 0 and 4095 (although mechanical stops my limit the values to between 5 and 4092).

#pragma config(Sensor, in1,    potentiometer,  sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
 
task main
{
  wait1Msec(2000);                // wait 2 seconds before exectuing following code
  bMotorReflected[port2] = true;  // reflects direction of motor on port 2
 
  while(true)                     // infinite loop:
  {
    clearLCDLine(0);                                  // clear the top VEX LCD line
    clearLCDLine(1);                                  // clear the bottom VEX LCD line
 
    setLCDPosition(0,0);                              // set the VEX LCD cursor the first line, first space
    displayNextLCDString("Potentiometer:");           // display "Potentiometer:" on the top line
 
    setLCDPosition(1,0);                              //set the VEX LCD cursor the second line, first space
    displayNextLCDNumber(SensorValue(potentiometer)); // display the reading of the potentiometer sensor
 
    wait1Msec(50);                                    // wait 50 milliseconds to help display properly
  }
}

Line Follower

File:Vex reflection.png
The Light sensor, also known as the Reflection sensor, returns values ranging between 0 and 4095. 0 is the lightest reading and 4095 is the darkest.

#pragma config(Sensor, in1,    lineFollower,   sensorLineFollower)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
 
task main
{
  wait1Msec(2000);                // wait 2 seconds before exectuing following code
  bMotorReflected[port2] = true;  // reflects direction of motor on port 2
 
  while(true)                     // infinite loop:
  {
    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
    }
  }
}

Gyro

Accelerometer