oServo Object
An Object that controls a servo-motor
Description:
 

A Hardware Object that uses one digital I/O line to set the position of an RC servo-motor.

The oServo 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 0 to 63 and once the servo has reached the specified position, it is held in place until the specified position changes or the oServo Object is turned off.

The maximum number of oServo Objects that can be dimensioned in a single application program is 21, limited only by the amount of Object RAM.  At best case, it is possible to control all 21 oServo Objects at the same time with a high torque setting of 70 Pulses Per Second.  At worse case, All 21 possible oServo Objects at full swing can be controlled at the same time while maintaining a 20 Pulses Per Second refresh rate.

The oServo and all other servo Objects use a default refresh rate of 35 Pulses Per Second.  This refresh rate can be doubled to 70 Pulses Per Second to provide a higher torque output from the servos.  Up to 12 servos positioned at full swing swing can be controlled at the same time while maintaining a 35 Pulses Per Second refresh rate and up to 6 servos positioned at full swing can be controlled at the same time while maintaining a 70 Pulses Per Second refresh rate. 

Operation:
 

An oServo Object positions a RC Servo motor connected to the I/O Line specified by the IOLine property to a position specified by the Value, Center and InvertOut properties. The position information is sent to the RC Servo in the form of a PWM servo control pulse that is sent out the I/O line repeatedly.

An Operate property specifies if the servo is active or not.  When set to 1 the oServo Object is active and will continuously output a PWM servo control pulse which results in the RC Servo turning to and holding at the specified position. When the Operate property is cleared to 0 the oServo Object is inactive and the specified I/O line is set to 0 volts which releases the servo.

The IOLine property specifies which one of the OOPic's 31 digital I/O Lines is to be used. When set to 0, the PWM servo control pulse is not outputted. When set to a value other than 0 the oServo Object will, when active, set that I/O line to an Output and use that I/O line for controlling the servo.

The Value property is used to specify the relative position of the servo.  Internally, the Value property is adjusted be the Center, and InvertOut properties which are used to adjust the actual mechanical positioning.  Note that the Center, and InvertOut properties only need to be set once and that after they are set, the Value property is the only property used to position the servo.

The Center property adjusts the servo's position by offsetting the Value property and must be adjusted for the mechanical differences of each different servo motor connected to the OOPic. The InvertOut property is used to reverse the direction that the servo turns in response to the Value and Center properties.

The oServo Object is tailored to control a standard RC Servo by generating a PWM servo control pulse with the Logical High-Going pulse ranging from 0 to 3ms in duration in 1/36ms increments. A typical servo with a rotational range of 180 degrees is positioned by the duration of a Logical high-going pulse in the range of .61ms to 2.36ms.  If the InvertOut property is set to 0 then the PWM's Logical high-going pulse time is calculated as ((Value + Center.) * (1/36))  If the InvertOut property is set to 1 then the pulse time is calculated as ((107 - (Value + Center)) * (1/36)). Note that each unit of magnitude of the control pulse time is equal to 1/36ms

PWM Servo Control Pulse Duration Examples:
In the case of positioning a servo at 0 degrees set the Value property to 0 and the Center property to 22.
((0+22) * (1/36)) = .61
In the case of positioning a servo at 180 degrees (full swing) set the Value property to 63 and the Center property to 22.
((63+22) * (1/36)) = 2.36
In the case of positioning a servo at 180 degrees (full swing) while turning in reverse set the Value property to 0 the Center property to 22 and the InvertOut property to 1.
((107-(0+22)) * (1/36)) = 2.36

Each dimensioned instance of the oServo Object shares the Servo Motor Control (SM) module which multitasks between all active servos.  The SM module provides the PWM servo control pulse that is required to electrically refresh a servo motor's position. The SM control module can output the PWM control pulse on any of the OOPic's 31 I/O Lines.

When the SM control module is activated, it looks for the first active servo Object. (The first servo Object with its Operate property set to 1). That servo's I/O line is set to 1 and the PWM Logical high-going pulse output is generated. When the duration of the PWM Logical high-going pulse is met, the I/O line is set to 0 and the SM control module moves to the next active servo Object. The SM control module will systematically continue through each active servo Object until all have been completed and then repeats the process.

The servo's refresh cycle is a result of the SM control module being activated 35 times each second, which in turn outputs the PWM Logical high-going pulse for each active oServo Object 35 times per second. If the sum of the durations of all PWM Logical high-going pulses from all the active oServo Objects totals more than 1/35th of a second, then the refresh cycle time is stretched to accommodate the total time.  For example; 12 servos at full swing requires 33.04 milliseconds. (2.36ms * 12 servos = 0.02832 Seconds) which is within the 1/35th of a second (0.02857 Seconds) time frame, therefore, the refresh cycle is not stretched.  But, 21 servos at full swing requires 49.56 milliseconds. (2.36ms * 21 servos = 0.04956 Seconds) which will stretch the refresh cycle time down to 20.18 times per second.

As of firmware B.2.x, the servo's refresh cycle time can be set to a high torque mode of  70 Pulses Per Second.  This mode can be selected by setting the OOPic.SrvRefresh Property to 1.  When in this mode, all the timing calculations discussed above are adjusted appropriately.

Remarks:
 

After the IOLine property is set, the specified IOLine will remain in its former logic state of either High-Z, High, or Low until the operate property is set to 1.

Storage size & Availability:
  The following table lists the size and availability of the oWire Object:
ObjectSizeVersion
oServo 4 Bytes A.1.0 and greater
Properties:
 

The following table lists the Properties of the oServo Object:
Property Description
Address

Returns a pointer to the address of the oServo Object instance.

Data-Type: Number-Pointer, Read-Only

Data-Range: 0 - 127

Center

Adjusts the value for the servo's mechanical center.

Data-Type: Byte

Data-Range: 0 - 63

InvertOut

A value that specifies if the output pulse is reversed.

Data-Type: Bit, Flag

Data-Range: 0 - 1

The following table lists the values of the InvertOut Property:
InvertOut Constant Description
0 cvFalse

The Servo control signal is normal

1 cvTrue

The Servo control signal is reversed.

IOLine

The physical I/O Line to use.

Data-Type: Byte

Data-Range: 0 - 31

Operate

A value that specifies whether or not the pulse is outputted.

Data-Type: Bit, Flag

Data-Range: 0 - 1

The following table list the values of the Operate Property.
Operate Constant Description
0 cvFalse

The Servo control signal is not outputted.

1 cvTrue

The Servo control signal is outputted.

String

The Value property represented as a string.

Note: The String property is available in OOPic Basic Version 2.

Data-Type: String

Value

The value specifying the position of the servo-motor.

Data-Type: Byte Default

Data-Range: 0 - 127

Example:
  In the following example, a Servo is moved back and forth.
'The servo connects to IOLine 31
'The servo continuously move to 0% then 180%.

Dim S1 As New oServo

Sub main()
  S1.IOLine = 31
  S1.Center = 28
  S1.Operate =cvTrue
  Do
     S1 = 0
     OOPic.delay = 150
     S1 = 63
     OOPic.delay = 150
  Loop
End Sub
Connections:
 
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.
See Also:
  oServoX - An Object that uses URCP Heading values to control an RC Servo.
oServoSP - An Object that uses URCP Speed values to control a modified RC Servo.
oServoSE
- An Object that controls a Scott Edwards mini ssc II servo controller module.
OOPic.SrvRefresh - A property that selects a 70 Pulses Per Second refresh rate for all servos.