Difference between revisions of "TETRIX Servo Controller"

From ROBOTC API Guide
Jump to: navigation, search
(Created page with "{| style="font-family:Verdana, Genega, sans-sarif; font-size:80%;color:gray;" width="100%" cellpadding="0%" cellspacing="0" border="0" |- | ''Main >> [[TETRIX_M...")
 
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
{| style="font-family:Verdana, Genega, sans-sarif; font-size:80%;color:gray;" width="100%" cellpadding="0%" cellspacing="0" border="0"
+
<yambe:breadcrumb self="Servo Controller">TETRIX|TETRIX</yambe:breadcrumb>
|-
+
|
+
''[[Main_Page|Main]] >> [[TETRIX_Main|TETRIX]] >> [[TETRIX:_Servo_Controller|Servo Controller]] ''
+
|-
+
|}
+
 
<br />
 
<br />
  
{|
+
{{tl|1|}}
|-
+
|style="vertical-align:top"| __TOC__
+
|-
+
|}
+
 
<br />
 
<br />
  
Line 17: Line 8:
 
{| class="wikiText"
 
{| class="wikiText"
 
|-
 
|-
|The HiTechnic Motor Controller allows you to drive two 12V motors and read values from two shaft encoders.
+
|The HiTechnic Servo Controller allows you to drive six different servo motors and read their positions via a single NXT sensor port.
 
|-
 
|-
 
|}
 
|}
Line 25: Line 16:
 
{| class="wikiText"
 
{| class="wikiText"
 
|-
 
|-
|Once your HiTechnic DC Motor Controller is configured in the "TETRIX Controllers" tab of the Motors and Sensor Setup screen, you can use the Motors tab of the Motors and Sensors Setup to configure your motors.
+
|Once your HiTechnic Servo Controller is configured in the "FTC Servo/Motor Ctrl" tab of the Motors and Sensors Setup screen, you can use the Servos tab of the Motors and Sensors Setup to rename your servos.
  
[[File:tetrix_motors_1.png]]
+
[[File:tetrix_servos_1.png]]
 
|-
 
|-
 
|}
 
|}
Line 35: Line 26:
 
{| class="wikiText"
 
{| class="wikiText"
 
|-
 
|-
|The name of the motor. NXT motors are given names "motorA" through "motorC". The TETRIX DC motors are named based on how they're connected to the NXT. The port name can be used to reference a motor in your program (i.e. <span class="keywordB">motor</span><span class="codePunc">[</span><span class="codeStringsNums">motorC</span><span class="codePunc">] = </span><span class="codeBasic">speed</span><span class="codePunc">;</span>)
+
|Name of the servos - servos are given names "servo1" through "servo6". This is the name you would use to refer to a specific servo port  (i.e. <span class="keywordB">servoTarget</span><span class="codePunc">[</span><span class="codeStringsNums">servo1</span><span class="codePunc">] = </span><span class="codeBasic">position</span><span class="codePunc">;</span>)
 
+
The TETRIX motor names can be translated as follows:<br />
+
<span class="codeStringsNums">mtr_S1_C1_1</span> - Motor (mtr) on Sensor Port 1 (S1) connected on the first controller (C1) in the daisy chain attached to Motor Port 1 (1)<br />
+
<span class="codeStringsNums">mtr_S1_C1_2</span> - Motor (mtr) on Sensor Port 1 (S1) connected on the first controller (C1) in the daisy chain attached to Motor Port 2 (2)
+
 
|-
 
|-
 
|}
 
|}
Line 47: Line 34:
 
{| class="wikiText"
 
{| class="wikiText"
 
|-
 
|-
|Motors can be given more descriptive names, such as "LeftMotor" or "FrontMotor". This name is an alias for the motor port name, so you can use it anywhere you want to specify that motor. The first two configured TETRIX motors are given the names "motorD" and "motorE" by default,  but these names can be changed based on your preference.
+
|You can rename the servo motor to something more descriptive, such as "FrontServo" or "RearServo". This name assigns an alias to your servo, so you can use your own user-defined name, or the default name of "servo#".
 
|-
 
|-
 
|}
 
|}
Line 55: Line 42:
 
{| class="wikiText"
 
{| class="wikiText"
 
|-
 
|-
|This allows you to set the type of motors, wether they are 12V DC motors or NXT motors.
+
|This allows you to set the types of servos. You can choose between a Standard Servo that has a limited movement range, or a Rotational Servo which can rotate freely.
|-
+
|}
+
<br />
+
 
+
=== PID Control ===
+
{| class="wikiText"
+
|-
+
|This checkbox enables the PID Speed Control functionality for a motor. The TETRIX DC motors don't have built-in encoders, so they must first be installed to use this feature.
+
|-
+
|}
+
<br />
+
 
+
=== Reverse ===
+
{| class="wikiText"
+
|-
+
|This checkbox will reverse the direction of a motor in an entire program. This is useful when motors are installed opposite one another. Instead of giving one motor a positive power level and the other motor a negative power level to make the robot move forward, both can be given a positive power level, simplifying your code.
+
 
|-
 
|-
 
|}
 
|}
Line 82: Line 53:
 
|-
 
|-
 
|}
 
|}
=== bMotorReflected ===
+
=== ServoValue ===
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="variableType"| <span class="bigKeywordBI">bool </span><span class="bigKeywordB">bMotorReflected</span>'''
+
| class="variableType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">ServoValue</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">TServoIndex servo</span><span class="bigCodePunc">]</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_bool|bool]]) Boolean array. Used to indicate that the direction of a motor should be reflected 180 degrees. Useful when mechanical design results in a logical "reversed" condition of a motor. This can also be configured in the Motors and Sensor Setup menu in ROBOTC.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) This read-only function is used to read the current position of the servos on a sensor port Servo controller. Values can range from 0 to 255. The value returned in this variable is the last position that the firmware has told the servo to move to. This may not be the actual position because the servo may not have finished the movement or the mechanical design may block the servo from fully reaching this position. To set the position of a servo, use the "servoTarget" or "servo" functions.
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''servo''
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|A servo port or name
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TServoIndex|TServoIndex]]
 +
  |-
 +
  |}
 
|-
 
|-
 
|
 
|
Line 93: Line 76:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
bMotorReflected[motorD] = true;  // motor D WILL be reflected 180 degrees
+
int a = ServoValue[servo1];  // assigns the value of servo1 to integer variable 'a'
bMotorReflected[motorD] = false;  // motor D will NOT be reflected 180 degrees
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 102: Line 84:
 
<br />
 
<br />
  
=== motor ===
+
=== servo ===
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="variableType"| <span class="bigKeywordBI">int </span><span class="bigKeywordB">motor</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">tMotor motor</span><span class="bigCodePunc">]</span>
+
| class="variableType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">servo</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">TServoIndex servo</span><span class="bigCodePunc">]</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) Contains the motor power or speed level (-100 to +100). Negative values are reverse; positive formward. A power level of 0 (zero) stops the motors.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) This function is used to set the position of the servos on a sensor port Servo controller. Values can range from 0 to 255. The firmware will automatically move the servo to this poisition over the next few update intervals. (Be sure to give the servo some amount of time to reach the new position before going on in your code.)
 +
<br />'''''NOTE:''''' ''<span class="keywordB">servo</span> can be interchanged with <span class="keywordB">servoTarget</span>.''
 
|-
 
|-
 
|
 
|
Line 115: Line 98:
 
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''motor''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''servo''  
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A motor port or name
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|A servo port or name
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_tMotor|tMotor]]
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TServoIndex|TServoIndex]]
 
   |-
 
   |-
 
   |}
 
   |}
Line 125: Line 108:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
motor[motorD] = 100;   // motor D is given a power level of 100 (forward)
+
servo[servo1] = 160;       // changes the position of servo1 to 160
motor[motorD] = -100;  // motor D is given a power level of -100 (reverse)
+
servoTarget[servo1] = 160;  // changes the position of servo1 to 160
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 134: Line 117:
 
<br />
 
<br />
  
=== nMotorEncoder ===
+
=== servoChangeRate ===
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="variableType"| <span class="bigKeywordBI">long </span><span class="bigKeywordB">nMotorEncoder</span>
+
| class="variableType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">servoChangeRate</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">TServoIndex servo</span><span class="bigCodePunc">]</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_long|long]]) Current value of the motor encoder. Range is -32768 to 32767 so it will "wrap" after about ~90 revolutions. The user's program should reset the value of the encoder often to avoid the value "resetting" itself when the maximum distance is met.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Specifies the rate at which an individual servo value is changed. A value of zero inidcates servo will move at maximum speed. The change rate is a useful variable for "smoothing" the movement of the servos and preventing jerky motion from software calculated rapid and wide changes in the servo value. The default value is a change rate of 10 positions on every servo update which occurs. (updates occur every 20 milliseconds)
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''servo''
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|A servo port or name
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_TServoIndex|TServoIndex]]
 +
  |-
 +
  |}
 
|-
 
|-
 
|
 
|
Line 145: Line 140:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
nMotorEncoder[motorD] = 0;         // reset the Motor Encoder of Motor D
+
servoChangeRate[servo1] = 2;  // slows the Change Rate of servo1 to 2 positions per update
while(nMotorEncoder[motorD] < 360) // while the Motor Encoder of Motor D has not yet reached 360 counts:
+
{
+
  motor[motorD] = 75;                // motor D is given a power level of 75
+
  motor[motorE] = 75;                // motor E is given a power level of 75
+
}
+
motor[motorD] = 0;                  // motor D is given a power level of 0 (stop)
+
motor[motorE] = 0;                  // motor E is given a power level of 0 (stop)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-

Latest revision as of 19:59, 30 April 2012

TETRIX → Servo Controller



Information

The HiTechnic Servo Controller allows you to drive six different servo motors and read their positions via a single NXT sensor port.


Configuration

Once your HiTechnic Servo Controller is configured in the "FTC Servo/Motor Ctrl" tab of the Motors and Sensors Setup screen, you can use the Servos tab of the Motors and Sensors Setup to rename your servos.

Tetrix servos 1.png


Port

Name of the servos - servos are given names "servo1" through "servo6". This is the name you would use to refer to a specific servo port (i.e. servoTarget[servo1] = position;)


Name

You can rename the servo motor to something more descriptive, such as "FrontServo" or "RearServo". This name assigns an alias to your servo, so you can use your own user-defined name, or the default name of "servo#".


Type

This allows you to set the types of servos. You can choose between a Standard Servo that has a limited movement range, or a Rotational Servo which can rotate freely.


ROBOTC Functions

ServoValue

short ServoValue[TServoIndex servo]
(short) This read-only function is used to read the current position of the servos on a sensor port Servo controller. Values can range from 0 to 255. The value returned in this variable is the last position that the firmware has told the servo to move to. This may not be the actual position because the servo may not have finished the movement or the mechanical design may block the servo from fully reaching this position. To set the position of a servo, use the "servoTarget" or "servo" functions.
Parameter Explanation Data Type
servo A servo port or name TServoIndex
int a = ServoValue[servo1];  // assigns the value of servo1 to integer variable 'a'


servo

short servo[TServoIndex servo]
(short) This function is used to set the position of the servos on a sensor port Servo controller. Values can range from 0 to 255. The firmware will automatically move the servo to this poisition over the next few update intervals. (Be sure to give the servo some amount of time to reach the new position before going on in your code.)


NOTE: servo can be interchanged with servoTarget.

Parameter Explanation Data Type
servo A servo port or name TServoIndex
servo[servo1] = 160;        // changes the position of servo1 to 160
servoTarget[servo1] = 160;  // changes the position of servo1 to 160


servoChangeRate

short servoChangeRate[TServoIndex servo]
(short) Specifies the rate at which an individual servo value is changed. A value of zero inidcates servo will move at maximum speed. The change rate is a useful variable for "smoothing" the movement of the servos and preventing jerky motion from software calculated rapid and wide changes in the servo value. The default value is a change rate of 10 positions on every servo update which occurs. (updates occur every 20 milliseconds)
Parameter Explanation Data Type
servo A servo port or name TServoIndex
servoChangeRate[servo1] = 2;  // slows the Change Rate of servo1 to 2 positions per update