RobotC Sensors
Learning Objectives Take a look at some of the options for VEX Sensors Be able to configure sensors Be able to use a touch sensor/limit switch to limit the movement of an arm Be able to implement functions to help organize code Be able to use the Ultrasonic Sensor to drive forward until you are near an object Be able to use light sensors to track a line
Sensor Ports UART (Universal Asynchronous Receiver/Transmitter) Ports 1, 2 Analog Ports 1-8 I2C Inter-integrated Circuit Protocol Allows several devices to be chained to one port. Digital Ports 1-12 Speaker
Analog Sensors Light Sensor: 0 – 6 Feet 0 = Very Bright 255 = Dark Line Tracker: LED Light + Light Sensor
Analog: Line Tracker Infrared light sensor and infrared LED. Lights the surface and measures the light reflected. Analog: 0 = Bright, Full Scale (4096 for Cortex, 1023 for PIC) = Dark More Info at http://content.vexrobotics.com/docs/instructions/276-2154-Line- Tracker-Instr-0312.pdf
Potentiometer: Analog Measure the angle position Measures 0 to 250 degrees +/- 20 Return values from 0 to 4096 Be careful, the sensor should not rotate beyond 250 degrees.
Analog Accelerometer Measures acceleration non three axis simultaneously Each channel being used connects to the controller (Cortex)
Digital: Limit Switch/ Bumper Switch Can sense when arms reach their limit.
Digital Sensors Ultrasonic Uses two digital ports Sensitivity: Detects a 3cm diameter pole at greater than 2m Usable Range: 3.0 cm to 3.0 m / 1.5 in – 115 in
Digital Optical Shaft Encoder Takes two digital ports Can detect of to 1700 pulses per second = 18.9 rev/sec = 1133 rev/min
I2C Sensor Integrated motor encoders Since it is I2C you can chain several (8?) encoders onto one I2C port. http://www.vexrobotics.com/vex/products/ac cessories/sensors/encodermodules.html Measures 627.2 ticks per revolution when the motor is geared for torque.
We will use the Squarebot for Sensors Section
Configuring the Limit Switch 1) Select the Digital Sensors Tab Robot -> Motors and Sensors Setup 3) Use the pull-down menu to select Touch. 2) Name the Sensor frontLimit 4) Apply and OK.
Configuring the Potentiometer Robot -> Motors and Sensors Setup Select Analog Sensors tab Using port 6 Name the variable: armPot Select ‘Potentiometer’ from the drop down menu Apply OK
Using the Limit Switch Can sense when arms reach their limit. 0 when not pressed 1 when pressed
Preventing the Arm From Lowering Too Far Pseudo Code If the down button is pressed AND the limit switch is not pressed Go down AND? Remember the conjunctions?
Conjunctions Conditions can be combined using conjunctions && (AND) while ((SensorValue[rightEncoder]<1800) && (SensorValue[leftEncoder] <1800)) { //while both encoders are less than 1800 it will repeat the code in the {} block } || (OR) while ((SensorValue[rightEncoder]<1800) || (SensorValue[leftEncoder] <1800)) { // While either the leftEncoder<1800 or the rightEncoder is <1800 it will //repeat the code inside the {} block ! (NOT) Turns true to false and false to true while !(SensorValue(leftEncoder)>1800)
The && can only combine two complete conditions. Putting it together Pseudo Code If the down button is pressed AND the limit switch is not pressed Go down The && can only combine two complete conditions.
Using the Potentiometer to Limit Go to http://education.rec.ri.cmu.edu/products/cortex_video_trainer/lesson/5-2LimitingtheArm3.html And follow the video trainer lesson