Difference between revisions of "ARDUINO MEGA Functions Motors and Servos"

From ROBOTC API Guide
Jump to: navigation, search
(Created page with "<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> <br /> {| |- |''For more examples and explanations, head over to [[VEX2_Moto...")
 
Line 1: Line 1:
 
<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
 
<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
<br />
 
 
{|
 
|-
 
|''For more examples and explanations, head over to [[VEX2_Motors_and_Servos_Overview|Motors and Servos Overview]]!''
 
|-
 
|Up to 8 motors and/or servos can be connected to the VEX controller. Motor speeds range from -127 (full reverse) through zero (stopped) up to +127 (full forward). There is a small deadband in the motors from about +15 to -15
 
|-
 
|}
 
 
<br />
 
<br />
  
Line 25: Line 16:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
bMotorReflected[port1] = true;  // motor 1 WILL be reflected 180 degrees
+
bMotorReflected[motor_2] = true;  // motor 1 WILL be reflected 180 degrees
bMotorReflected[port1] = false;  // motor 1 will NOT be reflected 180 degrees
+
bMotorReflected[motor_2] = false;  // motor 1 will NOT be reflected 180 degrees
</syntaxhighlight>
+
  |-
+
  |}
+
|-
+
|}
+
<br />
+
 
+
== getEncoderForMotor ==
+
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
|-
+
| class="functionType"| <span class="bigKeywordBI">tSensors </span><span class="bigKeywordB">getEncoderForMotor</span><span class="bigCodePunc">(</span><span class="bigCodeBasic">tMotor motorIndex</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_tSensors|tSensors]])  Returns the sensor port of the encoder paired to motor port, <span class="codeBasic">motorIndex</span>.
+
<br />
+
 
+
{| 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"|''motorIndex''
+
  | 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"|[[Data_Types#dataType_tMotor|tMotor]]
+
  |-
+
  |}
+
<br />
+
 
+
  {|
+
  |-
+
  |<syntaxhighlight lang="robotc">
+
int valueOfEncoder;                                      // set 'valueOfEncoder' to the value...
+
valueOfEncoder = SensorValue(getEncoderForMotor(port1));  // ...returned by the encoder paired to port1
+
</syntaxhighlight>
+
  |-
+
  |}
+
|-
+
|}
+
<br />
+
 
+
== mapEncoderToMotor ==
+
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
|-
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">mapEncoderToMotor</span><span class="bigCodePunc">(</span><span class="bigCodeBasic">tMotor motorPort</span><span class="bigCodePunc">, </span><span class="bigCodeBasic">tSensors I2CPort</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_void|void]])  Map an I2C sensor port to the motor it belongs to (when using VEX Integrated Encoder Modules).<br />
+
''This is taken care of in the Motors and Sensors Setup window.''
+
<br />
+
 
+
{| 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 1px 0px"|''motorPort''
+
  | style="border-style: solid; border-width: 1px 0px 1px 0px"|A motor port or name
+
  | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_tMotor|tMotor]]
+
  |-
+
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|''I2CPort''
+
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|An I2C sensor port or name
+
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_tSensors|tSensors]]
+
  |-
+
  |}
+
<br />
+
 
+
  {|
+
  |-
+
  |<syntaxhighlight lang="robotc">
+
mapEncoderToMotor(port1, I2C_1);  // map the encoder in I2C port 'I2C_1' to motor in port 'port1'
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 125: Line 48:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
motor[port1] = 127;  // motor 1 is given a power level of 127 (forward)
+
motor[motor_2] = 127;  // motor pin 2 is given a power level of 127 (forward)
motor[port1] = -127;  // motor 1 is given a power level of -127 (reverse)
+
motor[motor_2] = -127;  // motor pin 2 is given a power level of -127 (reverse)
</syntaxhighlight>
+
  |-
+
  |}
+
|-
+
|}
+
<br />
+
 
+
== motorType ==
+
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
|-
+
| class="variableType"| <span class="bigKeywordBI">word </span><span class="bigKeywordB">motorType</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">tMotor motor</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_word|word]]) An array variable with one element for each of the possible motors. This command is used to read/write the type of the motor in question.
+
|-
+
|
+
  {| 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"|''motor''
+
  | 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"|[[Data_Types#dataType_tMotor|tMotor]]
+
  |-
+
  |}
+
|-
+
|
+
  {|
+
  |-
+
  |<syntaxhighlight lang="robotc">
+
motorType[port1] = tmotorVex393HighSpeed;  // set motor in 'port1' to type 'tmotorVex393HighSpeed'
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-

Revision as of 01:53, 10 May 2012

ARDUINOFunctions and Variables → ARDUINO MEGA Functions Motors and Servos


Color Key
Function:
Variable:


bMotorReflected

bool bMotorReflected
(bool) Boolean array with one entry for each motor. Indicates that the direction of a motor should be reflected 180 degrees. Useful when mechanical design results in a logical "reversed" condition of a motor.
bMotorReflected[motor_2] = true;   // motor 1 WILL be reflected 180 degrees
bMotorReflected[motor_2] = false;  // motor 1 will NOT be reflected 180 degrees


motor

int motor[tMotor motor]
(int) An array variable with one element for each of the possible motors. This command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped. To drive the motor on port1 at 50% of full power you use the statement motor[port1] = 63;
Parameter Explanation Data Type
motor A motor port or name tMotor
motor[motor_2] = 127;   // motor pin 2 is given a power level of 127 (forward)
motor[motor_2] = -127;  // motor pin 2 is given a power level of -127 (reverse)