Auxiliary Servo Library  v0.91
Servo motor control library for educational and hobby applications
Functions
servoAux.h File Reference

If the servo library is already busy with 14 servos, you can use this library to control up to 14 more servos. Control the first 14 with servo_set, servo_speed, servo_angle, and other servo_ function calls. Control servos 15 and up with the same function calls, but starting with servoAux_ instead of servo_. More...

#include "simpletools.h"

Go to the source code of this file.

Functions

int servoAux_angle (int pin, int degreeTenths)
 Set Parallax Standard Servo to angle from 0 to 180 in tenths of a degree.
int servoAux_speed (int pin, int speed)
 Set Parallax Continuous Rotation servo speed.
int servoAux_setRamp (int pin, int stepSize)
 Set the maximum change in control signal a servo will change in a given 20 ms time period.
int servoAux_set (int pin, int time)
 Sets servo control signal to servo connected to a given pin for microsecond pulse durations.
int servoAux_get (int pin)
 Reports the number of microseconds of the pulse most recently sent to a given servo.
int servoAux_disable (int pin)
 Temporarily or permanently disable a servo by stopping its control signals, setting its I/O pin to input, and removing its settings from the servo library code's control list. To re-enable a servo's position/speed control, simply call servoAux_angle, servoAux_speed, or servoAux_set. Make sure to use the I/O pin of the servo you want to "wake back up". If the servo had ramp settings, they will have to be restored too.
void servoAux_stop (void)
 Stops the servo process and frees a cog.

Detailed Description

If the servo library is already busy with 14 servos, you can use this library to control up to 14 more servos. Control the first 14 with servo_set, servo_speed, servo_angle, and other servo_ function calls. Control servos 15 and up with the same function calls, but starting with servoAux_ instead of servo_.

Author
Andy Lindsay

This library automatically delivers control pulses to up to 14 servos every 20 ms. All your code has to do is use servoAux_angle, servoAux_speed, or servoAux_set, to pick the pin the servo is connected to and set its angle (standard servo)or speed (continuous rotation servo).

Note
Parallax standard servos have a position range from approximately 0 to 180 degrees.
Core Usage
Launches 1 core that controls up to 14 servos on the first call to servoAux_set, servoAux_angle or servoAux_speed. Additional calls to any of these functions will not launch more cores. Additional servos are controlled by supplying different pin arguments to these functions. For example, servoAux_angle(12, 900) followed by servoAux_angle(13, 300) will cause the other core sending servo control signals to set a servo connected to P12 to 90 degrees, and a servo connected to P13 to 30 degrees. If servoAux_angle(12, 900) was the first call to this library, it would automatically launch a core before making that core send control signals to the servo connected to P12. The servoAux_angle(13, 300) call would cause the same core controlling the P12 servo to also send control signals to a servo connected to P13.
Memory Models
Use with CMM or LMM.
Version
v0.91 Add servo_disable, make servoAux, servoAux_start, and servoAux_Pulse private, and fix lock bug that can occur if the process is stopped and then restarted.
v0.90
Help Improve this Library
Please submit bug reports, suggestions, and improvements to this code to edito.nosp@m.r@pa.nosp@m.ralla.nosp@m.x.co.nosp@m.m.

Function Documentation

int servoAux_angle ( int  pin,
int  degreeTenths 
)

Set Parallax Standard Servo to angle from 0 to 180 in tenths of a degree.

Examples:

servoAux_angle(pin, 0); // for 0 degrees
servoAux_angle(pin, 900); // for 90 degrees
servoAux_angle(pin, 1800); // for 180 degrees

0 to 1800 corresponds to control pulses ranging from 500 to 2300 with 1400 at center (90 degrees), which is slightly different from the 1500 center convention, but it places the Parallax Standard Servo's range of motion neatly between its mechanical limits.

Parameters
pinNumber of the I/O pin connected to servo
degreeTenthsTenths of a degree from 0 to 1800
Returns
pin number = success, -1 = no cogs available, -2 = no locks available, -3 = all 14 servo slots already filled.
int servoAux_disable ( int  pin)

Temporarily or permanently disable a servo by stopping its control signals, setting its I/O pin to input, and removing its settings from the servo library code's control list. To re-enable a servo's position/speed control, simply call servoAux_angle, servoAux_speed, or servoAux_set. Make sure to use the I/O pin of the servo you want to "wake back up". If the servo had ramp settings, they will have to be restored too.

This function can be useful for an application that has to make the servo "relax", but either stopping its position or speed control. It also opens up another entry in the servo control list for applications that use more than 28 servos (assuming the application also uses the servo library for the first 14 servos and this for the second 14), but only use 28 or fewer at any given time.

Parameters
pinNumber of the I/O pin the servo is connected to.
Returns
pin number = success, -1 = no cogs available, -2 = no locks available, -3 = all 14 servo slots already filled.
int servoAux_get ( int  pin)

Reports the number of microseconds of the pulse most recently sent to a given servo.

Parameters
pinNumber of the I/O pin the servo is connected to
Returns
tp[i] The value stored by the array element that keeps duration of the most recent pulse sent to the servo. (Or -4 if an entry is not found for the pin argument.
int servoAux_set ( int  pin,
int  time 
)

Sets servo control signal to servo connected to a given pin for microsecond pulse durations.

This function directly controls the number of microseconds servo control pulses last.

Examples for Parallax Standard Servo:

servoAux_set(pin, 500); // 0 degrees
servoAux_set(pin, 1400); // 90 degrees
servoAux_set(pin, 2300); // 180 degrees

500, 1400, and 2300 are the number of microseconds (us) the control pulses stay high. More generally, a microsecond above 500 corresponds to 1/10 of a degree counterclockwise of 0 degrees. So, for a given degree position, use:

degree position = 500 + (number of 10ths of a degree)

For setting Parallax Continuous Rotation Servo speed, use:

  • Full speed clockwise -> servoAux_set(pin, 1400);
  • Stay still -> servoAux_set(pin, 1500);
  • Full speed counterclockwise -> servoAux_set(pin, 1600);

Values in the 1400 to 1600 range are (roughly) proportional to speed for a Parallax Continuous Rotation Servo, but it's not nearly as precise as position control. Setting full speeds at 1300 and 1700 is a common practice to make sure both servos are going as fast as they possibly can.

Parameters
pinNumber of the I/O pin that sends signals to the servo.
timeMicrosecond servo pulse time.
Returns
pin number = success, -1 = no cogs available, -2 = no locks available, -3 = all 14 servo slots already filled.
int servoAux_setRamp ( int  pin,
int  stepSize 
)

Set the maximum change in control signal a servo will change in a given 20 ms time period.

This function allows you to make a Parallax Continuous Rotation servo ramp up to and down from whatever speed or position it was previously set to. It also allows you to set the rate at which a Parallax Standard servo turns from its previous position to a new position.

Parameters
pinNumber of the I/O pin the servo is connected to
stepSizeThe number of microseconds per 20 ms of time that the servo's control signal is allowed to change. This equates to the number of tenths of a degree a Parallax Standard servo is allowed to change, or the number of 100ths of full speed the a Parallax Continuous Rotation servo is allowed to change per 20 ms.
Returns
pin if successful, -4 if pin not found.
int servoAux_speed ( int  pin,
int  speed 
)

Set Parallax Continuous Rotation servo speed.

Examples:

servoAux_speed(pin, 200); // Twice full speed counterclockwise
servoAux_speed(pin, 100); // Full speed counterclockwise
servoAux_speed(pin, 0); // Stay still
servoAux_speed(pin, -100); // Full speed clockwise
servoAux_speed(pin, -200); // Twice full speed clockwise

100 to -100 corresponds to the linear speed control range. For example, servoAux_speed(pin, 75) will set the speed to roughly 75% of full speed counterclockwise. This is a very rough approximation.

Parameters
pinNumber of the I/O pin connected to servo
speedfrom -100 to 100
Returns
pin number = success, -1 = no cogs available, -2 = no locks available, -3 = all 14 servo slots already filled.