Tutorials/Programming with the new VEX Integrated Encoder Modules

Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <yambe:breadcrumb self="VEX Speaker module">Tutorials|Tutorials</yambe:breadcrumb> <br /> {| width="740px" |- |[[Image:tut_vex-motor-encoders...")
 
Line 6: Line 6:
 
|-
 
|-
 
|[[Image:tut_vex-motor-encoders_1.jpg|left|thumb|VEX Speaker]]
 
|[[Image:tut_vex-motor-encoders_1.jpg|left|thumb|VEX Speaker]]
|style="vertical-align: top;"|The VEX Cortex is an incredibly powerful and versatile microcontroller. Part of what makes it so versatile is the basic 3-pin system (Power, Signal, Ground) it uses for inputs and outputs.
+
|style="vertical-align: top;"|ROBOTC 3.06 now includes functionality to support the new VEX Integrated Encoder Modules!
  
When coupled with a powerful programming language like ROBOTC, the VEX Cortex allows you to connect all types of third-party sensors (and actuators) with little or no effort. Taken from the [http://www.vexforum.com/wiki/index.php/VEX_Cortex_Microcontroller VEX Wiki], any analog sensor can be connected to the Cortex as long as its characteristics align with the following:
+
The VEX Integrated Encoder Modules (IEMs) replace the plastic caps on the backs of 2-Wire Motors (269 and 393) with quadrature encoders. Unlike the existing VEX Shaft Encoders, they connect to the Cortex Microcontroller using the I2C port and provide feedback directly from the motor (with the added benefit of not hogging up your digital ports). These encoders will allow you to identify and control how fast the motors spin, how far the robot travels, and what direction it should move.
* Output voltage range: 0.0 v to 5.0 v.
+
* Must not exceed -0.5v to +5.5v.
+
  
Likewise, any digital sensor can be directly connected to the Cortex as long as its characteristics align with the following:
+
For more information and assembly instructions for the Integrated Motor Encoder for the '''VEX 2-wire 393 Motor''', [http://www.robotc.net/blog/wp-content/uploads/2012/02/393.pdf click here].
* Provides 0.0 to 0.6 volts for a low and 2.5 to 5.0 volts for a high.
+
 
* Must not exceed -0.5v or +5.5v.
+
For more information and assembly instructions for the Integrated Motor Encoder for the '''VEX 2-wire 269'''tor''', [http://www.robotc.net/blog/wp-content/uploads/2012/02/269.pdf click here].
 
|-
 
|-
 
|colspan="2"|All of the basic Fischertechnik sensors meet these qualifying characteristics, making them perfect candidates for use with the VEX Cortex!
 
|colspan="2"|All of the basic Fischertechnik sensors meet these qualifying characteristics, making them perfect candidates for use with the VEX Cortex!
Line 20: Line 18:
 
<br />
 
<br />
  
== Analog Sensors Example: Fischertechnic Photoresistor ==
+
== I2C Overview ==
 
{|width="740px"
 
{|width="740px"
 
|-
 
|-
|Based on the [http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/reference/cortex_schematic.pdf VEX Cortex Schematic], the SIGNAL line in the ANALOG INPUTS bank is closest to the USB Port in the center of the Cortex, with the +5 VOLTS line next, and finally the GROUND line. The Fischertechnic analog sensors only have two output pins, and we’ll be connecting them to the SIGNAL and +5V lines.
+
|As stated above, these new encoders connect to the single I2C port on the Cortex:
|-
+
|colspan="2"|[[Image:tut_fischertechnik_2.png|left|Schematic]]
+
|-
+
|colspan="2"|In the picture below, we used the connector pins that come with the Fischertechnik system to connect the photoresistor to male-to-male jumper cables, which can be plugged directly into the Cortex. Note that with these basic analog sensors, polarity does not matter; it only matters that you use the SIGNAL and +5V lines on the Cortex.
+
|-
+
|colspan="2"|[[Image:tut_fischertechnik_3.jpg|left|700px|Photoresistor]]
+
|-
+
|colspan="2"|With the sensor properly connected, configuring it in ROBOTC is no more difficult than any of the official VEX sensors. In the Motors and Sensors Setup, on the VEX 2.0 Analog Sensors 1-8 tab, give the sensor a name and choose from Potentiometer, Light Sensor, or Line Follower for the sensor type. Any of these three types will work, as they are set up to return the raw A-to-D (Analog-to-Digital) values from the sensor. The Gyro and Accelerometer sensor types perform additional calculations on the raw sensor data, making them inappropriate choices for a basic analog sensor like the photoresistor. The VEX Light Sensor is the most similar to the Fischertechnik photoresistor, so it’s the logical choice.
+
|-
+
|colspan="2"|[[Image:tut_fischertechnik_4.png|700px|left]]
+
|-
+
|colspan="2"|The values from the photoresistor can be used in your ROBOTC programs just like any of the other sensors – using the <span class="keywordB">SensorValue</span><span class="codePunc">[]</span> command. The ROBOTC Natural Language commands like <span class="keywordB">untilLight</span><span class="codePunc">()</span> and <span class="keywordB">untilDark</span><span class="codePunc">()</span> will also work!<br />
+
<syntaxhighlight lang="ROBOTC">
+
#pragma config(Sensor, in1,    FTPhotoresistor, sensorReflection)
+
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
+
+
task main()
+
{
+
  while(SensorValue[FTPhotoresistor] < 2000)
+
  {
+
    //Code
+
  }
+
}
+
</syntaxhighlight>
+
|-
+
|colspan="2"|Also, just like any of the official sensors, the value from the Fischertechnik sensors will appear in the ROBOTC Sensors Debug window!
+
|-
+
|[[Image:tut_fischertechnik_9.png|left|Sensor Debug - FTPhotoresistor]]
+
|}
+
<br />
+
 
+
== Digital Sensors Example: Fischertechnic Touch Sensor ==
+
{|width="740px"
+
|-
+
|Unlike the photoresistor, the touch sensor has three pins and we’ll need to be careful about how we plug them into the Cortex. We’ll need to plug the pin labeled 1 into the GROUND line on the Cortex, the pin labeled 2 into the SIGNAL line, and the pin labeled 3 into the +5V line. Failure to do so can result in the sensor always reading 1, always reading 0, or having the values reversed (0 = pushed, 1 = not pushed).
+
|-
+
|colspan="2"|[[Image:tut_fischertechnik_5.jpg|left|700px|Touch Sensor Closeup]]
+
|-
+
|colspan="2"|Below is a picture of the sensor connected to the Cortex. Note that all three lines are used, and that the Fischertechnik connectors were again used to connect the sensor to jumper cables.
+
|-
+
|colspan="2"|[[Image:tut_fischertechnik_6.jpg|left|700px|Touch Sensor]]
+
|-
+
|colspan="2"|The Fischertechnik touch sensor can be configured as a Touch Sensor or Digital Input in the ROBOTC Motors and Sensors Setup window.
+
 
|-
 
|-
|colspan="2"|[[Image:tut_fischertechnik_7.png|700px|left]]
+
|colspan="2"|[[Image:tut_vex-motor-encoders_2.jpg|left|I2C port]]
 
|-
 
|-
|colspan="2"|The values from the digital touch sensor can be used in your ROBOTC programs just like any of the other sensors – using the <span class="keywordB">SensorValue</span><span class="codePunc">[]</span> command. The ROBOTC Natural Language commands like <span class="keywordB">untilLight<span class="codePunc">()</span> and <span class="keywordB">untilDark<span class="codePunc">()</span> will also work!<br />
+
|colspan="2"|Unlike the DIGITAL and ANALOG ports on the Cortex, having only one I2C port does not limit you to only one I2C device. I2C ports allow multiple devices to be connected in a manner frequently referred to as daisy-chaining:
<syntaxhighlight lang="ROBOTC">
+
#pragma config(Sensor, dgtl4,  FTTouch,        sensorDigitalIn)
+
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//
+
+
task main()
+
{
+
  while(SensorValue[FTTouch] == 0)
+
  {
+
    //Code
+
  }
+
}
+
</syntaxhighlight>
+
 
|-
 
|-
|colspan="2"|And the Sensor Debug window will display whether the sensor is pressed in or released:
+
|colspan="2"|[[Image:tut_vex-motor-encoders_3.jpg|left|700px|Daisychain]]
 
|-
 
|-
|[[Image:tut_fischertechnik_8.png|left|Sensor Debug - Digital]]
+
|colspan="2"|The Integrated Encoder Modules support this by having built-in sets of input and output pins. A 4-wire cable connects the Cortex to Motor 1, another 4-wire cable connects Motor 1 to Motor 2, another 4-wire cable connects Motor 2 to Motor 3, and so on. In fact, ROBOTC 3.06 will support up to 8 devices on the single I2C port!
 
|-
 
|-
|As you can see, connecting third-party sensors to the Cortex and making use of them in ROBOTC isn’t much more complicated than using any of the official sensors. Happy programming!
+
|colspan="2"|[[Image:tut_vex-motor-encoders_4.png|700px|left|269]]
 
|}
 
|}
 
<br />
 
<br />

Revision as of 08:50, 7 May 2012

Tutorials → VEX Speaker module


VEX Speaker
ROBOTC 3.06 now includes functionality to support the new VEX Integrated Encoder Modules!

The VEX Integrated Encoder Modules (IEMs) replace the plastic caps on the backs of 2-Wire Motors (269 and 393) with quadrature encoders. Unlike the existing VEX Shaft Encoders, they connect to the Cortex Microcontroller using the I2C port and provide feedback directly from the motor (with the added benefit of not hogging up your digital ports). These encoders will allow you to identify and control how fast the motors spin, how far the robot travels, and what direction it should move.

For more information and assembly instructions for the Integrated Motor Encoder for the VEX 2-wire 393 Motor, click here.

For more information and assembly instructions for the Integrated Motor Encoder for the VEX 2-wire 269tor, click here.

All of the basic Fischertechnik sensors meet these qualifying characteristics, making them perfect candidates for use with the VEX Cortex!


I2C Overview

As stated above, these new encoders connect to the single I2C port on the Cortex:
I2C port
Unlike the DIGITAL and ANALOG ports on the Cortex, having only one I2C port does not limit you to only one I2C device. I2C ports allow multiple devices to be connected in a manner frequently referred to as daisy-chaining:
Daisychain
The Integrated Encoder Modules support this by having built-in sets of input and output pins. A 4-wire cable connects the Cortex to Motor 1, another 4-wire cable connects Motor 1 to Motor 2, another 4-wire cable connects Motor 2 to Motor 3, and so on. In fact, ROBOTC 3.06 will support up to 8 devices on the single I2C port!
269


Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox