Why Use a Servo?
A servo is needed in robotics to apply a force at a distance:
- To pick something up;
- to grab something;
- to push something aside.
A servo uses a motor to produce a rotational force, called ‘Torque’ – It equals a force (F) at a rotating radius (r): T = Fxr
The max torque is fixed by the servo motor, thus the force at a large radius is smaller than at a small radius.
The motor has limited rotation ability (0-180 degrees) to find and hold the rotational position.
Programming Servo Motors
To help save power, servo ports by default are not active until enabled
A command is provided in the CBC library for enabling (or disabling) all servo ports
enable_servos(); activates all servo ports
disable_servos(); de-activates all servo ports
[For the LINK each servo can be enabled/disabled individually: e.g. enable_servo(n);
These functions are NOT required with the CBC v2 because servo power is activated for each
port individually in response to the set_servo_position(port, position) function.
Setting the ‘position’ to ‘-1‘deactivates the port.]
set_servo_position(2,925); rotates the servo on port 2 to position 925
Position range is 0-2047 (~0-180 degrees), so each 100 counts is about 9 degrees.
When you set a servo’s position it will immediately be enabled and move to the position you want. Otherwise, the default position when servos are all enabled, using ‘enable_servos()’, is 1024 (~90 degrees).
The servo position resolution is only ~ 1% or 2 degrees, and each servo has an offset error which can be slightly greater, so if the motion required must be accurate, the servo should be calibrated using the Servo Test display. This is especially important if it is driven near 0 or 180 to assure that the servo is not commanded past its mechanical limits. This would cause a large power draw, and possibly damage to the servo and/or the controller.
get_servo_position(2); provides the current numeric position of the servo on port 2. It works only when servos are activated (actually only reads the value that is output to an activated servo).
Here are details on attaching a servo, testing it to find the angle positions for a particular application, and a couple example programs for making demonstrations: