Page 20
available power may fall below the threshold where the servo will function properly. Servos that
mysteriously begin misbehaving are usually symptomatic of a battery in need of recharge.
KIPR Link Library Functions for Servo Motors
Servo motor ports should be disabled when not in use to limit their impact on system power resources.
On boot, servo ports are disabled by default. There are 4 servo ports, labeled 0, 1, 2, 3. The KIPR Link
Library includes functions for managing servo ports as well as functions for operating servo motors. The
basic functions are:
enable_servo(<servo_port#>)
Enables power for the specified servo port. When the port is enabled, the servo motor plugged
into it will move to the last position set for the port, by default 1024, the center point of servo
travel range.
disable_servo(<servo_port#>)
Disables power for the specified servo port. This is useful when you want to conserve battery
life. Your servo motor will be at the mercy of any external forces and will not hold its position
when the port is disabled.
set_servo_position(<port#>, <position>)
Moves the servo motor plugged into the specified port to the specified position. Only position
values between 0 and 2047 are meaningful, and a value within 200 of an end point of the
position range may be unattainable, depending on the servo motor being used. The servo will
immediately move to position, unless impeded by external force or the position is unattainable,
in which case it will continue to draw its maximum power level in trying to reach the position. If
this function is called before the port is enabled, when the port is enabled the servo motor will
move to this position.
Example use of these functions for a servo motor plugged into servo port 2:
set_servo_position(
2
,
670
);
// set a position for the servo port
enable_servo(
2
);
// power the port and move the servo
... do something else ...
disable_servo(
2
);
// servo no longer needed
The C language prototypes for these three functions are:
void
enable_servo(
int
servo);
void
disable_servo(
int
servo);
int
digital(
int
servo,
int
position);
There are a few additional, less commonly used functions for servo motors in the KIPR Link library,
described in the appendices.