Functions | |
int | Servo_SetActive (int index, int state) |
Lock or unlock the I/O lines used by the servos. | |
int | Servo_GetActive (int index) |
Check whether the I/O lines used by the servos are locked. | |
int | Servo_SetPosition (int index, int position) |
Set the position of the specified servo motor. | |
int | Servo_SetSpeed (int index, int speed) |
Set the speed at which a servo will move in response to a call to Servo_SetPosition(). | |
int | Servo_GetPosition (int index) |
Read the current position of a servo motor. | |
int | Servo_GetSpeed (int index) |
Get the speed at which a servo will move in response to a call to Servo_SetPosition(). |
Standard servos have a range of motion of approximately 180 degrees, although this varies from motor to motor. Be sure to plug in the connector with the correct orientation with regard to the GND/5V signals on the board.
Because not all servo motors are created equal, and not all of them can be safely driven across all 180 degrees, the default (safe) range of motion is from values 0 to 1023. The full range of motion is from -512 to 1536, but use this extra range cautiously if you don't know how your motor can handle it. A little gentle experimentation should do the trick.
You can also specify the speed with which the motors will respond to new position commands - a high value will result in an immediate response, while a lower value can offer some smoothing when appropriate.
See the servo section in the Application Board overview for more detailed info.
int Servo_GetActive | ( | int | index | ) |
Check whether the I/O lines used by the servos are locked.
index | An integer specifying which servo (0-3). |
if( Servo_GetActive(2) ) { // Servo 2 is active } else { // Servo 2 is inactive }
int Servo_GetPosition | ( | int | index | ) |
Read the current position of a servo motor.
index | An integer specifying which servo (0 - 3). |
int srv0_pos = Servo_GetPosition(0); // now srv0_pos is the current position
int Servo_GetSpeed | ( | int | index | ) |
Get the speed at which a servo will move in response to a call to Servo_SetPosition().
Read the value previously set for the speed parameter.
index | An integer specifying which servo (0 - 3). |
int srv0_speed = Servo_GetSpeed(0); // now srv0_speed is the current speed
int Servo_SetActive | ( | int | index, | |
int | state | |||
) |
Lock or unlock the I/O lines used by the servos.
Sets whether the specified Servo I/O is active.
index | An integer specifying which servo (0 - 3). | |
state | An integer specifying the active state - 1 (active) or 0 (inactive). |
// enable servo 2 Servo_SetActive(2, 1);
int Servo_SetPosition | ( | int | index, | |
int | position | |||
) |
Set the position of the specified servo motor.
Most servos like to be driven within a "safe range" which usually ends up being somewhere around 110-120 degrees range of motion, or thereabouts. Some servos don't mind being driven all the way to their 180 degree range of motion limit. With this in mind, the range of values you can send to servos connected to the Make Controller Kit is as follows:
Note that it is sometimes possible to damage your servo by driving it too far, so proceed with a bit of caution when using the extended range until you know your servos can handle it.
index | An integer specifying which servo (0 - 3). | |
position | An integer specifying the servo position (0 - 1023). |
// set servo 1 to midway through the "safe" range Servo_SetPosition(1, 512);
int Servo_SetSpeed | ( | int | index, | |
int | speed | |||
) |
Set the speed at which a servo will move in response to a call to Servo_SetPosition().
Higher values will result in a more immediate response, while lower values will more slowly step through all the intermediate values, achieving a smoother motion.
index | An integer specifying which servo (0 - 3). | |
speed | An integer specifying the servo speed (0 - 1023). |
// set servo 1 half speed Servo_SetSpeed(1, 512);