VEX2 Sensors Overview
(→Sonar) |
|||
| (17 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | <yambe:breadcrumb self="Sensors Overview">VEX2|CORTEX</yambe:breadcrumb> | |
| − | + | <br /> | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
{| | {| | ||
|- | |- | ||
| − | | | + | |''For ROBOTC CORTEX Sensor ''functions'', check out the [[VEX2_Functions_Sensors|CORTEX Sensor Functions]] page!'' |
|- | |- | ||
|} | |} | ||
| + | <br /> | ||
| + | {{tl|1|1}} | ||
| + | <br /> | ||
== Analog Sensors == | == Analog Sensors == | ||
| Line 53: | Line 31: | ||
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| − | task main | + | task main() |
{ | { | ||
wait1Msec(2000); // wait 2 seconds before exectuing following code | wait1Msec(2000); // wait 2 seconds before exectuing following code | ||
| Line 91: | Line 69: | ||
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| − | task main | + | task main() |
{ | { | ||
wait1Msec(2000); // wait 2 seconds before exectuing following code | wait1Msec(2000); // wait 2 seconds before exectuing following code | ||
| Line 128: | Line 106: | ||
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| − | task main | + | task main() |
{ | { | ||
wait1Msec(2000); // wait 2 seconds before exectuing following code | wait1Msec(2000); // wait 2 seconds before exectuing following code | ||
| Line 155: | Line 133: | ||
=== Gyro === | === Gyro === | ||
| + | [[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].'' | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop) | ||
| + | #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop, reversed) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | /*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++ | ||
| + | Gyro Based Turns - Basic | ||
| + | -This program instructs your robot to turn for the specified number of degrees in "degrees10". | ||
| + | -For best sensor results, clear out the gyro and manually configure it at the begging of the code. | ||
| + | -The Gyro is configured by default to provide values from 0 to -3600 for clockwise rotation, | ||
| + | and 0 to 3600 for counter-clockwise rotation | ||
| + | |||
| + | Robot Model(s): Swervebot | ||
| + | |||
| + | [I/O Port] [Name] [Type] [Description] | ||
| + | Motor Port 2 rightMotor VEX Motor Right side motor | ||
| + | Motor Port 3 leftMotor VEX Motor Left side motor | ||
| + | Analog Port 8 in8 VEX Gyro Top-center mounted, | ||
| + | away from the Cortex | ||
| + | --------------------------------------------------------------------------------------------------*/ | ||
| + | |||
| + | task main() | ||
| + | { | ||
| + | //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 === | === Accelerometer === | ||
[[File:vex_accel.png]] | [[File:vex_accel.png]] | ||
| Line 172: | Line 215: | ||
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| − | task main | + | task main() |
{ | { | ||
int nBiasValues[3]; | int nBiasValues[3]; | ||
| Line 204: | Line 247: | ||
|- | |- | ||
| | | | ||
| + | |- | ||
| + | |} | ||
| + | <br /> | ||
| + | |||
| + | == Digital Sensors == | ||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | |There are 6 main types of Analog Sensors for the VEX CORTEX: | ||
| + | |- | ||
| + | | | ||
| + | |||
| + | === Touch === | ||
| + | [[File:vex_touch_sensor.png]] | ||
| + | <br /> | ||
| + | Returns a digital value. "1" means a closed circuit and "0" means an open circuit. | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Sensor, dgtl6, touchSensor, sensorTouch) | ||
| + | #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) | ||
| + | #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | task main() | ||
| + | { | ||
| + | wait1Msec(2000); // Robot waits for 2000 milliseconds before executing program | ||
| + | |||
| + | while(SensorValue(touchSensor) == 0) // Loop while robot's bumper/touch sensor isn't pressed in | ||
| + | { | ||
| + | motor[rightMotor] = 63; // Motor on port2 is run at half (63) power forward | ||
| + | motor[leftMotor] = 63; // Motor on port3 is run at half (63) power forward | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | |||
| + | === Sonar === | ||
| + | [[File:vex_sonar_sensor.png]] | ||
| + | <br /> | ||
| + | Returns an analog value in centimeters (i.e. a value of 20 means 20 centimeters away), millimeters, inches, or raw data. A value of "-1" means the sensor does not receive a "reflection". The sonar sensor requires the "Input" wire to be attached the digital port directly following the main port of the Sonar Sensor (i.e. dgtl4 and dgtl5, ROBOTC will automatically fill the following port with the correct information). | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Sensor, dgtl8, sonarSensor, sensorSONAR_cm) | ||
| + | #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) | ||
| + | #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | task main() | ||
| + | { | ||
| + | wait1Msec(2000); // Robot waits for 2000 milliseconds before executing program | ||
| + | |||
| + | while(SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 cm away from an object | ||
| + | { // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range) | ||
| + | motor[rightMotor] = 63; // Motor on port2 is run at half (63) power forward | ||
| + | motor[leftMotor] = 63; // Motor on port3 is run at half (63) power forward | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | |||
| + | === Quadrature Encoder === | ||
| + | [[File:vex_quad_enc.png]] | ||
| + | <br /> | ||
| + | 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. | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder) | ||
| + | #pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder) | ||
| + | #pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) | ||
| + | #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | task main() | ||
| + | { | ||
| + | wait1Msec(2000); // 2 Second Delay | ||
| + | |||
| + | //Clear Encoders | ||
| + | SensorValue[rightEncoder] = 0; | ||
| + | SensorValue[leftEncoder] = 0; | ||
| + | |||
| + | while(SensorValue[leftEncoder] < 1800) // While less than 5 rotations on the leftEncoder... | ||
| + | { | ||
| + | //...Move Forward | ||
| + | motor[rightMotor] = 63; | ||
| + | motor[leftMotor] = 63; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | |||
| + | === Digital In === | ||
| + | This will make the sensor port act as just a digital input, very similar to a touch sensor. | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | // No sample code here yet! Somebody supply some! | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | | | ||
| + | |||
| + | === 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. | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Sensor, dgtl7, solenoid, sensorDigitalOut) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | task main() | ||
| + | { | ||
| + | while(true) // Loop Forever | ||
| + | { | ||
| + | if(vexRT[Btn6U] == 1) // If button 6U (upper right shoulder button) is pressed: | ||
| + | { | ||
| + | SensorValue[solenoid] = 1; // ...activate the solenoid. | ||
| + | } | ||
| + | else // If button 6U (upper right shoulder button) is NOT pressed: | ||
| + | { | ||
| + | SensorValue[solenoid] = 0; // ..deactivate the solenoid. | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
|- | |- | ||
|} | |} | ||
<br /> | <br /> | ||
Latest revision as of 08:28, 25 July 2012
| For ROBOTC CORTEX Sensor functions, check out the CORTEX Sensor Functions page! |
|
| |||||||
Analog Sensors
| There are 5 main types of Analog Sensors for the VEX CORTEX: | |
Light
| |
Potentiometer
| |
Line Follower
| |
Gyro
For more information on the Gyro sensor, check out the ROBOTC blog post: Programming the VEX Gyro in ROBOTC.
| |
Accelerometer
| |
Digital Sensors







