Here's an improved program for the DiscRover. This new code uses the OOPic's Virtual Circuit technology.
These VCs are an integral part of OOPic programming and are ideally suited for event-based programming, something that's key in robotic control.
By re-coding the control routine with VCs, we are able to easily create more sophisticated behaviors for the individual switches
(the program in the book only has one set back-up routine that occurs when one or both switches are triggered). Building the code with VCs
also makes it easier to layer on new, more complicated routines
as we add other sensor systems. This code was created by Jesse Hurdus. Thanks, Jesse!
Dim S As New oSerialX
Dim LSwitch As New oDio1
Dim LTouch As New oWire
Sub Main( )
OOPic.Pullup = cvTrue
LSwitch.IOLine = 8
R.IOLine = 31
LTouch.Input.Link(LSwitch.Value)
LTouch.Operate = cvTrue
Do
End Sub
Sub LTurn_CODE ( ) 'left turn sub-procedure
S.Value = 128
End Sub
Sub RTurn_CODE ( ) 'right turn sub-procedure
S.Value = 128
End Sub
'An event driven program using Virtual Circuits
'to control two DC motors through a Pololu Motor Controller
'with two bump switches.
Dim R As New oDio1
Dim RSwitch As New oDio1
Dim RTouch As New oWire
Dim LTurn As New oEvent
Dim RTurn As New oEvent
LSwitch.Direction = cvInput 'Switch Initialization
RSwitch.IOLine = 10
RSwitch.Direction = cvInput
S.Baud = cv4800
S.IolineS = 30
S.Operate = cvTrue 'Motor controller serial initialization
R.Direction = cvOutput
OOPic.Delay = 50
LTouch.InvertIn = cvTrue
LTouch.Output.Link(RTurn.Operate)
RTouch.Input.Link(RSwitch.Value) 'setup bump parameters
RTouch.InvertIn = cvTrue
RTouch.Output.Link(LTurn.Operate)
RTouch.Operate = cvTrue 'begin watching for events
S.Value = 128
S.Value = 0
S.Value = 0
S.Value = 127 'travel forward
S.Value = 128
S.Value = 0
S.Value = 3
S.Value = 127
OOPic.Delay = 150
Loop
S.Value = 0
S.Value = 1
S.Value = 45
S.Value = 128
S.Value = 0
S.Value = 2
S.Value = 127
OOPic.Delay = 150
S.Value = 0
S.Value = 1
S.Value =127
S.Value = 128
S.Value = 0
S.Value = 2
S.Value = 45
OOPic.Delay = 150