RCServo Entity

API Documentation: [cpp] [python] [.NET] [LabVIEW]

The RCServo entity provides a pulsed signal based on the RC servo standard. This consist of a period lasting 20ms with a high pulse between 1-2ms. The time high corresponds to a specific position determined by the servo being used. For example if you are using a 90 degree servo a 1.5ms pulse will correspond to the 45 degrees. 1ms and 2ms pulses will correspond to 0 and 90 degree positions respectively.

The RCServo entity is an overload to the Digital Entity and therefor requires proper configuration of the Digital entity before the RCServo entity can be enabled.

Note

Not all BrainStem modules will have this capability.

Set/Get Enable

servo [ index ] . getEnable <= (unsigned char) enable
servo [ index ] . setEnable => (unsigned char) enable

This functions gets/sets the RCServo function for a given pin (pending, it has been properly configured in the digital entity). At a firmware level this enables/disables the timers.

Set/Get Position

servo [ index ] . getPosition <= (unsigned char) position
servo [ index ] . setPosition => (unsigned char) position

This functions gets/sets the RCServo position. For outputs this will return the currently set position; however, for inputs it will return the value seen at the pin pending the pulse is valid. If the pulse or period are invalid a zero will be returned along with the error code aErrRange.

The default range is: 64 (1ms) - 192 (2ms). For example when working with a 90 degree servo setting the position to 64 will give you 0 degrees and 192 will give you 90 degrees.

Note

getPosition() will return the original setPosition() regardless of the reverse settings.

Set/Get Reverse

servo [ index ] . getReverse <= (unsigned char) reverse
servo [ index ] . setReverse => (unsigned char) reverse

This functions gets/sets the reverse (invert) option in the RCServo Class.

Given a setPosition of 64 the servo pulse will be 1ms; however, if you reverse it the value will now be treated as 192.

Aligning the Digital and RCServo Entities

Digital Entity

Servo Entity

Pin Number

Assignment

digital[0]

servo[0]

Pin 0

RCServo Input

digital[1]

servo[1]

Pin 1

RCServo Input

digital[2]

servo[2]

Pin 2

RCServo Input

digital[3]

servo[3]

Pin 3

RCServo Input

digital[4]

servo[4]

Pin 4

RCServo Output

digital[5]

servo[5]

Pin 5

RCServo Output

digital[6]

servo[6]

Pin 6

RCServo Output

digital[7]

servo[7]

Pin 7

RCServo Output

Code Examples

C++

// All commands return aErr values when errors are encountered and aErrNone on
// success.

//Output
//Set digital pin 8 as an RCServo output.
err = stem.digital[8].setConfiguration(digitalConfigurationRCServoOutput);
//Enable the servo channel
err = stem.servo[4].setEnable(1);
//Set servo to middle/neutral position
err = stem.servo[4].setPosition(128);

//Input
//Set digital pin 0 as an RCServo input.
err = stem.digital[0].setConfiguration(digitalConfigurationRCServoInput);
//Enable the servo channel
err = stem.servo[0].setEnable(1);
//Set servo to middle/neutral position
err = stem.servo[4].getPosition(&pPosition);

Python

# All commands return aErr values when errors are encountered and aErrNone on
# success.

#Output
#Set digital pin 8 as an RCServo output.
err = stem.digital[8].setConfiguration(CONFIGURATION_RCSERVO_OUTPUT)
#Enable the servo channel
err = stem.servo[4].setEnable(1)
#Set servo to middle/neutral position
err = stem.servo[4].setPosition(128)

#Input
#Set digital pin 0 as an RCServo input.
err = stem.digital[0].setConfiguration(CONFIGURATION_RCSERVO_INPUT)
#Enable the servo channel
err = stem.servo[0].setEnable(1)
#Set servo to middle/neutral position
err = stem.servo[0].getPosition(&pPosition)