Page 22
KIPR Link Library Functions for DC Motors
motor(
<
motor#
>
,
<
power
>
)
Turns on a motor at a scaled PWM percentage, which will continue until another motor
command is issued. Power levels range from 100 (full forward) to -100 (full backward). PWM
stands for "pulse-width-modulation" and is a more effective way to control DC motor power
than using something like a variable resistor.
mav(
<
motor#
>
,
<
velocity
>
)
Move At Velocity moves a motor at a specified velocity until another motor command is issued.
The value of the velocity is scaled to range from -1000 to 1000 ticks per second.
mav
(and a
number of other KIPR Link Library motor commands) uses a more complex motor control
scheme than the static PWM percentage employed by the
motor
command. To obtain the
specified velocity,
mav
employs PID (proportional-integral-derivative) gain values and a dynamic
measure of the BEMF ("back electro-motive force") produced by the motor to dynamically
adjust the PWM percentage being applied so that the motor continues moving at the specified
velocity. The BEMF value is periodically refreshed by briefly suspending PWM so that the
motor's back EMF can be read by the KIPR Link.
mrp(
<
motor#
>
,
<
velocity
>
,
<
ticks
>
)
Move Relative Position moves a motor at a specified velocity from its current position to the
current position plus the number of ticks specified. Velocities range from 0 to 1000 ticks per
second. Like
mav
,
mrp
uses PID motor control.
mrp
stops executing when the new position is
reached or when another motor command is issued. The final motor position may be slightly off
due to motor coasting once power is no longer being applied.
bmd(
<
motor#
>
)
If the motor is currently executing a positioning command (such as
mrp
),
bmd
(Block Motor
Done) does not return until the positioning command finishes. Note that if the motor is stalled
by some external cause, the effect of this command will be to hang program execution until the
motor is freed.
ao()
All Off turns off power for all motor ports.
off(
<
motor#
>
)
Turns off power for the specified motor port.
There are a number of additional motor functions in the KIPR Link library, described in the appendices.