 |
oMath Object
|
|
|
Description: |
| | An Object that takes the value of two Objects, performs mathematical or Boolean operations on them, and copies the result to the another object. |
| | The following table lists the size and availability of the oMath Object and its variations.
| | Object | Size | Description | A1 | A2 | B1 | B2 | C1 |
 | oMath | 4 Bytes | Provides mathematical functions. | x | x | x | x | x |
 | oMathI | 5 Bytes | With 8-Bit Value on input 2. | x | x | x |
 | oMathO | With 8-Bit Value on Output. | x | x | x |
 | oMathC | 6 Bytes | Clocked mathematical functions. | x | x | x |
 | oMathIC | Clocked with 8-Bit Value on input 2. | x | x | x |
 | oMathOC | Clocked with 8-Bit Value on Output. | x | x | x |
|
Operation: |
| | The normal operation of the oMath Object is to take the values of the two Objects pointed to by the Input1 & Input2 properties, perform the operation specified by the Mode property, and then store the resulting value in the Object pointed to by the Output property once every Object List Loop. If the property option "C" is used, then the operation is modified so that this function only occurs once each time an oLogic Object transitions. Two evaluations are made on the resulting value. The Negative property is set to the result of a Negative-Value evaluation and the NonZero property is set to the result of a Not-Zero-Value evaluation. An 8-Bit signed Value property can be substituted for the either the Input2 or the Output property by specifying the appropriate property options. |
Property Options: |
| | The oMath Object has 6 variants which are selected with 3 different property options: I, O, and C.
- I specifies that the Input2 property is replaced with a Value property.
- O specifies that the Output property is replaced with a Value property.
- C specifies that a clocked version of the object is used.
| | Continuous operation | Clocked operation |
| Pointers for inputs and output: |  | oMath |  | oMathC |
| Signed 8-Bit Value on input 2: |  | oMathI |  | oMathIC |
| Signed 8-Bit Value on the output: |  | oMathO |  | oMathOC |
|
Properties: |
| | The following table lists the properties of the oMath Object:
Property | Description |
| Operate |
| A value that selects whether or not the mathematical operation is performed. |
 | Object Class: | oOperate | | Value Range: | 0 - 1 |
| Data Type: | Numeric | | Default Value: | 0 |
|
| Operate | Constant | Description |
| 0 | cvOff | The mathematical function is not performed. |
| 1 | cvOn | The mathematical function is performed. |
|
|
| Value |
| An 8-Bit value that replaces ether the Input2 or the Output properties. |
 | Object Class: | oChar | | Value Range: | -128 to +127 |
| Data Type: | Numeric | | Default Value: | 0 |
|
Availability: oMathI, oMathIC, oMathO, oMathOC |
|
| Input1 |
| A pointer to an object whose value is used in the mathematical operation. |
 | Object Class: | oValuePtrI | | Value Range: | Any oValue Object |
| Data Type: | Pointer | | Default Value: | Null |
|
|
| Input2 |
| A pointer to an object whose value is used in the mathematical operation. |
 | Object Class: | oValuePtrI | | Value Range: | Any oValue Object |
| Data Type: | Pointer | | Default Value: | Null |
|
Availability: oMath, oMathC, oMathO, oMathOC |
|
| Output |
| A pointer to an object whose Value will be updated with the result of the mathematical operation. |
 | Object Class: | oValuePtrO | | Value Range: | Any oValue Object |
| Data Type: | Pointer | | Default Value: | Null |
|
Availability: oMath, oMathC, oMathI, oMathIC |
|
| Mode |
| A value that selects which one of 8 math operations to performed. |
 | Object Class: | oSelect0to7 | | Value Range: | 0 - 7 |
| Data Type: | Numeric | | Default Value: | 0 |
|
| Mode | Constant | Description |
| 0 | cvAdd | Adds the values of Input1 and Input2 |
| 1 | cvSubtract | Subtracts the value of Input2 from the value of Input2. |
| 2 | cvLShift | Bit-shifts left the values of Input1 a number of times specified by Input2. |
| 3 | cvRShift | Bit-shifts right the values of Input1 a number of times specified by Input2. |
| 4 | cvAND | Input1 is ANDed with Input2. |
| 5 | cvOr | Input1 is ORed with Input2. |
| 6 | cvXOr | Input1 is XORed with Input2. |
| 7 | cvLatch | Input1 is copied to Output. |
|
|
| Negative |
| If Mode is 0-3, A value that indicates the result of the Output-value-is-negative evaluation. If Mode is 4-7, A value that specifies if the bits in the result will be inverted. |
 | Object Class: | oLogic | | Value Range: | 0 - 1 |
| Data Type: | Numeric | | Default Value: | 0 |
|
| Negative | Mode | Constant | Description |
| 0 | 0 - 3 | cvPositive | Output is positive in value. |
| 1 | 0 - 3 | cvNegative | Output is negative in value. |
| X | 4 - 7 | | Not updated. |
|
|
| NonZero |
| A value that indicates the result of the math function is not zero. |
 | Object Class: | oLogic | | Value Range: | 0 - 1 |
| Data Type: | Numeric | | Default Value: | 0 |
|
| NonZero | Constant | Description |
| 0 | cvFalse | Output is zero in value. |
| 1 | cvTrue | Output is not zero in value. |
|
|
Process Clock |
| See Clocked Objects for detail |
 | Object Class: | oClockedOperate | | Value Range: | 0 - 1 |
| Data Type: | Numeric | | Default Value: | 0 |
|
Availability: oMathC, oMathIC, oMathOC |
|
| 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 |
|
|
|
Example: |
| | The following examples use the oMath Object.
| Visual Basic Syntax | C and Java Syntax |
' This program reads two knob objects
' and adds them together using an
' oMath object and displays
' the result on a 7-Segment display.
Dim D As New o7Seg2
Dim K1 As New oKnob
Dim K2 As New oKnob
Dim M As New oMath
Sub main()
D.IOGroup = 3
D.IOLineD = 16
D.Mode = 1
D.Operate = cvOn
K1.IOLine = 1
K1.Operate = 1
K2.IOLine = 2
K2.Operate = 1
M.Input1.Link(K1)
M.Input2.Link(K2)
M.Output.Link(D)
M.Operate = 1
End Sub | // This program reads two knob objects
// and adds them together using an
// oMath object and displays
// the result on a 7-Segment display.
o7Seg2 D = New o7Seg2;
oKnob K1 = New oKnob;
oKnob K2 = New oKnob;
oMath M = New oMath;
Void main(Void){
D.IOGroup = 3;
D.IOLineD = 16;
D.Mode = 1;
D.Operate = cvOn;
K1.IOLine = 1;
K1.Operate = 1;
K2.IOLine = 2;
K2.Operate = 1;
M.Input1.Link(K1);
M.Input2.Link(K2);
M.Output.Link(D);
M.Operate = 1;
} |
| Basic Syntax | |
' This program reads two knob objects
' and adds them together using an
' oMath object and displays
' the result on a 7-Segment display.
D Var o7Seg2(3,16,1,0,cvOn)
K1 Var oKnob(1,cvOn)
K2 Var oKnob(2,cvOn)
M Var oMath(K1,K2,D,,cvOn) |
'This program creates a
'Virtual Circuit that adds
'two numbers and outputs
'the results on I/O line
'8-15 & 24-31.
Dim M As New oMath
Dim X As New oWord
Dim Y As New oWord
Dim Z As New oDIO16
Sub Main()
M.Input1.Link(X)
M.Input2.Link(Y)
M.Output.Link(Z)
M.Operate = cvTrue
Z.Direction = cvOutput
X = 16
Y = 4
End Sub | 'This program creates a
'Virtual Circuit that
'divides an oA2D reading
'by 4 and then sets the
'position of a servo with
'it.
Dim M As New oMathI
Dim X As New oA2D
Dim Z As New oServo
Sub Main()
M.Input1.Link(X)
M.Output.Link(Z)
M.Mode = cvRShift
M.Value = 2
M.Operate = cvTrue
X.IOLine = 1
X.Operate = cvTrue
Z.IOLine = 8
Z.Center = 26
Z.Operate = cvTrue
End Sub | 'This program creates a
'Virtual Circuit that adds
'two numbers and outputs
'the results on I/O
'line 8-15.
Dim M As New oMathO
Dim X As New oWord
Dim Y As New oWord
Dim Z As New oDIO8
Sub Main()
M.Input1.Link(X)
M.Input2.Link(Y)
M.Operate = cvTrue
Z.IOGroup = 1
Z.Direction = cvOutput
X = 8
Y = 4
Do
Z = M
Loop
End Sub |
|
Related Items:
|
| | The following table lists objects with related functions
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oNavCon | An Object that provides differential steering calculations. | x | x | x |
 | oRamp | An Object that calculate a ramp speed for a motor. | x | x |
|
Version History and Bug List: |
| | Firmware Ver A1: oMath Introduced. Firmware Ver B1: oMathC, oMathI oMathIC, oMathO, oMathOC Introduced.Bugs: firmware version A1-B2: Linking the oA2D to oMath directly causes the calculation to be incorrect. firmware version C1: No known bugs. |
|