oCenterSwitch4 Object

Back to top of page Description:
 

The oCenterSwitch4 Object is an I/O Function Object that is used to determine the center most active switch of a switch array. 

It is designed to gather information about moving objects such as a car driving over a set of pressure switches or a line that a robot needs to follow.

The oCenterSwitch4 Object can be configured to look at either 3 or 4 consecutive inputs.  It will report the position of the active switch, if it detects any active switches, which direction the active switch moved, and if there are no active switches, which side the active switch was on last.

 The following table lists the size and availability of the oCenterSwitch4 Object.
 ObjectSizeDescriptionA1A2B1B2C1
oCenterSwitch45 BytesAn Object that finds the center most active Input.xxx
Back to top of page Operation:
 

The oCenterSwitch4 Object monitors the 4 I/O lines specified by the IOPack property.  It is expecting that the 4 I/O lines are connected to an array of 4 switches that are arranged in such a way to detect a moving object.  It takes reading from these I/O lines and calculates a URCP Heading based on the position of the object and stores it in the Position property. 

Before the URCP Value is stored in the Position property, it is compared to the previous value and the Direction property is set based on the direction that the object has moved. 

If the object is in the middle of the switch array, then the Center property is set to 1, otherwise the Center property is set to 0.

If no switches are active, then the OutOfRange property is set to 1 and the Position property is set based on the value of the Mode property.  If the Mode property is 0, then the oCenterSwitch4 Object assumes that the object the switches are detecting has moved to the right or left of the switch array and the Position property is set to 32 or -32 depending on the value of the Direction property.    If the Mode property is 1, then the oCenterSwitch4 assumes that object the switches are detecting is between the two middle switches and the Position property is set to 0 and the Center property is set to 1.

Back to top of page Properties:

The following table lists the properties of the oCenterSwitch4 Object:

Property

Description

Position
A value that indicates the position of the active switch.
Object Class: oHeading Value Range: -32 to +32
Data Type: Numeric Default Value: 0
SwitchesModePositionCenterOutOfRange


URCP Heading

 ---->
1-3201
 ---X 
0 or 1-2400
 --XX 
0 or 1-1600
 --X- 
0 or 1-800
 -XXX 
0 or 1-800
 -XX- 
0 or 1010
 XXXX 
0 or 1010
 ---- 
0011
 -X-- 
0 or 1800
 XXX- 
0 or 1800
 XX-- 
0 or 11600
 X--- 
0 or 12400
<---- 
13201
All others0 or 1No Change
Centered
A value that indicates if the center switch(es) are active.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
CenterDescription
0The center switch(es) of the switch array is not the active one.
1The center switch(es) of the switch array are the active one(s).
(Line Switch Status = -XX- or XXXX)
Changed
A value that indicates if the active switch has changed.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
MovedDescription
0The inputs have not changed since the last time Changed was set to 0.
1The inputs have changed since the last time Changed was set to 0.
Direction
A value that indicates the direction that the active switches moved in the last change.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
DirectionDescription
0The last movement was towards the LSB switch
1The last movement was towards the MSB switch
OutofRange
A value that indicates that no switches are active.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OutofRangeDescription
0At least one switch is active.
1No switches are active.
IOPack
A value that specifies which pack of 4 I/O lines is connected to the switches.
Object Class: oIOPack Value Range: 0 - 7
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOPack help file for details.
Width
A value that selects how many I/O lines should be used.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
 The following table show the value of the Width property.
WidthEffect
0Use four switches for line detection.
1

Use only three switches for line detection. Setting this property has the following effects:

  • Bit 0 is left alone
  • Bit 2 is shifted over to bit 3's position
  • Bit 1 is copied into bit 2's position
  • Bit 3's input is ignored.

This means that basically the middle two bits are the same and the values are applied to the Value table above.

InvertIn
A value that selects if the inputs from the I/O lines should be inverted.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
InvertInDescription
0A high logic input (5 Volts) indicates an active switch.
1A low logic input (0 Volts) indicates an active switch.
Mode
A value that selects how to set the Center property when no switches are active.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
ModeDescription
0If no switches are active, assume the object is far outside either the left or right sides, depending upon the last direction seen. The Position property is set to either -32 or 32 depending upon the Direction property.
1If no switches are active, assume the object is between the center two switches. The Position property is set to 0 and the Center property is set to 1.
Operate
A value that selects whether or not the switches are evaluated.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOff

The switches are not evaluated.

1cvOn

The switches are evaluated.

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, the oCenterSwitch4 Object is used.
Visual Basic SyntaxC and Java Syntax
'This program creates a Virtual 
'Circuit that uses an oCenterSwitch4
'Object to track a line and 
'position a servo via an oServo
'Object for a line following robot.

Dim l As New oCenterSwitch4
Dim S As New oServoX
Dim W As New oBus

Sub Main()
  ooPIC.PullUp = cvTrue
  l.IOPack = 1
  l.Operate = cvTrue
  S.IOLine = 1
  S.Operate = cvTrue
  W.Input.Link(l.Position)
  W.Output.Link(S)
  W.Operate = cvTrue
End Sub
// This program creates a Virtual 
// Circuit that uses an oCenterSwitch4
// Object to track a line and 
// position a servo via an oServo
// Object for a line following robot.

oCenterSwitch4 l = New oCenterSwitch4;
oServoX S = New oServoX;
oBus W = New oBus;

Void Main(Void){
  ooPIC.PullUp = cvTrue;
  l.IOPack = 1;
  l.Operate = cvTrue;
  S.IOLine = 1;
  S.Operate = cvTrue;
  W.Input.Link(l.Position);
  W.Output.Link(S);
  W.Operate = cvTrue;
}
Basic Syntax 
' This program creates a Virtual 
' Circuit that uses an oCenterSwitch4
' object to track a line and 
' position a servo via an oServo
' object for a line following robot.

l As oCenterSwitch4(1,,,,cvOn)
S As oServoX(31,,,,,,,cvOn)
W As oBus(l.Position,,S.Position,cvOn)

ooPIC.PullUp = cvTrue
Back to top of pageConnections:
 See the oTracker Object for connection examples.

Back to top of page Related Items:

 The following table lists the objects that use the oCenterSwitch4 Object.
 ObjectDescriptionA1A2B1B2C1
oTrackerAn Object that tracks the position of a line.xxx
 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oOrbitSwitch4Reads a circular array of 4 switches.xx
oOrbitSwitch8Reads a circular array of 8 switches.xx
Back to top of page Version History and Bug List:
 Firmware Ver B1: Introduced.

Bugs: No known bugs.


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