Visual Basic Code (April 30, 2001 5:00 pm)

 

Option Explicit                 ' Variables must be defined

Dim flag As Boolean             ' Allow for continuation of event

Dim X, Y As Integer             ' Coordinate direction increment (-1,0,1)

Dim sDirection As String        ' Character variable for robot heading

Dim bSetPoint As Boolean        ' Initial starting point

Dim bBackwards As Boolean       ' Backwards movement flag

 

'Private Sub cmdDraw_Click()     ' Drawing routine

Public Sub PlotRobot()         ' Robot plotting routine

'    Dim time As Long            ' Pause counter

   

'    flag = True                 ' Allow for event continuation

   

'    Do While flag               ' Draw a line until stopped

        DoEvents                ' Allow for other actions to occur

        Call Direction           ' Get plotting direction

        If picDraw.CurrentX > 0 And picDraw.CurrentX < 10000 And _

           picDraw.CurrentY > 0 And picDraw.CurrentY < 6000 Then

            If frmSerial.sInstr = "B" Then      ' Direction dependent line color

                picDraw.PSet Step(X, Y), vbRed  ' Draws a red line

            Else

                picDraw.PSet Step(X, Y), vbBlue ' Draws a blue line

            End If

        Else

            ' Error message

            MsgBox "Robot out of bounds!" & vbNewLine & _

                   "Robot position will be reset"

            ' Reset position

            picDraw.CurrentX = 5000     ' Initialize x-coordinate

            picDraw.CurrentY = 3000     ' Initialize y-coordinate

            sDirection = "N"            ' Initialize direction

            ' Break from movement

 '           flag = False

        End If

  '      For time = 1 To 1000000: Next    ' Pause

   

        ' Display realtime plotting information to user

        lblInfo.Caption = "Plotting current position"

        lblPosition.Caption = "X: " & picDraw.CurrentX & "  Y: " & picDraw.CurrentY

 '   Loop

   

    lblInfo.Caption = "Program Stopped Successfully!"

 

End Sub

 

Private Sub cmdExit_Click()

    End                         ' Exit program

End Sub

 

Private Sub cmdStop_Click()     ' Stop action

    flag = False                ' Set flag to stop action

End Sub

 

Private Sub Form_Load()

    picDraw.CurrentX = 5000     ' Initialize x-coordinate

    picDraw.CurrentY = 3000     ' Initialize y-coordinate

    sDirection = "N"            ' Initialize direction

End Sub

Private Sub Direction()          ' Plotting of BOEBot path

 

If frmSerial.bDirChange Then    ' Allow direction change?

  Select Case frmSerial.sInstr  ' Determine direction

    Case "F"                    ' Forward - no need to alter direction

        If bBackwards Then      ' Moving backwards?

          Select Case sDirection    ' Alter the direction

            Case "N": sDirection = "S"

            Case "S": sDirection = "N"

            Case "E": sDirection = "W"

            Case "W": sDirection = "E"

          End Select

          bBackwards = False        ' Moving forwards

        End If

    Case "B"                        ' Backward

        bBackwards = True           ' Set flag to let user know going backwards

        Select Case sDirection      ' Alter the direction

            Case "N": sDirection = "S"

            Case "S": sDirection = "N"

            Case "E": sDirection = "W"

            Case "W": sDirection = "E"

        End Select

    Case "R"                        ' Right

        If bBackwards Then          ' Moving backwards?

          Select Case sDirection    ' Backwards logic

            Case "N": sDirection = "W"

            Case "S": sDirection = "E"

            Case "E": sDirection = "N"

            Case "W": sDirection = "S"

          End Select

          bBackwards = False        ' Moving right

        Else

          Select Case sDirection    ' Fowards logic

            Case "N": sDirection = "E"

            Case "S": sDirection = "W"

            Case "E": sDirection = "S"

            Case "W": sDirection = "N"

          End Select

        End If

    Case "L"                        ' Left

        If bBackwards Then          ' Moving backwards?

          Select Case sDirection    ' Forwards logic

            Case "N": sDirection = "E"

            Case "S": sDirection = "W"

            Case "E": sDirection = "S"

            Case "W": sDirection = "N"

          End Select

          bBackwards = False        ' Moving left

        Else

          Select Case sDirection    ' Forwards logic

            Case "N": sDirection = "W"

            Case "S": sDirection = "E"

            Case "E": sDirection = "N"

            Case "W": sDirection = "S"

          End Select

        End If

  End Select

  frmSerial.bDirChange = False  ' Do not allow direction change

End If                          ' End direction change

 

Select Case sDirection          ' Set plot direction

        Case "N"                ' North

            X = 0: Y = -1

        Case "S"                ' South

            X = 0: Y = 1

        Case "E"                ' East

            X = 1: Y = 0

        Case "W"                ' West

            X = -1: Y = 0

    End Select

End Sub