This functionality is similar to that found on the LEGO Mindstorms RCX with a few notable exceptions:
6. TETRIX / FTC
6.1 HiTechnic Controllers
6.1.1 Using Motor/Servo Controllers
Because the HiTechnic controllers are able to be daisy chained in a number of configurations, the NXT must be told which sensor port and what order each controller is connected to before you can use the DC Motor or Servo Controllers.
ROBOTC supports every possible configuration, but some shortcuts have been added to make configuring your controllers easier.
There are three settings:
No Controllers Configured - This is the default configuration. No Motor Controllers or Servo Controllers will be configured.
Standard Configuration - This configuration is the default FTC configuration, where teams only have one motor and one servo controller . This configuration automatically configures the devices connected to Sensor Port 1, with the Motor Controller connected directly to the NXT and the Servo Controller attached to the daisy-chain port of the Motor Controller. (NXT -> Motor Controller -> Servo Controller). This is the configuration shown below.
Custom Configuration - This allows you to connect as many Motor and Servo controllers in any order. Simply match your hardware configuration to the configuration on the screen and ROBOTC will take care of all of the configuration code for your program.
6.1.2 Motor Controller
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.
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:
motor[]
Contains the motor power or speed level (-100 to +100). Negative values are reverse; positive formward.
Zero is stopped.
Example: (program example can be found at: " \Sample Programs\NXT\Motor\Moving Forward TETRIX.c ")
motor[motorD] = 75; // Set motorD (FTC motor #1) to power level of 75%.
nMotorEncoder[]
Current value of the motor encoder. This value will be returne rotation counts as an integer. Set the value of this function to zero to reset the encoders. (i.e. nMotorEncoder[motor] = 0;)
Example: (program example can be found at: " \Sample Programs\NXT\Motor\Motors with While Loops TETRIX.c ")
while(nMotorEncoder[motorD] < 10000) // While motorD encoder is less than 10000 rotation counts:
bMotorReflected[]
This function when set to true checked will reflect all motor commands to this motor. This is useful if the motors are installed opposite to each other and allows the same "Motor" command to be given to each motor to have the robot drive in a forward direction. (i.e. 100 becomes -100.) This command only needs to be issued once per program and this function is not required if you have enabled "Reverse" control via the Motors and Sensor Setup.
Example:
bMotorReflected[motorD] = true; // Enable "Reflected" motorD commands (100 becomes -100).
6.1.3 Servo Controller
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.
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[servo#]
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.
Example: (program example can be found at: "\Sample Programs\NXT\Servos\Servo Sweep TETRIX.c")
int a = ServoValue [servo1]; // Assigns the value of servo1 to integer variable 'a'.
servo[servo#] = position or servoTarget[servo#] = position;
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.)
Example: (program example can be found at: " \Sample Programs\NXT\Servos\Servo Sweep TETRIX.c
")
servo[servo1] = 160; // Changes the position of servo1 to 160.
servoTarget[servo1] = 160; // Changes the position of servo1 to 160.
servoChangeRate[servo#] = changeRate;
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)
Example: (program example can be found at: " \Sample Programs\NXT\Servos\Servo Sweep TETRIX.c
")
servoChangeRate[servo1] = 2; // Slows the Change Rate of servo1 to 2 positions per update.