Difference between revisions of "TETRIX Motor Controller"

From ROBOTC API Guide
Jump to: navigation, search
 
(6 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="Motor Controller">TETRIX|TETRIX</yambe:breadcrumb>
|-
+
|
+
''[[Main_Page|Main]] >> [[TETRIX_Main|NXT]] >> [[TETRIX:_Motor_Controller|Motor Controller]] ''
+
|-
+
|}
+
 
<br />
 
<br />
  
{|
+
{{tl|1|}}
|-
+
|style="vertical-align:top"| __TOC__
+
|-
+
|}
+
 
<br />
 
<br />
  
Line 80: Line 71:
 
|-
 
|-
 
|
 
|
 +
|-
 +
|}
 +
=== bMotorReflected ===
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="variableType"| <span class="bigKeywordBI">bool </span><span class="bigKeywordB">bMotorReflected</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.
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="robotc">
 +
bMotorReflected[motorD] = true;  // motor D WILL be reflected 180 degrees
 +
bMotorReflected[motorD] = false;  // motor D will NOT be reflected 180 degrees
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
 +
 
=== motor ===
 
=== motor ===
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
Line 103: Line 116:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
motor[motorA] = 100;  // motor A is given a power level of 100 (forward)
+
motor[motorD] = 100;  // motor D is given a power level of 100 (forward)
motor[motorA] = -100;  // motor A is given a power level of -100 (reverse)
+
motor[motorD] = -100;  // motor D is given a power level of -100 (reverse)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 111: Line 124:
 
|}
 
|}
 
<br />
 
<br />
 +
 +
=== nMotorEncoder ===
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="variableType"| <span class="bigKeywordBI">long </span><span class="bigKeywordB">nMotorEncoder</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.
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="robotc">
 +
nMotorEncoder[motorD] = 0;          // reset the Motor Encoder of Motor D
 +
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>
 +
  |-
 +
  |}
 
|-
 
|-
 
|}
 
|}
 
<br />
 
<br />

Latest revision as of 19:58, 30 April 2012

TETRIX → Motor Controller



Information

The HiTechnic Motor Controller allows you to drive two 12V motors and read values from two shaft encoders.


Configuration

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.

Tetrix motors 1.png


Port

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. motor[motorC] = speed;)

The TETRIX motor names can be translated as follows:
mtr_S1_C1_1 - Motor (mtr) on Sensor Port 1 (S1) connected on the first controller (C1) in the daisy chain attached to Motor Port 1 (1)
mtr_S1_C1_2 - Motor (mtr) on Sensor Port 1 (S1) connected on the first controller (C1) in the daisy chain attached to Motor Port 2 (2)


Name

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.


Type

This allows you to set the type of motors, wether they are 12V DC motors or NXT motors.


PID Control

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.


Reverse

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.


ROBOTC Functions

bMotorReflected

bool bMotorReflected
(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.
bMotorReflected[motorD] = true;   // motor D WILL be reflected 180 degrees
bMotorReflected[motorD] = false;  // motor D will NOT be reflected 180 degrees


motor

int motor[tMotor motor]
(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.
Parameter Explanation Data Type
motor A motor port or name tMotor
motor[motorD] = 100;   // motor D is given a power level of 100 (forward)
motor[motorD] = -100;  // motor D is given a power level of -100 (reverse)


nMotorEncoder

long nMotorEncoder
(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.
nMotorEncoder[motorD] = 0;          // reset the Motor Encoder of Motor D
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)