[Up] [Transmit VB Code] [Receive VB Code] [Feedback Hardware]
'MultiBot II Interface Source Code
'Senior Project 2003
'Transmit Side
'frmMain
Dim command As String 'variable to store the current command
Public StartingAddress As String
Option Explicit
Private Sub cmdTurnCamLeft_Click()
'sends command to robot to turn camera left
MSComm1.Output = "tturnl"
End Sub
Private Sub cmdTurnCamRight_Click()
'sends command to robot to turn camera left
MSComm1.Output = "tturnr"
End Sub
Private Sub cmdstopcam_Click()
'sends command to robot to stop camera
MSComm1.Output = "sstopcam"
End Sub
Private Sub Form_Load()
'Comm Port is initally NOT active
'Set Status Label
lblStatus.FontSize = 18
lblStatus = "Inactive"
'Put the Delay times in the correspoding text boxes
txtMotor = tmrdelay.Interval
txtTrim = tmrDelay2.Interval
'puts address of camera on robot in string
StartingAddress = "http://169.254.87.21/servlet/RouteGfrGui?routeip=169.254.87.21&routeport=80"
'browser on form displays address above
brwWebBrowser.Navigate StartingAddress
End Sub
Private Sub chkArrows_KeyDown(KeyCode As Integer, Shift As Integer)
'Check if NumPad is Enabled
If chkArrows.Value = 1 Then
'Code to Real Time Arrow Controls
'Each key's code is linked to the button
'it represents, the Keydown event will only work
'while the chkbox is in focus. If the chkbox lose's
'focus than the robot is stopped.
Select Case KeyCode
Case vbKeyNumpad6
Call cmdRight_Click
Case vbKeyNumpad4
Call cmdLeft_Click
Case vbKeyNumpad8
Call cmdFrwd_Click
Case vbKeyNumpad2
Call cmdReverse_Click
Case vbKeyNumpad5
Call cmdStop_Click
Case vbKeyNumpad7
Call cmdLTrim_Click
Case vbKeyNumpad9
Call cmdRTrim_Click
End Select
End If
End Sub
Private Sub chkArrows_LostFocus()
'If chkbox lose's Focus than robot is to stop
If command <> "stop" Then
Call cmdStop_Click
End If
chkArrows.Value = 0
End Sub
Private Sub cmdConnect_Click()
'Open the Comm Port
MSComm1.PortOpen = True
'Set Status and Port Status Labels
lblStatus.FontSize = 15
lblStatus.Caption = "Active"
lblpstatus.FontBold = True
lblpstatus.Caption = "Connected"
'Upon connection with the robot
'Enable all of the command buttons
cmdFrwd.Enabled = True
cmdLeft.Enabled = True
cmdReverse.Enabled = True
cmdRight.Enabled = True
cmdStop.Enabled = True
cmdLTrim.Enabled = True
cmdRTrim.Enabled = True
cmdDiscon.Enabled = True
cmdConnect.Enabled = False
chkArrows.Enabled = True
End Sub
'This Sub-Routine allows the controller to set the
'Motor Relay switching delay as well as the Trim length
Private Sub cmdDelayChange_Click()
Dim Msg As String
Msg = "Invalid Value, Must Be Greater Than 100"
If txtMotor.Text < 100 Then
MsgBox Msg, vbExclamation, "Error"
Else
tmrdelay.Interval = txtMotor.Text
End If
If txtTrim.Text < 100 Then
MsgBox Msg, vbExclamation, "Error"
Else
tmrDelay2.Interval = txtTrim.Text
End If
End Sub
Private Sub cmdDiscon_Click()
'When the Disconnect Command is given
'Stop the Robot
Call cmdStop_Click
'Close the Comm Port
MSComm1.PortOpen = False
'Set Status and Port Status Label
lblStatus.FontSize = 12
lblpstatus.FontBold = True
lblpstatus.Caption = "Disconnected"
'Disable Command Buttons
cmdFrwd.Enabled = False '
cmdLeft.Enabled = False
cmdReverse.Enabled = False
cmdRight.Enabled = False
cmdStop.Enabled = False
cmdLTrim.Enabled = False
cmdRTrim.Enabled = False
cmdDiscon.Enabled = False
cmdConnect.Enabled = True
chkArrows.Enabled = False
End Sub
Private Sub cmdFrwd_Click()
'Stop the robot
Call cmdStop_Click
'Set Status Label
lblStatus.FontSize = 18
lblStatus = "Stopped"
'Sets command value which will be
'sent to Robot computer
command = "forward"
'Relay Switching Delay (intially 3 seconds)
tmrdelay.Enabled = True
End Sub
Private Sub cmdLeft_Click()
'Stop the robot
Call cmdStop_Click
'Set Status Label
lblStatus.FontSize = 18
lblStatus = "Stopped"
'Sets command value which will be
'sent to Robots computer
command = "left"
'Relay Switching Delay (intially 3 seconds)
tmrdelay.Enabled = True
End Sub
Private Sub cmdLTrim_Click()
'Send command out the Comm Port to the RF board
MSComm1.Output = "lltrim"
'Activate Trim Delay
tmrDelay2.Enabled = True
'Set Status Label
lblStatus.FontSize = 14
lblStatus = "Trimming Left"
End Sub
Private Sub cmdReverse_Click()
'Stop the Robot
Call cmdStop_Click
'Set Status Label
lblStatus.FontSize = 18
lblStatus = "Stopped"
'Set the command value which will be
'sent to the Robots computer
command = "reverse"
'Relay Switching Delay (intially 3 seconds)
tmrdelay.Enabled = True
End Sub
Private Sub cmdRight_Click()
'Stop the Robot
Call cmdStop_Click
'Set the Status Label
lblStatus.FontSize = 18
lblStatus = "Stopped"
'Set the command value which will be
'sent to the Robots computer
command = "right"
'Relay Switching Delay (intially 3 seconds)
tmrdelay.Enabled = True
End Sub
Private Sub cmdRTrim_Click()
'Send command out the Comm Port to the RF board
MSComm1.Output = "rrtrim"
'Activate Trim Delay
tmrDelay2.Enabled = True
'Set the Status Label
lblStatus.FontSize = 14
lblStatus = "Trimming Right"
End Sub
Private Sub cmdStop_Click()
'Send command out the Comm Port to the RF board
MSComm1.Output = "sstop"
'Set the Status Label
lblStatus.FontSize = 18
lblStatus.FontBold = True
lblStatus.Caption = "Stopped"
End Sub
Private Sub FExit_Click()
'Exit the Program
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
'If program is closed send stop to robot.
'Send command out the Comm Port to the RF board
MSComm1.Output = "sstop"
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement
' Errors
Case comEventBreak ' A Break was received.
'If there is a break in the RF communication
'Stop the robot
Call cmdStop_Click
'Set Status Label
lblStatus.Caption = "Connection Broken"
Case comEventFrame ' Framing Error
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]
' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer
Case comEvEOF ' An EOF charater was found in
' the input stream
End Select
End Sub
Public Sub tmrdelay_Timer()
'in each of the case statements we added an extra character at the
'begining of each string that is to be outputted because the RF boards
'scramble the first character
Select Case command
Case "forward"
'Sends command out the Comm Port
MSComm1.Output = "fforward"
'Stop the timer from looping
tmrdelay.Enabled = False
'Set the status label
lblStatus.FontSize = 14
lblStatus = "Moving Forward"
Case "reverse"
'sends command out the comm port
MSComm1.Output = "rreverse"
'stop the timer from looping
tmrdelay.Enabled = False
'Set the status label
lblStatus.FontSize = 14
lblStatus = "Moving Backward"
Case "left"
'sends command out the comm port
MSComm1.Output = "lleft"
'Stop the timer from looping
tmrdelay.Enabled = False
'set the status label
lblStatus.FontSize = 14
lblStatus = "Turning Left"
Case "right"
'sends the command out the comm port
MSComm1.Output = "rright"
'stop the timer from looping
tmrdelay.Enabled = False
'set the status label
lblStatus.FontSize = 14
lblStatus = "Turning Right"
Case "LTrim"
'sends the command out the comm port
MSComm1.Output = "lltrim"
'starts the trim delay timer
tmrDelay2.Enabled = True
'set the status label
lblStatus.FontSize = 14
lblStatus = "Trimming Left"
Case "RTrim"
'sends the command out the comm port
MSComm1.Output = "rrtrim"
'starts the trim delay timer
tmrDelay2.Enabled = True
'set the status label
lblStatus.FontSize = 14
lblStatus = "Trimming Right"
End Select
End Sub
Private Sub tmrDelay2_Timer()
'Stop the robot
Call cmdStop_Click
'initates delay for the Trim
tmrDelay2.Enabled = False
'stops motor delay timer from looping
tmrdelay.Enabled = False
End Sub
Private Sub tmrfeedback_Timer()
'timer is initiated by on form option
'initiates needed variables
Dim fp As Long
Dim filename As String
Dim moving As String
Dim direction As String
Dim sonar As String
'sets path of file to be read
filename = "\\slave\feedback\feedback.txt"
'gets a file pointer number from the system
fp = FreeFile
'opens the file to be read from and reads comma deliminated
'items into seperate variables then closes file (must be done)
Open filename For Input As #fp
Input #fp, moving, direction, sonar
Close #fp
'copies variables to text boxes on form
txtmoving.Text = moving
txtdirection.Text = direction
txtsensor.Text = sonar
If sonar <> "CLEAR" Then
'Stop the robot
Call cmdStop_Click
End If
End Sub