TETRIX Functions Servos

From ROBOTC API Guide
Revision as of 20:21, 30 April 2012 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


For more examples and explanations, head over to Motors and Servos Overview, Using Motor and Servo Controllers, and Servo Controller

There are three motors on the NXT labeled A, B and C. Each motor is equipped with an integrated encoder that can be used to determine the current position of the motor. The encoders have 360 counts per single revolution of the motor. A count of 180 indicates that the motor has traveled half a rotation.


Color Key
Function:
Variable:


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: This function is equivalent to the deprecated function, servoTarget[TServoIndex servo].

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


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'