Tutorials/Programming with the new VEX Integrated Encoder Modules

From ROBOTC API Guide
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...")
 
 
(16 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
<yambe:breadcrumb self="VEX Speaker module">Tutorials|Tutorials</yambe:breadcrumb>
+
<yambe:breadcrumb self="Programming with the new VEX Integrated Encoder Modules">Tutorials|Tutorials</yambe:breadcrumb>
 
<br />
 
<br />
  
 
{| width="740px"
 
{| width="740px"
 
|-
 
|-
|[[Image:tut_vex-motor-encoders_1.jpg|left|thumb|VEX Speaker]]
+
|[[Image:tut_vex-motor-encoders_1.jpg|left|thumb|VEX motors with IME's installed]]
|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''', [[Media: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 Motor''', [[Media: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!
 
|}
 
|}
 
<br />
 
<br />
 +
{{toc}}
  
== 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]]
+
|[[Image:tut_vex-motor-encoders_2.jpg|700px|left|I2C port]]
 
|-
 
|-
|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.
+
|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:
 
|-
 
|-
|colspan="2"|[[Image:tut_fischertechnik_3.jpg|left|700px|Photoresistor]]
+
|[[Image:tut_vex-motor-encoders_3.jpg|left|700px|Daisychain]]
 
|-
 
|-
|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.
+
|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!
 
|-
 
|-
|colspan="2"|[[Image:tut_fischertechnik_4.png|700px|left]]
+
|[[Image:tut_vex-motor-encoders_4.png|700px|left|269]]
 +
|}
 +
<br />
 +
 
 +
== Programming Overview ==
 +
=== Motors and Sensors Setup ===
 +
{|width="740px"
 
|-
 
|-
|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 />
+
|ROBOTC has undergone substantial changes to support the new encoders. Some of the most visually noticeable changes are in the Motors and Sensors Setup. On the Motors tab, the Type drop-down box allows you to choose from the different motors available in the VEX Robotics System:
<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_vex-motor-encoders_5.png|700px|left]]
 
|-
 
|-
|[[Image:tut_fischertechnik_9.png|left|Sensor Debug - FTPhotoresistor]]
+
|This is significant because each of the new IEMs return a different number of encoder counts per revolution. Specifically, the IEM for the '''2-wire 269 motor measures 240.448 counts per revolution''' of the motor output shaft. The '''2-wire 393 motor measures 627.2 counts per revolution''' of the output shaft in its default '''high-torque''' configuration and  '''392 counts per revolution''' of the output shaft in its modified '''high-speed''' configuration.
 +
<br />
 +
Let’s take a look at a physical robot and configure it using the Motors and Sensors Setup.
 +
|-
 +
|[[Image:tut_vex-motor-encoders_6.jpg|left|700px]]
 +
|-
 +
|
 +
*This robot has two 269 motors with encoders.
 +
*The right motor is connected on MOTOR port 1. The left motor is connected on MOTOR port 10.
 +
*The encoder on the right motor is the first device plugged into the I2C port.
 +
*The encoder on the left motor is the second device, daisy-chained off of the right motor.
 +
|-
 +
|[[Image:tut_vex-motor-encoders_7.jpg|700px|left]]
 +
|-
 +
|We can configure this in ROBOTC by going to the Robot > Motors and Sensors Setup menu.
 +
|-
 +
|[[Image:tut_vex-motor-encoders_8.png|left]]
 +
|-
 +
|On the motors tab, we can enter all of the information necessary so that it matches our physical robot:
 +
|-
 +
|[[Image:tut_vex-motor-encoders_9.png|700px|left]]
 +
|-
 +
|Note that:
 +
*“rightMotor” was configured in port1 as a VEX 269 Motor.
 +
*rightMotor was “Reversed” so that positive power levels will allow the robot to move forward.
 +
*The “Encoder” box was checked and “I2C_1″ was chosen since it is the first device plugged in to the Cortex.
 +
*“leftMotor” was configured in port10 as a VEX 269 Motor.
 +
*The “Encoder” box was checked and “I2C_2″ was chosen since it is the second device along the daisy-chain.
 +
*It is not necessary that the order of your motor ports correspond with the order of the I2C ports, although doing so will reduce confusion. It is necessary that your Motors and Sensors Setup perfectly match the physical setup of your robot.
 +
 
 +
 
 +
Additionally, you’ll notice that there is also a new “I2C Sensors” tab in the Motors and Sensors Setup:
 +
|-
 +
|[[Image:tut_vex-motor-encoders_10.png|700px|left]]
 +
|-
 +
|The additional configuration you can do here is '''optional'''. Like existing VEX Sensors, you can use this tab to name your I2C devices and monitor their values in the Sensor Debug Window. Note that these values are the raw values – not adjusted for polarity or the “Reversed” checkbox on the Motors tab.
 +
 
 +
When you’re done configuring your motors and encoders, you can press '''OK''' to apply your changes.
 
|}
 
|}
 
<br />
 
<br />
  
== Digital Sensors Example: Fischertechnic Touch Sensor ==
+
=== Function Library ===
 
{|width="740px"
 
{|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).
+
|In addition to the Motors and Sensors Setup, you’ll also notice new commands available in the Function Library. Most notably, we’ve included the <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command.
 
|-
 
|-
|colspan="2"|[[Image:tut_fischertechnik_5.jpg|left|700px|Touch Sensor Closeup]]
+
|[[Image:tut_vex-motor-encoders_11.png|left]]
 
|-
 
|-
|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.
+
|Those of you familiar with the NXT system will be very familiar with the <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command. To those who are not, it acts very similarly to the <span class="keywordB">SensorValue</span><span class="codePunc">[]</span> command you may be more used to. The <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command gives you read-write access the value of the encoder associated with the motor specified within the brackets.
|-
+
|}
|colspan="2"|[[Image:tut_fischertechnik_6.jpg|left|700px|Touch Sensor]]
+
<br />
|-
+
 
|colspan="2"|The Fischertechnik touch sensor can be configured as a Touch Sensor or Digital Input in the ROBOTC Motors and Sensors Setup window.
+
=== Sample Code ===
 +
{|width="740px"
 
|-
 
|-
|colspan="2"|[[Image:tut_fischertechnik_7.png|700px|left]]
+
|For example, in the sample code below, the <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command is used to clear the values of the encoders on lines 19 and 20, and then also control the distance the robot moves in the while loop on line 23. This program will cause the robot to move forward for a specified number of encoder counts (1000), while displaying encoder values to the VEX LCD.
 
|-
 
|-
|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 />
+
|<syntaxhighlight lang="ROBOTC">
<syntaxhighlight lang="ROBOTC">
+
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl4, FTTouch,        sensorDigitalIn)
+
#pragma config(Sensor, I2C_1,    rightIEM,            sensorQuadEncoderOnI2CPort,        , AutoAssign)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
+
#pragma config(Sensor, I2C_2,     leftIEM,                sensorQuadEncoderOnI2CPort,        , AutoAssign)
 +
#pragma config(Motor,    port1,                        rightMotor,        tmotorVex269, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
 +
#pragma config(Motor,    port10,                    leftMotor,        tmotorVex269, openLoop, encoder, encoderPort, I2C_2, 1000)
 +
//*!!Code automatically generated by 'ROBOTC' configuration wizard                             !!*//
 
   
 
   
task main()
+
task main
 
{
 
{
   while(SensorValue[FTTouch] == 0)
+
   wait1Msec(2000);
 +
 +
  //Setup the VEX LCD for displaying encoder values
 +
  clearLCDLine(0);
 +
  clearLCDLine(1);
 +
  displayLCDString(0, 0, "R: ");
 +
  displayLCDString(1, 0, "L: ");
 +
 +
  //Clear the encoders associated with the left and right motors
 +
  nMotorEncoder[rightMotor] = 0;
 +
  nMotorEncoder[leftMotor] = 0;
 +
 +
  //While less than 1000 encoder counts of the right motor
 +
  while(nMotorEncoder[rightMotor] < 1000)
 
   {
 
   {
     //Code
+
     //Display the right and left motor encoder values
 +
    displayLCDNumber(0, 3, nMotorEncoder[rightMotor], 6);
 +
    displayLCDNumber(1, 3, nMotorEncoder[leftMotor], 6);
 +
 
 +
    //Move forward at half power
 +
    motor[rightMotor] = 63;
 +
    motor[leftMotor]    = 63;
 
   }
 
   }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|-
 
|-
|colspan="2"|And the Sensor Debug window will display whether the sensor is pressed in or released:
+
|You can see the code running on an the robot here:
 +
{{#ev:youtubehd|LGynIouwrZM}}
 
|-
 
|-
|[[Image:tut_fischertechnik_8.png|left|Sensor Debug - Digital]]
+
|For a more detailed explanation of how this code and encoders work, you should check out the videos in the  Movement > Shaft Encoders section of the [http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/index.html VEX Cortex Video Trainer]. For more information on the <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command and how it is used in the NXT system, check out this video.
 +
|}
 +
<br />
 +
 
 +
=== Motors Debug Window ===
 +
{|width="740px"
 
|-
 
|-
|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!
+
|Yet another change in ROBOTC to support the new encoders was made in the Motors debug window, found by going to Robot > Debug Windows > Motors. ROBOTC will now display the Type of motor you have connected and the Encoder value as your robot runs.
 +
|-
 +
|[[Image:tut_vex-motor-encoders_12.png|left]]
 +
|-
 +
|This window, unlike the Sensor Debug window, will take the motor “Reversed” setting and polarity into account; positive motor powers will always result in positive encoder values and negative motor powers will always result in negative encoder values. In other words, the Encoder column displays the same value that gets returned by the <span class="keywordB">nMotorEncoder</span><span class="codePunc">[]</span> command.
 
|}
 
|}
 
<br />
 
<br />
 +
 +
== Conclusion and Future Development ==
 +
{|width="740px"
 +
|-
 +
|The new VEX Integrated Encoder Modules are a fantastic addition to the VEX Robotics System, which we’re thrilled to support in ROBOTC. That being the case, we have additional improvements with the encoders coming down the pipeline. With integrated encoders, we’ll be able to implement “Encoder Targets” and “PID Control” like we have available for the NXT Platform. With Encoder Targets, you’ll be able to specify a “target” encoder value for the motors to spin to, and the robot will actually slow to a stop at that value, rather than letting its momentum carry it too far. With PID, we’ll be able to use feedback from the encoders to constantly adjust the power levels of the motors so that their physical performance matches what you set in the code – all with no extra effort on your part! Again for lots of additional information on both Encoder Targets and PID Control, check out the Movement > Improved Movement section of [http://www.education.rec.ri.cmu.edu/previews/robot_c_products/teaching_rc_lego_v2_preview/ Teaching ROBOTC for Mindstorms].<br />
 +
 +
Finally, if the VEX IEM’s seem like something you’d like to have (and they should) you can purchase them for the [http://robomatter.com/Shop-By-Robot/VEX-Robots/Hardware/Mechanics/Motor-393-Integrated-Encoder-Module-2-pack 2-wire 393 Motors here], and the [http://robomatter.com/Shop-By-Robot/VEX-Robots/Hardware/Mechanics/Motor-269-Integrated-Encoder-Module-2-pack 2-wire 269 Motors here].
 +
|}

Latest revision as of 13:08, 6 December 2012

Tutorials → Programming with the new VEX Integrated Encoder Modules


VEX motors with IME's installed
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 269 Motor, click here.

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


Contents


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


Programming Overview

Motors and Sensors Setup

ROBOTC has undergone substantial changes to support the new encoders. Some of the most visually noticeable changes are in the Motors and Sensors Setup. On the Motors tab, the Type drop-down box allows you to choose from the different motors available in the VEX Robotics System:
Tut vex-motor-encoders 5.png
This is significant because each of the new IEMs return a different number of encoder counts per revolution. Specifically, the IEM for the 2-wire 269 motor measures 240.448 counts per revolution of the motor output shaft. The 2-wire 393 motor measures 627.2 counts per revolution of the output shaft in its default high-torque configuration and 392 counts per revolution of the output shaft in its modified high-speed configuration.


Let’s take a look at a physical robot and configure it using the Motors and Sensors Setup.

Tut vex-motor-encoders 6.jpg
  • This robot has two 269 motors with encoders.
  • The right motor is connected on MOTOR port 1. The left motor is connected on MOTOR port 10.
  • The encoder on the right motor is the first device plugged into the I2C port.
  • The encoder on the left motor is the second device, daisy-chained off of the right motor.
Tut vex-motor-encoders 7.jpg
We can configure this in ROBOTC by going to the Robot > Motors and Sensors Setup menu.
Tut vex-motor-encoders 8.png
On the motors tab, we can enter all of the information necessary so that it matches our physical robot:
Tut vex-motor-encoders 9.png
Note that:
  • “rightMotor” was configured in port1 as a VEX 269 Motor.
  • rightMotor was “Reversed” so that positive power levels will allow the robot to move forward.
  • The “Encoder” box was checked and “I2C_1″ was chosen since it is the first device plugged in to the Cortex.
  • “leftMotor” was configured in port10 as a VEX 269 Motor.
  • The “Encoder” box was checked and “I2C_2″ was chosen since it is the second device along the daisy-chain.
  • It is not necessary that the order of your motor ports correspond with the order of the I2C ports, although doing so will reduce confusion. It is necessary that your Motors and Sensors Setup perfectly match the physical setup of your robot.


Additionally, you’ll notice that there is also a new “I2C Sensors” tab in the Motors and Sensors Setup:

Tut vex-motor-encoders 10.png
The additional configuration you can do here is optional. Like existing VEX Sensors, you can use this tab to name your I2C devices and monitor their values in the Sensor Debug Window. Note that these values are the raw values – not adjusted for polarity or the “Reversed” checkbox on the Motors tab.

When you’re done configuring your motors and encoders, you can press OK to apply your changes.


Function Library

In addition to the Motors and Sensors Setup, you’ll also notice new commands available in the Function Library. Most notably, we’ve included the nMotorEncoder[] command.
Tut vex-motor-encoders 11.png
Those of you familiar with the NXT system will be very familiar with the nMotorEncoder[] command. To those who are not, it acts very similarly to the SensorValue[] command you may be more used to. The nMotorEncoder[] command gives you read-write access the value of the encoder associated with the motor specified within the brackets.


Sample Code

For example, in the sample code below, the nMotorEncoder[] command is used to clear the values of the encoders on lines 19 and 20, and then also control the distance the robot moves in the while loop on line 23. This program will cause the robot to move forward for a specified number of encoder counts (1000), while displaying encoder values to the VEX LCD.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,     rightIEM,             sensorQuadEncoderOnI2CPort,        , AutoAssign)
#pragma config(Sensor, I2C_2,     leftIEM,                 sensorQuadEncoderOnI2CPort,        , AutoAssign)
#pragma config(Motor,     port1,                        rightMotor,         tmotorVex269, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor,     port10,                    leftMotor,         tmotorVex269, openLoop, encoder, encoderPort, I2C_2, 1000)
//*!!Code automatically generated by 'ROBOTC' configuration wizard                             !!*//
 
task main
{
  wait1Msec(2000);
 
  //Setup the VEX LCD for displaying encoder values
  clearLCDLine(0);
  clearLCDLine(1);
  displayLCDString(0, 0, "R: ");
  displayLCDString(1, 0, "L: ");
 
  //Clear the encoders associated with the left and right motors
  nMotorEncoder[rightMotor] = 0;
  nMotorEncoder[leftMotor] = 0;
 
  //While less than 1000 encoder counts of the right motor
  while(nMotorEncoder[rightMotor] < 1000)
  {
    //Display the right and left motor encoder values
    displayLCDNumber(0, 3, nMotorEncoder[rightMotor], 6);
    displayLCDNumber(1, 3, nMotorEncoder[leftMotor], 6);
 
    //Move forward at half power
    motor[rightMotor] = 63;
    motor[leftMotor]    = 63;
  }
}
You can see the code running on an the robot here:


For a more detailed explanation of how this code and encoders work, you should check out the videos in the Movement > Shaft Encoders section of the VEX Cortex Video Trainer. For more information on the nMotorEncoder[] command and how it is used in the NXT system, check out this video.


Motors Debug Window

Yet another change in ROBOTC to support the new encoders was made in the Motors debug window, found by going to Robot > Debug Windows > Motors. ROBOTC will now display the Type of motor you have connected and the Encoder value as your robot runs.
Tut vex-motor-encoders 12.png
This window, unlike the Sensor Debug window, will take the motor “Reversed” setting and polarity into account; positive motor powers will always result in positive encoder values and negative motor powers will always result in negative encoder values. In other words, the Encoder column displays the same value that gets returned by the nMotorEncoder[] command.


Conclusion and Future Development

The new VEX Integrated Encoder Modules are a fantastic addition to the VEX Robotics System, which we’re thrilled to support in ROBOTC. That being the case, we have additional improvements with the encoders coming down the pipeline. With integrated encoders, we’ll be able to implement “Encoder Targets” and “PID Control” like we have available for the NXT Platform. With Encoder Targets, you’ll be able to specify a “target” encoder value for the motors to spin to, and the robot will actually slow to a stop at that value, rather than letting its momentum carry it too far. With PID, we’ll be able to use feedback from the encoders to constantly adjust the power levels of the motors so that their physical performance matches what you set in the code – all with no extra effort on your part! Again for lots of additional information on both Encoder Targets and PID Control, check out the Movement > Improved Movement section of Teaching ROBOTC for Mindstorms.

Finally, if the VEX IEM’s seem like something you’d like to have (and they should) you can purchase them for the 2-wire 393 Motors here, and the 2-wire 269 Motors here.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox