oServoX Object

Back to top of page Description:
A Hardware Object that uses one digital I/O line to set the position of an RC servo-motor using URCP Heading values for positioning.

The oServoX Object is capable of positioning an RC Servo anywhere within its 180 degree rotational span.  The position within the 180 degree span is specified by a value with a range of -64 to 63 were 0 is the center position. Once the servo has reached the specified position, it is held in place until the specified position changes or the oServoX Object is turned off.

The oServoX Object uses 6 bytes of object memory and therefore the maximum number of oServoX Objects that can be dimensioned in a single application program is 13, limited only by the amount of object RAM.  If you need to control more servos, 20 of the oServo Objects (which use four bytes each) can be dimensioned in a single application.

The following table lists the size and availability of the oServoX Object.
 ObjectSizeDescriptionA1A2B1B2C1
oServoX6 BytesControls an RC Servo-motor with a signed value.xxx
Back to top of page Operation:
An oServoX Object positions a RC servo motor connected to the I/O Line specified by the IOLine property to a position specified by the Value, Adjust, Offset and Invert properties by outputting a PWM servo control pulse. 

When all 4 of the positioning values are set to 0, the servo will move to the middle position.  As the Position property increases, the servo will move to one direction.  And as the servo decreases, the servo will move to the other direction.  The Position property is a full 8-bit URCP Heading value, but since the servo can only rotate 180 degrees, one half of the range is not used.

When the Operate property is set to 1, the oServo Object will continuously output a PWM servo control pulse to the I/O Line specified by the IOLine  property. This results in the RC Servo holding at the position specified by the Position property. When the Operate property is cleared to 0, the oServo Object sets the specified I/O line to 0 volts.

At best case, it is possible to control all 13 possible oServoX servos at the same time with a low torque setting and 6 oServoX servos at the same time while maintain the high torque setting.  Note that only the servos with their Operate property set to 1 will be counted as controlled.

The IOLine property specifies which one of the ooPIC's 31 digital I/O Lines is to be used. 
NOTE: The IOLine property MUST be set before the Operate property is set to 1.

The Position property is used to specify the position of the servo. Its range is -64 to 63.  Note that the least significant bit is ignored which provides 64 steps over a 180 degree turning range. This works out to 2.8 degrees per step.  Note that position of -128 to 127 can be specified, but will be ignored.  What to do with positions in that range are controlled by the Offset and Mode properties.

The Offset property indicates which one-half section of the URCP Heading value to use and the Mode property specifies how the servo responds to values on the other half of the URCP Heading.

It is important to keep in mind that different servos have different mechanical capabilities. Some servos can rotate more than 180 degrees, some less than 180 degrees. A servo manufacturer typically publishes that their servos are only able to rotate 90 degrees with some areas for adjustment. This area for adjustment is usually another 90 degrees or so, giving the servo a full swing capability of 180 degrees.  The ooPIC will take advantage of the full rotational capability of the servo, whatever it may be.

The Adjust property is used to adjust the mechanical starting point of the 0 position. Its range is 0 to 127. It is also 2.8 degrees per step with the LSB ignored. This value is typically set to a value between 40 and 80 and must be customized for each servo.

By adjusting the Adjust property, The -64 to 63 range of the Position property can be centered over the 180 degree range of the mechanical capability of the servo. Every servo is different.  Even with the same manufacturer and model of servo, the mechanical capability may translate to a different area of the servo, so it is important to make this adjustment for each servo you use.

When adjusting the Adjust Value to find the proper value, first set the Adjust property to 40 and the Position property to 0. Slowly move the Adjust property down until the actuator on the servo hits its mechanical stop. Then bring the Adjust property up by 1.

The Invert property causes the servo to move in the opposite direction. This is useful when you are using servos as drive motors on opposite sides of a robot.

The Invert property is used to reverse the direction that the servo will rotate in response to the Value and Adjust properties.

The Invert property is useful when two servos need to rotate in opposite directions when given the same position value. Such applications include Hexapod Walkers, or modified servos driving the wheels on a robotic base. When doing this, one servo's Invert property needs to be set to 0 and the second servo's Invert Property needs to be set to 1.

Note: If a servo's Adjust property has already been adjusted and then the Invert property is changed, the Adjust property will need to be recalculated for the other side of the servo's mechanical capabilities.

The Torque property controls how strong the servo's turning power is.  (see history)  Setting the Torque property to 1 (high-torque) will double the servo's turning power. Note that when the torque is set to high, the servo will draw twice the current from the battery.  Note that the torque property will be overridden when using several servos.  (see the oPWMS object for details.)

When created, the oServo Object also creates an instance of the oPWMS object which it uses to generate and output the signal that controls the servo.  Modifying any of the properties of the oPWMS instance will affect the oServo Object's operation.  See the oPWMS Help for more detail on how servos are controlled.

Back to top of page Properties:

The following table lists the properties of the oServoX Object:

Property

Description

Position
A value that specifies the position of the servo-motor
Object Class: oHeading Value Range: -128 to 127
Data Type: Numeric Default Value: 0
PositionHeading


URCP Heading

N0
NE32
E64
SE96
S-128
SW-96
W-64
NW-32
IOLine
A value that specifies which I/O Line is used to control the Servo.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
Adjust
A value that adjusts where the servo's mechanical center is.
Object Class: oVar7 Value Range: 0 - 127
Data Type: Numeric Default Value: 0
OffSet
A value that specifies where to place the servo's mechanical capability.
Object Class: oVar8 Value Range: -128 to +127*
Data Type: Numeric Default Value: 0
The Position property is capable of specifying one of 256 possible Brad positions (360 degrees).  A typical RC servo has a mechanical limit of 128 Brads (180 degrees).  The offset property specifies which Brad the servo is to consider the center of its movement.
If the Position property is set to a value that sits outside the mechanical limits as specified by the Offset property, then the OutofRange property is set.
OffsetThe servo will be at
Center when the
Position property is:
The servo will be
positioned for values:
AnyAt the Offset valueOffset-64 to Offset+63
Examples
0 0-64 to +63
64 640 to +127
-64-64-128 to -1
Invert
A value that selects if the servo's physical position is inverted.
Object Class: oSelect0to1L Value Range: 0 - 1
Data Type: Numeric Default Value: 0
InvertConstantDescription
0cvFalse

The Servo positioning is normal

1cvTrue

The Servo positioning is reversed.

Torque
A value that selects the servo's torque.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
Availability: This property was added if firmware version B.2.
OperateConstantDescription
0cvFalse

The Servo is normal..

1cvTrue

The Servo control signal is doubled.

Mode
A value that selects how the servo responds to values outside of it's mechanical limit.
Object Class: oSelect0to3 Value Range: 0 - 3
Data Type: Numeric Default Value: 0
ModeDescription
0The servo splits the inaccessible area into 2 parts and will position itself to the side closest to the Position property.
1The servo will position itself on the low value side.
2The servo will position itself on the high value side.
3The servo will shut off.
Operate
A value that selects if the servo is on or off.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe servo is off.
1cvOnThe servo is on.
OutofRange
A value that indicates the Position property is outside of the mechanical capability of the servo.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe servo is position inside its mechanical limits as specified by the Offset property
1cvOnThe servo is position outside its mechanical limits as specified by the Offset property
PWM
The I/O function object used to control the servo.
Object Class: oPWMS Value Range: 0 - 63
Data Type: Numeric Default Value: 0
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of page Examples:
In the following example, a Servo is moved back and forth.
'This program moves a servo to the 
'center, then left of center, then
'back to center then right of center.

Dim S As New oServoX

Sub Main()
  S.IOLine = 1
  S.Operate =cvTrue
  Do
   S = 0:   ooPIC.delay = 150
   S = 31:  ooPIC.delay = 150
   S = 0:   ooPIC.delay = 150
   S = -31: ooPIC.delay = 150
  Loop
End Sub
Back to top of pageConnections:
A RC Servo requires only one I/O Line connection to the ooPIC.  It is absolutely necessary that the servo be driven by a different power source than the one that the ooPIC is using AND that the ground of each power supply be connected together.

The IOLine property is used to specify which one of the ooPIC's 31 I/O lines will be used to connect to the control line of the servo. Any I/O lines can be used, but you may want to keep in mind that other Objects, such as the oA2D Object, can only use certain I/O lines. If you are planning to use these other Objects, you may need to avoid using those I/O lines.

RC servos normally have 3 wires: Power, Ground and Control. The Control wire is used to specify were the servo is positioned and is connected to the I/O lines specified by the IOLine property. This control wire is usually yellow or white, but can be any color other than red or black.

The I/O lines can be connected directly to the servo. However, if you are powering your servo with a power supply of less than +5 Volts, you will need to put a 1k resistor between the I/O line and the servo's control line.

Servos can be powered by a wide range of voltages between 4.8 and 6 volts. Be sure to consult the manufacturer's specifications before applying power. Also, be sure not to power the servo from the same power supply as the ooPIC. A servo will pull large amounts of power in quick surges causing the servo's power supply to periodically drop below 4.5 volts. The ooPIC has a brown out circuit that resets the ooPIC if its power supply goes under 4.5 volts. Using separate power supplies will prevent the ooPIC from resetting when driving a servo.

More diagrams can be found on the help page for oServo

Back to top of page Related Items:

The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oRCIN(1-6)An Object that reads a Radio Receiver with up to 6 channels.x
oServoControls an RC Servo-motor.xxxxx
oServoSEControls a Scott Edwards Serial Servo controller.xxx
oServoSP(1,2)Controls an RC Servo modified for continuous rotation.xx
Back to top of page Version History and Bug List:
Firmware Ver B1: Introduced.
Firmware Ver B2: Torque property added.

Bugs: No known bugs.


 

ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.