Servo

Control the position and movement of up to 8 individual servo motors (servos).

Servo motors are designed to “hold position” after they move (same as stepper motors but unlike normal DC brushed motors).  So this means that once “attached” or “on” servos will consume significant current (energy) and get hot and drain your battery faster.  To avoid this, it is best to turn servos “off” or “detach” them unless you specifically need it to “hold position” for gripping etc.

Servo motors, unlike normal brushed DC motors, are position controlled and are primarily used to move to a particular fixed position rather than continually rotate.  Servo motors normally rotate clockwise and anticlockwise through an arc of 180 degrees, however, this may be less or more depending on the manufacturing of that servo motor and its pulse input range specifications.  Some servos only rotate through 120 degrees but 180 degrees is normal.

Servo motors have an on board motor controller that responds to square wave pulses that indicate the desired servo position.  Normally, a pulse gap of 0.75 milliseconds (ms) being 750 microseconds (us) causes servo to rotate to minimum position.  Mid position is 1.5ms or 1500us and 180 degree position is 2.25ms or 2250us.  These pulse widths are the basis of the PWM command, however, ScratchLink simplifies servo control by allowing degrees or percent to be used for servo position.

servo config

Up to 8 servos can be controlled by ScratchLink and are addressed as “servo0′ to “servo7”

The config command allows the names of servos from servo0 – servo7 to be set to physical Input/Output pins on the ScratchLink Controller.

Reporting Config Info:

Command Syntax:

servo config info;

Purpose:  Reports currently stored servo configuration for all servos.

Example Report:

{Servo:0,Enabled:1,Pin:2,Low:200,High:8000,Reverse:0,Width:16,Freq:50}
{Servo:1,Enabled:1,Pin:4,Low:100,High:8000,Reverse:0,Width:16,Freq:50}

Enable & Disable Servos:

Command Syntax:  “[ ]” means optional argument and “|” means OR 

servo[device] config enable [on|off];

Purpose:  Enables individual or all servos- default is enable all servos.

Example 1:  Enable all servos.

servo config enable;

Example 2:  Disable all servos.

servo config enable off;

Example 3:  Enable servo1 only.

servo1 config enable;

Example 4:  Disable servo1 only.

servo1 config enable off;

Set Servo Config Parameters:

Command Syntax:  “[ ]” means optional argument and “|” means OR 

servoDevice config set pinValue lowPWM highPWM;

Defaults: [low] = 750us and [high] = 2250us

Example:  Attach servo0 to pin 2 , with a low PWM duty cycle of 200 and high PWM duty cycle of 8000

servo0 config set 2 200 8000;

Reverse Servo Direction:

Command Syntax:  “[ ]” means optional argument and “|” means OR 

servoDevice config reverse yes|no;

Example: Reverse the direction of servo2

servo2 config reverse yes;

Remove servo from Configuration:

Command Syntax:

servoDevice config remove;

Example:  Remove servo2 from the Configuration.

servo2 config remove;

servo on|off

Servo on or off (attach or detach):

Note on how servos work:  Servo motors are designed to “hold position” after they move (same as stepper motors but unlike normal DC brushed motors).  So this means that once “attached” or “on” servos will consume significant current (energy) and get hot and drain your battery faster.  To avoid this, it is best to turn servos “off” or “detach” them unless you specifically need it to “hold position” for gripping etc.

Command Syntax:  “[ ]” means optional argument and “|” means OR 

servo[device] [on|off];

Default:  Disable servo.

Example 1: Enable servo 3.

servo3 on;

Example 2: Disable servo 3.

servo3 off;

Example 3: Disable all servos using default.

servo;

servo pwm

Servo duty cycle or PWM (Pulse Width Modulation)

Command Syntax:  “[ ]” means optional argument and “|” means OR

servo[device] pwm value hold yes|no;

Defaults: pwm 1500us and hold noNote: Not subject to “servo reverse” command.

Example 1: Move servo 4 to position pwm (pulse width modulation) 1500us and hold position.

servo4 pwm 1500 hold yes;

Example 2: Move servo 2 to position pwm (pulse width modulation) 750us and release i.e. disable.

servo2 pwm 750 hold no;

servo percent

Set the Servo Position Using 0-100%:

Command Syntax:  “[ ]” means optional argument and “|” means OR

Default: percent 50 hold no

servoDevice percent value hold yes|no;

Example 1: Set servo 5 to its 1/4 position and release

servo5 percent 25 hold no;

Example 2:  Set servo 3 to midway and hold.

servo3 percent 50 hold yes;

servo degree

Set the Servo Position Using 0-180 degrees:

Command Syntax:  “[ ]” means optional argument and “|” means OR

servoDevice degree value hold yes|no;

Default:  degree 90 hold no

Example 1: Set servo 5 to its 1/4 position and release

servo5 degree 45 hold no;

Example 2:  Set servo 3 to midway and hold.

servo3 degree 90 hold yes;