M:\Mike (4-19)\Stub Programs\Follow Me\vidcap test.frm
File saved: 4/24/2006 6:43:56 PM
Generated: 4/24/2006 6:54:02 PM
Table of Contents (Designer Object Definition) Declarations SendCommand Move_Servo HandlePacket pollme GetBinary Center_Click Command3_Click Forward_Click Left1_Click left4_Click Reverse_Click Right1_Click right4_Click STOP_Click threesixtyleft_Click threesixtyright_Click Form_Activate Form_Unload Build_Combos Form_Load Lock_Buttons Restore_Buttons Command5_Click Command1_Click command_middle_mass_on_servo_to_Click command_middle_mass_off_Click command_middle_mass_on_Click Command2_Click Command4_Click Reg_Update_Click Reset_regs_Click RGB_OFF_Click RGB_ON_Click Ser_In_Change stop_loop_Click unlock_movement_Click YcrCb_off_Click YcrCb_on_Click DIR_Change Output_Change
VERSION 5.00 Table of Contents Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "Richtx32.ocx" Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Form1" ClientHeight = 8565 ClientLeft = 45 ClientTop = 1680 ClientWidth = 15255 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 571 ScaleMode = 3 'Pixel ScaleWidth = 1017 Begin VB.Frame Frame11 Caption = "Line Mode Data" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1935 Left = 9960 TabIndex = 68 Top = 3600 Width = 3015 Begin VB.PictureBox pic_hi Height = 1455 Left = 840 ScaleHeight = 1395 ScaleWidth = 1155 TabIndex = 69 Top = 360 Width = 1215 End End Begin VB.Frame Frame10 Caption = "Directions to Move" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 8415 Left = 13080 TabIndex = 62 Top = 120 Width = 2055 Begin RichTextLib.RichTextBox DIR Height = 8055 Left = 120 TabIndex = 63 Top = 240 Width = 1815 _ExtentX = 3201 _ExtentY = 14208 _Version = 393217 Enabled = -1 'True ReadOnly = -1 'True ScrollBars = 2 TextRTF = $"vidcap test.frx":0000 End End Begin VB.Frame Frame6 Caption = "Robot Controls" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 3015 Left = 9960 TabIndex = 48 Top = 5520 Width = 3015 Begin VB.CommandButton right4 Caption = "Right 4" Height = 495 Left = 2040 TabIndex = 66 Top = 1920 Width = 735 End Begin VB.CommandButton left4 Caption = "Left 4" Height = 495 Left = 120 TabIndex = 65 Top = 1920 Width = 735 End Begin VB.CommandButton unlock_movement BackColor = &H0000FF00& Caption = "Unlock Robot" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 120 MaskColor = &H0080FFFF& Style = 1 'Graphical TabIndex = 64 Top = 240 Width = 2655 End Begin VB.CommandButton Stop BackColor = &H000000FF& Caption = "Stop" BeginProperty Font Name = "MS Sans Serif" Size = 13.5 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 240 Style = 1 'Graphical TabIndex = 56 Top = 2520 Width = 2415 End Begin VB.CommandButton threesixtyright Caption = "360 Right" Height = 495 Left = 2040 TabIndex = 55 Top = 720 Width = 735 End Begin VB.CommandButton threesixtyleft Caption = "360 Left" Height = 495 Left = 120 TabIndex = 54 Top = 720 Width = 735 End Begin VB.CommandButton Right1 Caption = "Right 2" Height = 495 Left = 2040 TabIndex = 53 Top = 1320 Width = 735 End Begin VB.CommandButton Left1 Caption = "Left 2" Height = 495 Left = 120 TabIndex = 52 Top = 1320 Width = 735 End Begin VB.CommandButton Reverse Caption = "Reverse" Height = 495 Left = 1080 TabIndex = 51 Top = 1920 Width = 735 End Begin VB.CommandButton forward Caption = "Forward" Height = 495 Left = 1080 TabIndex = 50 Top = 720 Width = 735 End Begin VB.CommandButton center Caption = "Center" Height = 495 Left = 1080 TabIndex = 49 Top = 1320 Width = 735 End End Begin VB.Frame Frame9 Caption = "Looping Raw Data" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 855 Left = 6960 TabIndex = 46 Top = 6960 Width = 2895 Begin VB.Label Label12 Caption = "None" Height = 255 Left = 240 TabIndex = 61 Top = 480 Width = 2415 End Begin VB.Label Label25 Caption = "None" Height = 255 Left = 240 TabIndex = 47 Top = 240 Width = 2535 End End Begin VB.CommandButton stop_loop BackColor = &H000000FF& Caption = "STOP LOOP" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 555 Left = 6960 MaskColor = &H000000FF& Style = 1 'Graphical TabIndex = 44 Top = 7920 Width = 2895 End Begin VB.Frame Frame5 Caption = "Program Status" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2295 Left = 120 TabIndex = 23 Top = 6240 Width = 6735 Begin VB.Line Line3 BorderWidth = 2 X1 = 3960 X2 = 3960 Y1 = 240 Y2 = 2160 End Begin VB.Line Line2 BorderWidth = 2 X1 = 0 X2 = 3960 Y1 = 1080 Y2 = 1080 End Begin VB.Line Line1 BorderWidth = 2 X1 = 2040 X2 = 2040 Y1 = 240 Y2 = 2160 End Begin VB.Shape MM_Status BorderColor = &H00000000& FillColor = &H000000FF& FillStyle = 0 'Solid Height = 495 Left = 3000 Shape = 3 'Circle Top = 360 Width = 855 End Begin VB.Shape tracking_Status FillColor = &H000000FF& FillStyle = 0 'Solid Height = 495 Left = 1200 Shape = 3 'Circle Top = 1320 Width = 855 End Begin VB.Label Label22 Caption = "Tracking Status" Height = 255 Left = 120 TabIndex = 37 Top = 1440 Width = 1215 End Begin VB.Label Label1 Alignment = 2 'Center Caption = "Program Messages (status)" Height = 255 Left = 4080 TabIndex = 26 Top = 120 Width = 2415 End Begin VB.Shape Command_Status BorderColor = &H00000000& FillColor = &H000000FF& FillStyle = 0 'Solid Height = 495 Left = 1200 Shape = 3 'Circle Top = 360 Width = 855 End Begin VB.Label Frame_Status BorderStyle = 1 'Fixed Single Height = 1815 Left = 4080 TabIndex = 24 Top = 360 Width = 2415 End Begin VB.Label Label4 Caption = "Program Status" Height = 255 Left = 120 TabIndex = 25 Top = 480 Width = 1095 End Begin VB.Label Label23 Caption = "MiddleMass Status" Height = 375 Left = 2280 TabIndex = 42 Top = 360 Width = 975 End Begin VB.Shape looping_status BorderColor = &H00000000& FillColor = &H000000FF& FillStyle = 0 'Solid Height = 495 Left = 3000 Shape = 3 'Circle Top = 1320 Width = 855 End Begin VB.Label Label24 Caption = "Looping Input" Height = 375 Left = 2400 TabIndex = 43 Top = 1320 Width = 855 End End Begin VB.Frame Frame8 Caption = "Middle Mass (centroids)" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 975 Left = 6960 TabIndex = 38 Top = 120 Width = 2895 Begin VB.CommandButton command_middle_mass_on_servo_to Caption = "MM With Servo" Height = 615 Left = 2040 TabIndex = 41 Top = 240 Width = 735 End Begin VB.CommandButton command_middle_mass_on Caption = "MM on" Height = 615 Left = 1080 TabIndex = 40 Top = 240 Width = 735 End Begin VB.CommandButton command_middle_mass_off Caption = "MM off" Height = 615 Left = 120 TabIndex = 39 Top = 240 Width = 735 End End Begin VB.Frame Frame7 Caption = "Commands" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1455 Left = 6960 TabIndex = 30 Top = 3960 Width = 2895 Begin VB.CommandButton Command3 BackColor = &H0000FF00& Caption = "Line Mood" Height = 495 Left = 120 Style = 1 'Graphical TabIndex = 67 Top = 840 Width = 1335 End Begin VB.CommandButton Command5 BackColor = &H0000FF00& Caption = "Track Center Object" Height = 495 Left = 120 Style = 1 'Graphical TabIndex = 45 Top = 240 Width = 1335 End Begin VB.CommandButton Command2 Caption = "Ping Camera" Height = 255 Left = 1560 TabIndex = 33 Top = 240 Width = 1215 End Begin VB.CommandButton Command1 BackColor = &H0000FFFF& Caption = "Dump Frame" Height = 255 Left = 1560 MaskColor = &H0000FFFF& Style = 1 'Graphical TabIndex = 32 Top = 960 Width = 1215 End Begin VB.CommandButton Command4 Caption = "Reset Board" Height = 255 Left = 1560 TabIndex = 31 Top = 600 Width = 1215 End End Begin VB.Frame Frame4 Caption = "Serial Output" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 3015 Left = 120 TabIndex = 21 Top = 120 Width = 6735 Begin RichTextLib.RichTextBox Output Height = 2655 Left = 120 TabIndex = 22 Top = 240 Width = 6495 _ExtentX = 11456 _ExtentY = 4683 _Version = 393217 ReadOnly = -1 'True ScrollBars = 2 TextRTF = $"vidcap test.frx":0082 End End Begin VB.Frame Frame3 Caption = "Serial Input" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2895 Left = 120 TabIndex = 19 Top = 3240 Width = 6735 Begin RichTextLib.RichTextBox Ser_In Height = 2535 Left = 120 TabIndex = 20 Top = 240 Width = 6495 _ExtentX = 11456 _ExtentY = 4471 _Version = 393217 ReadOnly = -1 'True ScrollBars = 2 TextRTF = $"vidcap test.frx":0104 End End Begin VB.Frame Frame2 Caption = "Image Dump" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 3375 Left = 9960 TabIndex = 17 Top = 120 Width = 3015 Begin MSComctlLib.Slider tolerance_slider Height = 255 Left = 120 TabIndex = 70 Top = 3000 Width = 2775 _ExtentX = 4895 _ExtentY = 450 _Version = 393216 LargeChange = 4 Min = 3 Max = 35 SelStart = 8 Value = 8 End Begin VB.PictureBox PIC Height = 2175 Left = 240 ScaleHeight = 132.019 ScaleMode = 0 'User ScaleWidth = 150.414 TabIndex = 18 Top = 240 Width = 2535 End Begin VB.Label Robo_Size Caption = "0" Height = 255 Left = 1680 TabIndex = 60 Top = 2760 Width = 855 End Begin VB.Label Label10 Caption = "Base Size of Object:" Height = 255 Left = 120 TabIndex = 59 Top = 2760 Width = 1575 End Begin VB.Label Label9 Caption = "0" Height = 255 Left = 1440 TabIndex = 58 Top = 2520 Width = 1335 End Begin VB.Label Label8 Caption = "Distance Guess:" Height = 255 Left = 120 TabIndex = 57 Top = 2520 Width = 1215 End End Begin VB.Frame Frame1 Caption = "Color Modes" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1335 Left = 6960 TabIndex = 12 Top = 5520 Width = 2895 Begin VB.OptionButton YcrCb_on Caption = "YCrCb White Balance On" Height = 255 Left = 360 TabIndex = 16 Top = 240 Width = 2295 End Begin VB.OptionButton YcrCb_off Caption = "YCrCb White Balance Off" Height = 255 Left = 360 TabIndex = 15 Top = 480 Width = 2295 End Begin VB.OptionButton RGB_ON Caption = "RGB White Balance On" Height = 255 Left = 360 TabIndex = 14 Top = 720 Width = 2295 End Begin VB.OptionButton RGB_OFF Caption = "RGB White Balance Off" Height = 255 Left = 360 TabIndex = 13 Top = 960 Width = 2295 End End Begin MSCommLib.MSComm COM Left = 3480 Top = 1560 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DTREnable = 0 'False BaudRate = 115200 End Begin VB.Frame Registers_Frame Caption = "Registers" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2655 Left = 6960 TabIndex = 0 Top = 1200 Width = 2895 Begin VB.ComboBox HM_Combo Height = 315 Left = 1200 TabIndex = 34 Text = "0" Top = 1680 Width = 975 End Begin VB.ComboBox Combo_FPS Height = 315 Left = 1200 TabIndex = 28 Text = "17" Top = 1320 Width = 975 End Begin VB.CommandButton Reset_regs Caption = "Reset Registers" Height = 495 Left = 1440 TabIndex = 11 Top = 2040 Width = 1215 End Begin VB.ComboBox noise_combo Height = 315 Left = 1200 TabIndex = 10 Text = "0" Top = 960 Width = 975 End Begin VB.ComboBox brightness_combo Height = 315 Left = 1200 TabIndex = 9 Text = "0" Top = 600 Width = 975 End Begin VB.ComboBox contrast_combo Height = 315 Left = 1200 TabIndex = 8 Text = "0" Top = 240 Width = 975 End Begin VB.CommandButton Reg_Update Caption = "Update Registers" Height = 495 Left = 120 TabIndex = 3 Top = 2040 Width = 1215 End Begin VB.Label Label21 Caption = "HM Mode" Height = 255 Left = 120 TabIndex = 36 Top = 1680 Width = 975 End Begin VB.Label Label3 Caption = "0-off" Height = 255 Left = 2280 TabIndex = 35 Top = 1680 Width = 495 End Begin VB.Label Label16 Caption = "FPS" Height = 255 Left = 2280 TabIndex = 29 Top = 1320 Width = 495 End Begin VB.Label Label2 Caption = "Clock Speed" Height = 255 Left = 120 TabIndex = 27 Top = 1320 Width = 975 End Begin VB.Label Label15 Caption = "0-off" Height = 255 Left = 2280 TabIndex = 7 Top = 960 Width = 495 End Begin VB.Label Label14 Caption = "0 - 255" Height = 255 Left = 2280 TabIndex = 6 Top = 600 Width = 495 End Begin VB.Label Label13 Caption = "0 - 255" Height = 255 Left = 2280 TabIndex = 5 Top = 240 Width = 495 End Begin VB.Label Label7 Caption = "Noise Filter" Height = 255 Left = 120 TabIndex = 4 Top = 960 Width = 975 End Begin VB.Label Label6 Caption = "Brightness" Height = 255 Left = 120 TabIndex = 2 Top = 600 Width = 735 End Begin VB.Label Label5 Caption = "Contrast" Height = 255 Left = 120 TabIndex = 1 Top = 240 Width = 735 End End Begin MSCommLib.MSComm Comm Left = 0 Top = 0 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DTREnable = -1 'True End End
Attribute VB_Name = "Form1" Table of Contents Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False '************************************************************************ '********************************************************* '****************************************** ' Created By: Michael Konicki ' Date: 4/19/2006 (last edit) ' 'The project no uses constant motion which means that the program 'no longer tries to do an action and then stop that action and get 'input to do the next action. Now all that happens is the program determines 'what action is needed and does that action until a different actions is required 'so if the program says move forward the robot does that until the program says 'to do something else. This eliminates all the bottleneck issues in dealing 'with the comport and sleep ' ' To Use: certain rules must be obeyed. ' 1. You cant lift the object to follow over or below the field ' of view of the CMUcam. It has no servo to control up and down ' movement of the camera ' 2. The cmucam and robot obviously can't move as fast as a ' person moving and object, while fast it isnt that fast ' be gentle with her when doing movements '****************************************** '********************************************************* '************************************************************************ Option Explicit Dim Stop_Looping As Boolean 'Used to Signify and end to data looping Dim Object_size As Integer 'Size of the object Dim Avg_Pos As Integer 'the position of the object according to cmucam Dim userlock As Boolean 'Prevents the sending of commands if the user sends a command to the robot using the joystick Dim First_Run As Boolean 'First run of loop trackin g Dim BusY As Boolean 'used as a lock on some code that shouldnt be run Dim moving As Boolean 'Are we moving Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '************************************************************************ '********************************************************* '****************************************** ' CUSTOM FUNCTIONS (SENDCOMMAND, MOVE SERVO) '****************************************** '********************************************************* '************************************************************************
Private Function SendCommand(cmd As String, sleeptime As Integer) As String Table of Contents '********************************************** ' Sends a command to the board then checks for ' the ack command '********************************************** Dim RcvBytes As String 'Stores bytes from the input buffer Dim CheckBytes As String 'used to check for an ack meaning good command Dim temp As String 'dump unused input buffer into here Dim start_time As Integer Dim cur_time As Integer On Error GoTo err1 'Set the status flag to yellow Command_Status.FillColor = RGB(255, 255, 0) Frame_Status.Caption = "Talking with CMUcam..." Me.Refresh 'Send data out on serial port and clear the input textbox Ser_In.Text = Ser_In.Text & "-----------------------------" & vbCrLf If cmd = "" Then Output.Text = Output.Text & "Sending Command: \r" & vbCrLf Else Output.Text = Output.Text & "Sending Command: " & cmd & vbCrLf End If 'Send the actual command to the CMUcam COM.Output = cmd & Chr(13) 'Do loop to rip the data out of the com.input buffer if it is a DF 'the other commands are all smaller then 8 chars, no need to loop actually is slower If cmd = "DF" Then Do DoEvents RcvBytes = RcvBytes & COM.Input Sleep (50) Loop Until COM.InBufferCount <= 0 Else Sleep (sleeptime) RcvBytes = COM.Input End If 'Check for ack or nck or somethign else (which is bad) CheckBytes = Left(RcvBytes, 3) If CheckBytes = "ACK" Then 'found an ack Command_Status.FillColor = RGB(0, 255, 0) 'Display the command in the history If cmd = "" Then Ser_In.Text = Ser_In.Text & "ACK: \r" & cmd & vbCrLf Else Ser_In.Text = Ser_In.Text & "ACK: " & cmd & vbCrLf End If 'Return the info SendCommand = RcvBytes 'Didnt get and ACK from CMUcam Else 'got a nck (error) Command_Status.FillColor = RGB(255, 0, 0) 'Display command in window If cmd = "" Then Ser_In.Text = Ser_In.Text & "NCK: \r" & cmd & vbCrLf Else Ser_In.Text = Ser_In.Text & "NCK: " & cmd & vbCrLf End If 'Return -1 = error SendCommand = "-1" 'send error back to caller End If 'Turn off error handeling and exit function before getting to the error On Error GoTo 0 Exit Function err1: MsgBox "Fatal Error(1): Error Sending To CMUcam", vbCritical, "FATAL ERROR" End Function
Private Sub Move_Servo(command As String, from As String) Table of Contents '*********************************************************** ' Controls all the data going to the servo board '*********************************************************** Dim ret As String If from = 0 Then 'came from user click so its ok to send whenever 'Send the command to the robot to do whatever built in movement is required Comm.Output = "11" + " " + command + " " + " " + "0" + " " + "22" + " " Sleep (60) ElseIf from = 1 Then 'came from program control we want to check it to make sure controls arent locked down If userlock = False Then Do Loop Until moving = False moving = True 'Send the command to the robot to do whatever built in movement is required Comm.Output = "11" + " " + command + " " + " " + "0" + " " + "22" + " " Sleep (80) ret = Comm.Input 'do nothing everything worked moving = False End If End If End Sub
Private Sub HandlePacket(InputString As String) Table of Contents '****************************************** ' One fucntion that handles all of the other ' packet processing features. And robot following ' for all the packet recieving functiosn '****************************************** Dim ret As String 'return strign from sendcommand Dim mark As Integer 'mark for ripping up packet Dim WhatPacket As String 'Whatpacket are we on Dim Mx As String, My As String 'centroid coordinates Dim X1 As String, Y1 As String, X2 As String, Y2 As String 'box coordinates Dim PixCnt As String, ObjConf As String 'Pixcount and object confidence Dim spos As String 'servo position Dim spinner As Boolean 'tell us if we are spinning Dim cur_size As Integer Dim Pic_Mid As Integer 'middle of the picture (central spot on x plane) Dim Cur_Mid As Integer 'current middle of the object according to CMUCam Dim Cur_Direction As String 'what direction the robot is going 'Need to be able to handle both C & M packets here, 'will send either or depending on the settings the use selected WhatPacket = Left(InputString, 1) If WhatPacket = "M" Then If Right(InputString, 1) = Chr(13) Then 'Find the M and drop them mark = InStr(1, InputString, " ") InputString = Right(InputString, Len(InputString) - mark) 'Get the MMx out mark = InStr(1, InputString, " ") Mx = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the MMy out mark = InStr(1, InputString, " ") My = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the x1 out mark = InStr(1, InputString, " ") X1 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the y1 out mark = InStr(1, InputString, " ") Y1 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the x2 out mark = InStr(1, InputString, " ") X2 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the y2 out mark = InStr(1, InputString, " ") Y2 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the pixcnt out mark = InStr(1, InputString, " ") PixCnt = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the Bdev out mark = InStr(1, InputString, "M") If mark = 0 Then mark = 1 End If ObjConf = Mid(InputString, 1, 2) If ObjConf = "" Or ObjConf = " " Then ObjConf = InputString End If 'display the data we got to the user Label25 = "M: " & Mx & My & X1 & Y1 & X2 & Y2 & PixCnt & ObjConf If First_Run = True Then Object_size = (X1 - X2) * (Y1 - Y2) First_Run = False Robo_Size.Caption = Object_size Else cur_size = (X1 - X2) * (Y1 - Y2) Label9.Caption = cur_size End If 'Clear the picture out PIC.Cls Pic_Mid = PIC.ScaleWidth / 2 Robo_Size.Caption = Object_size 'Determine the Robot Direction and move it thusly 'first check objectconfidence to see if it is our object according to the cmucam If ObjConf > tolerance_slider.Value Then '( <10 horrible, >50 amazing, well settle for inbetween) PIC.BackColor = RGB(0, 255, 0) 'Handle movement side to side now If Mx * 2 > Pic_Mid + 42 Then 'go right 'if we are going backwards we have to backup the other way If Cur_Direction = "r" Then GoTo end_jump 'no need to resend the command End If Cur_Direction = "r" Call Move_Servo(6, 1) spinner = True DIR.Text = DIR.Text & "Moving Right" & vbCrLf GoTo end_jump ElseIf Mx * 2 < Pic_Mid - 42 Then 'go left If Cur_Direction = "l" Then GoTo end_jump 'no need to resend the command End If Call Move_Servo(7, 1) Cur_Direction = "l" spinner = True DIR.Text = DIR.Text & "Moving Left" & vbCrLf GoTo end_jump End If 'Move forward and backwards If Object_size > cur_size + 1000 Then If spinner = True Then Call Move_Servo(0, 1) 'stop them as well spinner = False End If Cur_Direction = "f" Call Move_Servo(1, 1) 'forward DIR.Text = DIR.Text & "Moving Forward" & vbCrLf ElseIf Object_size < cur_size - 1000 Then If spinner = True Then Call Move_Servo(0, 1) 'center the wheels after a 360 spinner = False End If Cur_Direction = "b" Call Move_Servo(3, 1) 'GO BACKWARDS DIR.Text = DIR.Text & "Moving Backwards" & vbCrLf Else DIR.Text = DIR.Text & "Stoping" & vbCrLf Call Move_Servo(0, 1) 'STOP THE ROBOT Cur_Direction = "-1" End If Else 'Bad packet so we should stop the robot in case 'the object is really lost Call Move_Servo(0, 1) PIC.BackColor = RGB(255, 0, 0) End If 'Draw the middle mass coordinates PIC.Circle (Mx * 2, My), 5, RGB(0, 0, 255) 'Draw the box that shows where the object is PIC.Line (X1 * 2, Y1)-(X2 * 2, Y1), RGB(255, 0, 0) PIC.Line (X2 * 2, Y1)-(X2 * 2, Y2), RGB(255, 0, 0) PIC.Line (X2 * 2, Y2)-(X1 * 2, Y2), RGB(255, 0, 0) PIC.Line (X1 * 2, Y2)-(X1 * 2, Y1), RGB(255, 0, 0) Frame_Status.Caption = "Recieving Loop..." & vbCrLf & vbCrLf Frame_Status.Caption = Frame_Status.Caption & "Pixels in Box: " & PixCnt & vbCrLf & "Confidence: " & ObjConf Frame_Status.Caption = Frame_Status.Caption & vbCrLf & "Numbers Cap at 255" End If 'same as above for a C packet (slgihtly different) ElseIf WhatPacket = "C" Then If Right(InputString, 1) = Chr(13) Then 'Find the M and drop them mark = InStr(1, InputString, " ") InputString = Right(InputString, Len(InputString) - mark) 'Get the x1 out mark = InStr(1, InputString, " ") X1 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the y1 out mark = InStr(1, InputString, " ") Y1 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString) - mark) 'Get the x2 out mark = InStr(1, InputString, " ") X2 = Mid(InputString, 1, mark) InputString = Right(InputString, Len(InputString