Form1

M:\Mike (latest)\Stub Programs\Advanced Joystick - doneprinter\vidcap test.frm
File saved: 4/30/2006 2:24:06 PM
Generated: 4/30/2006 4:51:50 PM

Table of Contents
(Designer Object Definition)
Declarations
SendCommand
HandlePacket
pollme
GetBinary
Form_Activate
Form_Unload
Build_Combos
Form_Load
Lock_Buttons
Restore_Buttons
TrackCenter_BU_Click
DumpFrame_BU_Click
Joystick_BU_Click
button_auto_tracking_Click
command_middle_mass_on_servo_to_Click
command_middle_mass_off_Click
command_middle_mass_on_Click
button_disable_tracking_Click
ping_bu_Click
version_bu_Click
reset_bu_Click
Mean_Color_value_Click
menu_exit_Click
menu_joystick_Click
poll_mode_Click
Reg_Update_Click
Reset_regs_Click
Restore_window_size_Click
RGB_OFF_Click
RGB_ON_Click
Ser_In_Change
Set_window_Size_Click
set_servo_Click
Start_Tracking_Click
stop_loop_Click
YcrCb_off_Click
YcrCb_on_Click
menu_autotracking_Click
menu_crcboff_Click
menu_crcbon_Click
menu_dumpframe_Click
menu_enabletracking_Click
menu_firmversion_Click
menu_getmean_Click
menu_mmoff_Click
menu_mmon_Click
menu_mmonservo_Click
menu_ping_Click
menu_resboard_Click
menu_resetregs_Click
menu_restorewindow_Click
menu_rgboff_Click
menu_rgbon_Click
menu_line_Click
menu_setservopos_Click
menu_setwinsowsize_Click
menu_trackcenterobject_Click
menu_updatreregs_Click
menu_disabletracking_Click
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" Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Form1" ClientHeight = 8565 ClientLeft = -135 ClientTop = 1575 ClientWidth = 13170 LinkTopic = "Form1" MaxButton = 0 'False ScaleHeight = 571 ScaleMode = 3 'Pixel ScaleWidth = 878 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 = 10080 TabIndex = 84 Top = 2880 Width = 3015 Begin VB.PictureBox pic_hi Height = 1455 Left = 840 ScaleHeight = 1395 ScaleWidth = 1155 TabIndex = 85 Top = 360 Width = 1215 End End Begin VB.Frame Frame10 Caption = "Servo 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 = 855 Left = 7080 TabIndex = 76 Top = 7680 Width = 2895 Begin VB.CommandButton set_servo Caption = "Set" Height = 255 Left = 720 TabIndex = 79 Top = 480 Width = 615 End Begin VB.TextBox new_servo_pos Height = 285 Left = 120 TabIndex = 78 Top = 480 Width = 495 End Begin VB.Label Servo_Pos Caption = "N/A" Height = 255 Left = 1920 TabIndex = 81 Top = 480 Width = 375 End Begin VB.Label Label27 Caption = "Last Reported Pos" Height = 255 Left = 1440 TabIndex = 80 Top = 240 Width = 1335 End Begin VB.Label Label26 Caption = "Set Servo Pos" Height = 255 Left = 120 TabIndex = 77 Top = 240 Width = 1095 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 = 735 Left = 240 TabIndex = 74 Top = 7800 Width = 2895 Begin VB.Label Label25 Caption = "None" Height = 255 Left = 240 TabIndex = 75 Top = 360 Width = 2415 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 = 495 Left = 3360 MaskColor = &H000000FF& Style = 1 'Graphical TabIndex = 72 Top = 7920 Width = 3495 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 = 36 Top = 5400 Width = 6735 Begin VB.CommandButton Joystick_BU BackColor = &H0000FFFF& Caption = "Launch Joystick" Height = 375 Left = 4320 Style = 1 'Graphical TabIndex = 82 Top = 1800 Width = 2055 End 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 = 65 Top = 1440 Width = 1215 End Begin VB.Label Label1 Alignment = 2 'Center Caption = "Program Messages (status)" Height = 255 Left = 4080 TabIndex = 39 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 = 1335 Left = 4080 TabIndex = 37 Top = 360 Width = 2415 End Begin VB.Label Label4 Caption = "Program Status" Height = 255 Left = 120 TabIndex = 38 Top = 480 Width = 1095 End Begin VB.Label Label23 Caption = "MiddleMass Status" Height = 375 Left = 2280 TabIndex = 70 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 = 71 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 = 7080 TabIndex = 66 Top = 2400 Width = 2895 Begin VB.CommandButton command_middle_mass_on_servo_to Caption = "MM With Servo" Height = 615 Left = 2040 TabIndex = 69 Top = 240 Width = 735 End Begin VB.CommandButton command_middle_mass_on Caption = "MM on" Height = 615 Left = 1080 TabIndex = 68 Top = 240 Width = 735 End Begin VB.CommandButton command_middle_mass_off Caption = "MM off" Height = 615 Left = 120 TabIndex = 67 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 = 2175 Left = 10080 TabIndex = 54 Top = 6360 Width = 3015 Begin VB.CommandButton poll_mode BackColor = &H0000C000& Caption = "Line Mode" Height = 495 Left = 120 Style = 1 'Graphical TabIndex = 83 Top = 240 Width = 1215 End Begin VB.CommandButton TrackCenter_BU BackColor = &H0000C000& Caption = "Track Center Object" Height = 495 Left = 120 Style = 1 'Graphical TabIndex = 73 Top = 840 Width = 1215 End Begin VB.CommandButton Mean_Color_value Caption = "Mean Color Value" Height = 495 Left = 120 TabIndex = 59 Top = 1440 Width = 1215 End Begin VB.CommandButton ping_bu Caption = "Ping Camera" Height = 375 Left = 1680 TabIndex = 58 Top = 720 Width = 1215 End Begin VB.CommandButton DumpFrame_BU Caption = "Dump Frame" Height = 375 Left = 1680 TabIndex = 57 Top = 1680 Width = 1215 End Begin VB.CommandButton reset_bu Caption = "Reset Board" Height = 375 Left = 1680 TabIndex = 56 Top = 240 Width = 1215 End Begin VB.CommandButton version_bu Caption = "Version" Height = 375 Left = 1680 TabIndex = 55 Top = 1200 Width = 1215 End End Begin VB.Frame Frame6 Caption = "Adjust Window Size" 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 = 7080 TabIndex = 43 Top = 6240 Width = 2895 Begin VB.CommandButton Restore_window_size Caption = "Restore Window" Height = 495 Left = 1560 TabIndex = 53 Top = 720 Width = 1215 End Begin VB.CommandButton Set_window_Size Caption = "Set Window" Height = 375 Left = 1560 TabIndex = 52 Top = 240 Width = 1215 End Begin VB.TextBox windowsize_y1 Height = 375 Left = 1080 TabIndex = 47 Text = "1" Top = 360 Width = 375 End Begin VB.TextBox windowsize_x2 Height = 375 Left = 360 TabIndex = 46 Text = "80" Top = 840 Width = 375 End Begin VB.TextBox windowsize_y2 Height = 375 Left = 1080 TabIndex = 45 Text = "143" Top = 840 Width = 375 End Begin VB.TextBox windowsize_x1 Height = 375 Left = 360 TabIndex = 44 Text = "1" Top = 360 Width = 375 End Begin VB.Label Label20 Caption = "Y2" Height = 255 Left = 840 TabIndex = 51 Top = 960 Width = 255 End Begin VB.Label Label18 Caption = "Y1" Height = 255 Left = 840 TabIndex = 50 Top = 480 Width = 255 End Begin VB.Label Label19 Caption = "X2" Height = 255 Left = 120 TabIndex = 49 Top = 960 Width = 255 End Begin VB.Label Label17 Caption = "X1" Height = 255 Left = 120 TabIndex = 48 Top = 480 Width = 255 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 = 2535 Left = 120 TabIndex = 34 Top = 120 Width = 6735 Begin RichTextLib.RichTextBox Output Height = 2175 Left = 120 TabIndex = 35 Top = 240 Width = 6495 _ExtentX = 11456 _ExtentY = 3836 _Version = 393217 Enabled = -1 'True ScrollBars = 2 TextRTF = $"vidcap test.frx":0000 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 = 2535 Left = 120 TabIndex = 32 Top = 2760 Width = 6735 Begin RichTextLib.RichTextBox Ser_In Height = 2175 Left = 120 TabIndex = 33 Top = 240 Width = 6495 _ExtentX = 11456 _ExtentY = 3836 _Version = 393217 Enabled = -1 'True ScrollBars = 2 TextRTF = $"vidcap test.frx":0082 End End Begin VB.Frame Frame2 Caption = "Image Dump\Tracking 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 = 2775 Left = 10080 TabIndex = 30 Top = 120 Width = 3015 Begin VB.PictureBox PIC Height = 2415 Left = 120 ScaleHeight = 147 ScaleMode = 0 'User ScaleWidth = 165 TabIndex = 31 Top = 240 Width = 2775 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 = 10080 TabIndex = 25 Top = 4920 Width = 3015 Begin VB.OptionButton YcrCb_on Caption = "YCrCb White Balance On" Height = 255 Left = 360 TabIndex = 29 Top = 240 Width = 2295 End Begin VB.OptionButton YcrCb_off Caption = "YCrCb White Balance Off" Height = 255 Left = 360 TabIndex = 28 Top = 480 Width = 2295 End Begin VB.OptionButton RGB_ON Caption = "RGB White Balance On" Height = 255 Left = 360 TabIndex = 27 Top = 720 Width = 2295 End Begin VB.OptionButton RGB_OFF Caption = "RGB White Balance Off" Height = 255 Left = 360 TabIndex = 26 Top = 960 Width = 2295 End End Begin VB.Frame Color_Track Caption = "Color Tracker" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2175 Left = 7080 TabIndex = 5 Top = 120 Width = 2895 Begin VB.CommandButton button_auto_tracking Caption = "Auto Tracking" Height = 495 Left = 120 TabIndex = 64 Top = 1560 Width = 855 End Begin VB.CommandButton button_disable_tracking Caption = "TrackingOff" Height = 495 Left = 1080 TabIndex = 63 Top = 1560 Width = 855 End Begin VB.CommandButton Start_Tracking Caption = "Track Color" Height = 495 Left = 2040 TabIndex = 17 Top = 1560 Width = 735 End Begin VB.TextBox U_B Height = 375 Left = 2160 TabIndex = 11 Text = "0" Top = 960 Width = 375 End Begin VB.TextBox L_B Height = 375 Left = 2160 TabIndex = 10 Text = "0" Top = 480 Width = 375 End Begin VB.TextBox U_G Height = 375 Left = 1680 TabIndex = 9 Text = "0" Top = 960 Width = 375 End Begin VB.TextBox L_G Height = 375 Left = 1680 TabIndex = 8 Text = "0" Top = 480 Width = 375 End Begin VB.TextBox U_R Height = 375 Left = 1200 TabIndex = 7 Text = "0" Top = 960 Width = 375 End Begin VB.TextBox L_R Height = 375 Left = 1200 TabIndex = 6 Text = "0" Top = 480 Width = 375 End Begin VB.Label Label12 Caption = "Upper Bound" Height = 255 Left = 120 TabIndex = 16 Top = 1080 Width = 1095 End Begin VB.Label Label11 Caption = "Lower Bound" Height = 255 Left = 120 TabIndex = 15 Top = 600 Width = 1095 End Begin VB.Label Label10 Alignment = 2 'Center Caption = "B" Height = 255 Left = 2160 TabIndex = 14 Top = 240 Width = 375 End Begin VB.Label Label9 Alignment = 2 'Center Caption = "G" Height = 255 Left = 1680 TabIndex = 13 Top = 240 Width = 375 End Begin VB.Label Label8 Alignment = 2 'Center Caption = "R" Height = 255 Left = 1200 TabIndex = 12 Top = 240 Width = 375 End End Begin MSCommLib.MSComm COM Left = 120 Top = 7680 _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 = 7080 TabIndex = 0 Top = 3480 Width = 2895 Begin VB.ComboBox HM_Combo Height = 315 Left = 1200 TabIndex = 60 Text = "0" Top = 1680 Width = 975 End Begin VB.ComboBox Combo_FPS Height = 315 Left = 1200 TabIndex = 41 Text = "17" Top = 1320 Width = 975 End Begin VB.CommandButton Reset_regs Caption = "Reset Registers" Height = 495 Left = 1440 TabIndex = 24 Top = 2040 Width = 1215 End Begin VB.ComboBox noise_combo Height = 315 Left = 1200 TabIndex = 23 Text = "0" Top = 960 Width = 975 End Begin VB.ComboBox brightness_combo Height = 315 Left = 1200 TabIndex = 22 Text = "0" Top = 600 Width = 975 End Begin VB.ComboBox contrast_combo Height = 315 Left = 1200 TabIndex = 21 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 = 62 Top = 1680 Width = 975 End Begin VB.Label Label3 Caption = "0-off" Height = 255 Left = 2280 TabIndex = 61 Top = 1680 Width = 495 End Begin VB.Label Label16 Caption = "FPS" Height = 255 Left = 2280 TabIndex = 42 Top = 1320 Width = 495 End Begin VB.Label Label2 Caption = "Clock Speed" Height = 255 Left = 120 TabIndex = 40 Top = 1320 Width = 975 End Begin VB.Label Label15 Caption = "0-off" Height = 255 Left = 2280 TabIndex = 20 Top = 960 Width = 495 End Begin VB.Label Label14 Caption = "0 - 255" Height = 255 Left = 2280 TabIndex = 19 Top = 600 Width = 495 End Begin VB.Label Label13 Caption = "0 - 255" Height = 255 Left = 2280 TabIndex = 18 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 VB.Menu menu_file Caption = "File" Begin VB.Menu menu_joystick Caption = "Lauch Joystick" End Begin VB.Menu menu_help Caption = "Help" End Begin VB.Menu space Caption = "-" End Begin VB.Menu menu_exit Caption = "Exit" End End Begin VB.Menu menu_colortracker Caption = "Color Tracker" Begin VB.Menu menu_autotracking Caption = "Auto Tracking" End Begin VB.Menu menu_disabletracking Caption = "Disable Tracking" End Begin VB.Menu menu_enabletracking Caption = "Track Color" End Begin VB.Menu menu_userdefined_color Caption = "User Definied Color" End End Begin VB.Menu mne_middlemass Caption = "Middle Mass (Centroids)" Begin VB.Menu menu_mmon Caption = "Middle Mass Mode ON" End Begin VB.Menu menu_mmoff Caption = "Middle Mass Mode Off" End Begin VB.Menu menu_mmonservo Caption = "Middel Mass Mode ON(with servo)" End End Begin VB.Menu menu_registers Caption = "Registers" Begin VB.Menu menu_updatreregs Caption = "Update Registers" End Begin VB.Menu menu_resetregs Caption = "Reset Registers" End End Begin VB.Menu menu_capsize Caption = "Cpature Size" Begin VB.Menu menu_setwinsowsize Caption = "Set New Window Size" End Begin VB.Menu menu_restorewindow Caption = "Restore Window Size" End End Begin VB.Menu menu_colormodes Caption = "Color Modes" Begin VB.Menu menu_crcbon Caption = "CrYCb White Balance On" End Begin VB.Menu menu_crcboff Caption = "CrYCb White Balance Off" End Begin VB.Menu menu_rgbon Caption = "RGB White Balance On" End Begin VB.Menu menu_rgboff Caption = "RGB White Balance Off" End End Begin VB.Menu menu_gencommands Caption = "Generic Commands" Begin VB.Menu menu_firmversion Caption = "Get Firmware Version" End Begin VB.Menu menu_resboard Caption = "Reset Board" End Begin VB.Menu menu_ping Caption = "Ping Camera" End Begin VB.Menu menu_dumpframe Caption = "Dump Frame" End Begin VB.Menu menu_line Caption = "Line Mode Tracking" End Begin VB.Menu menu_getmean Caption = "Get Mean Color Data" End Begin VB.Menu menu_trackcenterobject Caption = "Track Centered Object" End End Begin VB.Menu menu_servocontrols Caption = "Servo Controls" Begin VB.Menu menu_setservopos Caption = "Set New Servo Pos" End 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 ' ' ' This program contains all the functions and abilities of the CMUCam. It also has a seperate ' form that is launchable to control the airens robot if the user wanted to do so. ' ' '****************************************** '********************************************************* '************************************************************************ Option Explicit Dim Stop_Looping As Boolean 'Used to Signify and end to data looping Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '************************************************************************ '********************************************************* '****************************************** ' CUSTOM FUNCTIONS (SENDCOMMAND) '****************************************** '********************************************************* '************************************************************************
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) 'Clean out the input buffer before getting new data 'COM.InBufferCount = 0 '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 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 Dim mark As Integer Dim WhatPacket As String Dim Mx As String, My As String Dim X1 As String, Y1 As String, X2 As String, Y2 As String Dim PixCnt As String, ObjConf As String Dim spos As String '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, mark - 1) If ObjConf = "" Or ObjConf = " " Then ObjConf = InputString End If Label25 = "M: " & Mx & My & X1 & Y1 & X2 & Y2 & PixCnt & ObjConf 'Clear the picture out PIC.Cls 'Draw the middle mass coordinates PIC.Circle (Mx, 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 = "Getting Packet Stream" End If 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) - 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, "C") If mark = 0 Then mark = 1 End If ObjConf = Mid(InputString, 1, mark - 1) If ObjConf = "" Or ObjConf = " " Then ObjConf = InputString End If Label25 = "C: " & X1 & Y1 & X2 & Y2 & PixCnt & ObjConf 'Clear the picture out PIC.Cls '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 = "Getting Packet Stream" End If ElseIf WhatPacket = "N" Then If Right(InputString, 1) = Chr(13) Then 'Find the N and drop them mark = InStr(1, InputString, " ") InputString = Right(InputString, Len(InputString) - mark) 'Get the spos out mark = InStr(1, InputString, " ") spos = Mid(InputString, 1, mark) 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, "N") If mark = 0 Then mark = 1 End If ObjConf = Mid(InputString, 1, mark - 1) If ObjConf = "" Or ObjConf = " " Then ObjConf = InputString End If Label25 = "N: " & spos & X1 & Y1 & X2 & Y2 & PixCnt & ObjConf 'Clear the picture out PIC.Cls '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 & vbCrLf & vbCrLf Servo_Pos.Caption = spos Frame_Status.Caption = Frame_Status.Caption & vbCrLf & "Numbers Cap at 255" End If Else 'do nothign bad packet Frame_Status.Caption = "Unknown/Bad Packet" End If End Sub
Private Sub pollme() Table of Contents '***************************************************** ' Process all of the incoming linemode data. That is the ' binary representation of what the CMUCam is tracking ' This also displays it to the user and sends the packet ' that comes with the image to handlepacket '***************************************************** Dim ret As String Dim str As String Dim num As String Dim s As String Dim binstr As String Dim temp As String Dim i As Integer Dim k As Integer Dim start1 As Integer Dim col As Long Dim row As Long Dim cnt As Long Dim startpos As Integer Dim packet As String 'Issue the command to get one packet out COM.Output = "TW" & Chr(13) Sleep (250) 'Read the packet in before processing Do str = str & COM.Input Sleep (75) Loop Until COM.InBufferCount >= 0 start1 = 0 col = 0 row = 0 cnt = 0 'PIC.Cls PIC.ScaleMode = vbPixels pic_hi.ScaleMode = vbPixels startpos = InStr(1, str, "ACK") If startpos = 0 Then Exit Sub End If For i = startpos To Len(str) - 1 temp = Mid(str, i, 1) s = GetBinary(Asc(temp)) If s = "10101010" Then start1 = start1 + 1 If cnt = 1 Then GoTo done 'ElseIf start1 > 1 Then ' GoTo badpacket End If cnt = 1 Else If start1 = 0 Then 'do nothing Else cnt = 0 For k = 1 To 9 - 1 temp = Mid(s, k, 1) If temp = 1 Then pic_hi.PSet (col, row), RGB(0, 0, 255) pic_hi.PSet (col, row + 1), RGB(0, 0, 255) Else pic_hi.PSet (col, row), RGB(0, 0, 0) pic_hi.PSet (col, row + 1), RGB(0, 0, 0) End If col = col + 1 If col = 80 Then col = 0 row = row + 2 End If Next k End If End If Next i done: 'Should process the packet data here If start1 = 3 Then 'do nothing good image Else 'hide it if we have a bad picture pic_hi.Cls End If packet = Mid(str, i + 1, Len(str) - i) packet = packet & Chr(13) HandlePacket (packet) 'Sleep (75) End Sub
Function GetBinary(ByVal iInput As Integer) As String Table of Contents '*************************************************** ' Returns the 8-bit binary representation ' of an integer iInput where 0 <= iInput <= 255 '*************************************************** Dim s As String, i As Integer 'Make sure we have good data coming in If iInput < 0 Or iInput > 255 Then GetBinary = "" Exit Function End If s = "" 'BUild the binary string For i = 1 To 8 s = CStr(iInput Mod 2) & s iInput = iInput \ 2 Next GetBinary = s End Function '************************************************************************ '********************************************************* '****************************************** ' FORM LOAD, UNLOAD, AND SETUP FUNCTIONS '****************************************** '********************************************************* '************************************************************************
Private Sub Form_Activate() Table of Contents '********************************************* ' Call ping to make sure the camera is up and ' running '********************************************* Sleep (100) 'sleep for a sec Call ping_bu_Click 'call the reset command Call RGB_ON_Click 'set the RGB white on mode to selected on the form End Sub
Private Sub Form_Unload(Cancel As Integer) Table of Contents 'Make sure there are no loops running If Stop_Looping = False Then Cancel = MsgBox("Please Stop All Packet Streams Before Closing", vbCritical, "Error Closing") Exit Sub End If shutdown: Me.BackColor = RGB(0, 0, 0) 'change background so user knows whats up Unload Joystick 'unload the other form COM.InBufferCount = 0 'clear the buffer COM.PortOpen = False 'close the port Sleep (2000) 'wait to make sure it died Unload Me End Sub
Private Function Build_Combos() Table of Contents '***************************************** ' Fill in some of the combo boxes '***************************************** Dim X As Integer 'Build the contrast box For X = 0 To 255 contrast_combo.AddItem str(X) Next X 'Build the brightness box For X = 0 To 255 brightness_combo.AddItem str(X) Next X 'Build the noise filter box noise_combo.AddItem str(0) noise_combo.AddItem str(1) 'Build the HM Mode box HM_Combo.AddItem str(0) HM_Combo.AddItem str(1) 'Build the FPS combo Combo_FPS.AddItem str(17) Combo_FPS.AddItem str(13) Combo_FPS.AddItem str(11) Combo_FPS.AddItem str(9) Combo_FPS.AddItem str(8) Combo_FPS.AddItem str(7) Combo_FPS.AddItem str(6) Combo_FPS.AddItem str(5) Combo_FPS.AddItem str(4) End Function
Private Sub Form_Load() Table of Contents On Error GoTo err1 stop_loop.Visible = False COM.CommPort = 1 'our comport holding the CMUcam COM.InBufferSize = 32764 'input buffer size COM.PortOpen = True 'open the port for communication 'Set up joystick form Joystick.Comm.CommPort = 3 Joystick.Comm.PortOpen = True 'build and fill all the combobox data for the registers Call Build_Combos Stop_Looping = True Exit Sub err1: MsgBox "Couldn't Resolve Robot or CMU device, Terminating Program", vbCritical Unload Me End Sub
Private Sub Lock_Buttons() Table of Contents '************************************ ' Locks all the buttons during ' looping input '************************************ Start_Tracking.Enabled = False button_auto_tracking.Enabled = False button_disable_tracking.Enabled = False command_middle_mass_off.Enabled = False command_middle_mass_on.Enabled = False command_middle_mass_on_servo_to.Enabled = False DumpFrame_BU.Enabled = False ping_bu.Enabled = False version_bu.Enabled = False reset_bu.Enabled = False TrackCenter_BU.Enabled = False Mean_Color_value.Enabled = False Reg_Update.Enabled = False Reset_regs.Enabled = False Set_window_Size.Enabled = False Restore_window_size.Enabled = False poll_mode.Enabled = False End Sub
Private Sub Restore_Buttons() Table of Contents '************************************ ' Restore all input '************************************ Start_Tracking.Enabled = True button_auto_tracking.Enabled = True button_disable_tracking.Enabled = True command_middle_mass_off.Enabled = True command_middle_mass_on.Enabled = True command_middle_mass_on_servo_to.Enabled = True DumpFrame_BU.Enabled = True ping_bu.Enabled = True version_bu.Enabled = True reset_bu.Enabled = True TrackCenter_BU.Enabled = True Mean_Color_value.Enabled = True Reg_Update.Enabled = True Reset_regs.Enabled = True Set_window_Size.Enabled = True Restore_window_size.Enabled = True poll_mode.Enabled = True End Sub '************************************************************************ '********************************************************* '****************************************** ' FORM CLICKS SECTION '****************************************** '********************************************************* '************************************************************************
Private Sub TrackCenter_BU_Click() Table of Contents '***************************************** ' track the object in the center of the ' cameras view '***************************************** Dim ret As String Dim InputString As String Dim mark As Integer Dim WhatPacket As String Dim Mx As String, My As String Dim X1 As String, Y1 As String, X2 As String, Y2 As String Dim PixCnt As String, ObjConf As String Dim spos As String ret = SendCommand("TW", 150) If ret = "-1" Then Frame_Status.Caption = "Couldn't Init Object Tracking Mode" Exit Sub Else Ser_In.Text = Ser_In.Text & "TC --> Object Tracking Mode Initialized" & vbCrLf tracking_Status.FillColor = RGB(0, 255, 0) End If 'Init variables for the data loop Stop_Looping = False stop_loop.Visible = True looping_status.FillColor = RGB(0, 255, 0) Call Lock_Buttons Do DoEvents 'without this bad things happen InputString = COM.Input '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) HandlePacket (InputString) Sleep (100) Loop Until Stop_Looping = True 'Shutdown loop Call Restore_Buttons 'Restore Buttons Upon Loop Termination Call reset_bu_Click 'call board reset stop_loop.Visible = False 'hide the stop loop End Sub
Private Sub DumpFrame_BU_Click() Table of Contents 'Send dumpframe command Dim ret As String Dim Left As Long Dim col As Integer, row As Integer Dim r As String, b As String, g As String Dim started As Boolean Dim Y As String Dim Cr As String Dim Cb As String 'Send the command to the camera ret = SendCommand("DF", 6000) On Error GoTo err1 'error check the results If ret = "-1" Then Frame_Status.Caption = "Error Dumping Frame" Else Command_Status.FillColor = RGB(255, 255, 0) Frame_Status.Caption = "Dumping Frame..." PIC.ScaleMode = vbPixels PIC.Cls pic_hi.Visible = False 'set up our flags and coutners started = False Left = 1 row = 0 col = 0 While Left < Len(ret) DoEvents 'Check for new column If Asc(Mid(ret, Left, 1)) = 2 Then 'Frame_Status.Caption = "New Col Found" col = col + 2 Left = Left + 1 row = 0 'Check for new frame ElseIf Asc(Mid(ret, Left, 1)) = 1 Then 'Frame_Status.Caption = "New Frame Found" row = 0 started = True Left = Left + 1 col = 0 'Check for end of frame ElseIf Asc(Mid(ret, Left, 1)) = 3 Then 'Frame_Status.Caption = "End of Frame Found" started = False Else 'make sure we are in an image and then dump If started = True Then r = Mid(ret, Left, 1) g = Mid(ret, Left + 1, 1) b = Mid(ret, Left + 2, 1) PIC.PSet (col, row), RGB(Asc(r), Asc(g), Asc(b)) 'have to double each column PIC.PSet (col + 1, row), RGB(Asc(r), Asc(g), Asc(b)) row = row + 1 Left = Left + 3 End If End If 'if we havent started yet inc by 1 until we find the start If started = False Then Left = Left + 1 End If Wend Command_Status.FillColor = RGB(0, 255, 0) Frame_Status.Caption = "Done Recieving Frames(" & col & ")" End If On Error GoTo 0 Exit Sub err1: Frame_Status.Caption = "Error Dumping Frame" Command_Status.FillColor = RGB(255, 0, 0) Ser_In.Text = Ser_In.Text & "Error Reading Image From Comport (try again)" & vbCrLf End Sub
Private Sub Joystick_BU_Click() Table of Contents '********************************** ' Show the joystick form '********************************** Joystick.Show End Sub
Private Sub button_auto_tracking_Click() Table of Contents '***************************************** 'Sets the cam into autotracking mode '***************************************** Dim ret As String 'send command ret = SendCommand("L1 2", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Auto Tracking Mode" Else Ser_In.Text = Ser_In.Text & " --> Tracking Mode Set To (Auto)" & vbCrLf tracking_Status.FillColor = RGB(0, 0, 255) End If End Sub
Private Sub command_middle_mass_on_servo_to_Click() Table of Contents '***************************************** 'Sets the cam into MiddleMass mode off '***************************************** Dim ret As String 'send command ret = SendCommand("MM 14", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Middle Mass Mode To On with Servo Support" Else Ser_In.Text = Ser_In.Text & " --> Middle Mass Mode Set To (Servo On)" & vbCrLf MM_Status.FillColor = RGB(0, 0, 255) End If End Sub
Private Sub command_middle_mass_off_Click() Table of Contents '***************************************** 'Sets the cam into MiddleMass mode off '***************************************** Dim ret As String 'send command ret = SendCommand("MM 0", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Middle Mass Mode To Off" Else Ser_In.Text = Ser_In.Text & " --> Middle Mass Mode Set To (Off)" & vbCrLf MM_Status.FillColor = RGB(255, 0, 0) End If End Sub
Private Sub command_middle_mass_on_Click() Table of Contents '***************************************** 'Sets the cam into MiddleMass mode Normal (on) '***************************************** Dim ret As String 'send command ret = SendCommand("MM 1", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Middle Mass Mode To On" Else Ser_In.Text = Ser_In.Text & " --> Middle Mass Mode Set To (on)" & vbCrLf MM_Status.FillColor = RGB(0, 255, 0) End If End Sub
Private Sub button_disable_tracking_Click() Table of Contents '***************************************** 'Sets the cams tracking to off '***************************************** Dim ret As String 'send command ret = SendCommand("L1 0", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Disable Auto Tracking Mode" Else Ser_In.Text = Ser_In.Text & " --> Tracking Mode Set To (Off)" & vbCrLf tracking_Status.FillColor = RGB(255, 0, 0) End If End Sub
Private Sub ping_bu_Click() Table of Contents '***************************************** 'Send default command, basically ping the 'camera. Nothing is reset and the camera 'simply responds with a ack or nck. '***************************************** Dim ret As String 'Send the blank command to check for status, used for ping ret = SendCommand("", 50) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Could Not Find Camera" Ser_In.Text = Ser_In.Text & "CMUcam not found" & vbCrLf ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Could Not Find Camera" Ser_In.Text = Ser_In.Text & "CMUcam not found" & vbCrLf Else 'Did get the command so parse it Frame_Status.Caption = "Found the CMUcam" Ser_In.Text = Ser_In.Text & "Ping Successful" & vbCrLf End If End Sub
Private Sub version_bu_Click() Table of Contents '***************************************** 'Get the firmware version of the CMUCam '***************************************** Dim ret As String 'send command ret = SendCommand("GV", 100) 'Check for an error from the snedcommand and recievecommand 'also check for a : whcih indicates an end to the data If ret = "-1" Then Frame_Status.Caption = "Couldn't Get Firmware Version" Ser_In.Text = Ser_In.Text & "Couldn't Get Firmware Version" & vbCrLf ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Get Firmware Version" Ser_In.Text = Ser_In.Text & "Couldn't Get Firmware Version" & vbCrLf Else 'Did get the command so parse it Frame_Status.Caption = "Got CMUcam Firmware" Ser_In.Text = Ser_In.Text & "Firmware: " & Mid(ret, 5, Len(ret) - 5) & vbCrLf End If End Sub
Private Sub reset_bu_Click() Table of Contents '***************************************** ' Sends the reset command. Resets all registers ' and settings currently in the CMUCam '***************************************** Dim ret As String 'send command ret = SendCommand("RS", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Reset Camera" Ser_In.Text = Ser_In.Text & "Couldn't Reset Camera, Retrying" & vbCrLf Call reset_bu_Click Exit Sub ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Reset Camera" Ser_In.Text = Ser_In.Text & "Couldn't Reset Camera, Retrying" & vbCrLf Call reset_bu_Click Exit Sub Else 'Did get the command so parse it Frame_Status.Caption = "Camera Reset" Ser_In.Text = Ser_In.Text & Mid(ret, 6, Len(ret) - 6) & vbCrLf 'reset status markers tracking_Status.FillColor = RGB(255, 0, 0) MM_Status.FillColor = RGB(255, 0, 0) looping_status.FillColor = RGB(255, 0, 0) Me.Refresh End If End Sub
Private Sub Mean_Color_value_Click() Table of Contents '****************************************** ' Get and constant display the mean color value ' of the current image '****************************************** Dim ret As String Dim mark As Integer Dim mark2 As Integer Dim rmean As String Dim gmean As String Dim bmean As String Dim rdev As String Dim gdev As String Dim bdev As String 'send command ret = SendCommand("GM", 150) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Get Color Data" Ser_In.Text = Ser_In.Text & "Couldn't Get Color Data, Retrying" & vbCrLf Call Mean_Color_value_Click Exit Sub Else 'Did get the command so parse it Frame_Status.Caption = "Got Mean Color Data" Ser_In.Text = Ser_In.Text & "Got Mean Color Data, Data as Follows" & vbCrLf 'Find the ACK & S and drop them mark = InStr(1, ret, " ") ret = Right(ret, Len(ret) - mark) 'Get the Rmean out mark = InStr(1, ret, " ") rmean = Mid(ret, 1, mark) ret = Right(ret, Len(ret) - mark) 'Get the Gmean out mark = InStr(1, ret, " ") gmean = Mid(ret, 1, mark) ret = Right(ret, Len(ret) - mark) 'Get the Bmean out mark = InStr(1, ret, " ") bmean = Mid(ret, 1, mark) ret = Right(ret, Len(ret) - mark) 'Get the Rdev out mark = InStr(1, ret, " ") rdev = Mid(ret, 1, mark) ret = Right(ret, Len(ret) - mark) 'Get the Gdev out mark = InStr(1, ret, " ") gdev = Mid(ret, 1, mark) ret = Right(ret, Len(ret) - mark) 'Get the Bdev out mark = InStr(1, ret, "S") If mark = 0 Then mark = 1 End If bdev = Mid(ret, 1, mark - 1) If bdev = "" Or bdev = " " Then bdev = ret End If 'display the info With Ser_In .Text = .Text & " Rmean = " & rmean & vbCrLf .Text = .Text & " Gmean = " & gmean & vbCrLf .Text = .Text & " Bmean = " & bmean & vbCrLf .Text = .Text & " Rdeviation = " & rdev & vbCrLf .Text = .Text & " GDeviation = " & gdev & vbCrLf .Text = .Text & " BDeviation = " & bdev & vbCrLf End With End If Call reset_bu_Click End Sub
Private Sub menu_exit_Click() Table of Contents '************************************ ' User wants to exit so call the ' unload function '************************************ Unload Me End Sub
Private Sub menu_joystick_Click() Table of Contents '************************************ ' User wants to launch the joystcik so ' we do so '************************************ Joystick.Show End Sub
Private Sub poll_mode_Click() Table of Contents '****************************************** ' Enable pollmode for the cmucam '****************************************** Dim ret As String 'start pollmode ret = SendCommand("PM 1", 50) If ret = "-1" Then Exit Sub End If 'Start linemode ret = SendCommand("LM 1", 50) If ret = "-1" Then Exit Sub End If Stop_Looping = False PIC.Cls pic_hi.Cls pic_hi.Visible = True stop_loop.Visible = True While Stop_Looping = False DoEvents Call pollme Wend stop_loop.Visible = False pic_hi.Visible = False Call reset_bu_Click End Sub
Private Sub Reg_Update_Click() Table of Contents '****************************************** ' Update the brightness and contrast regs '****************************************** Dim temp As String Dim ret As String Dim val As String Dim bool As Boolean 'Flag to see if any of the reg updates fail bool = True 'Send the brightness command temp = brightness_combo.Text ret = SendCommand("CR 6 " & temp, 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Brightness" Ser_In.Text = Ser_In.Text & "Couldn't Set Brightness" & vbCrLf bool = False ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Set Brightness" Ser_In.Text = Ser_In.Text & "Couldn't Set Brightness" & vbCrLf bool = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Brightness Register set to " & temp & vbCrLf End If 'Send the Contrast Command temp = contrast_combo.Text ret = SendCommand("CR 5 " & temp, 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Contrast" Ser_In.Text = Ser_In.Text & "Couldn't Set Contrast" & vbCrLf bool = False ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Set Contrast" Ser_In.Text = Ser_In.Text & "Couldn't Set Contrast" & vbCrLf bool = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Contrast Register set to " & temp & vbCrLf End If 'Send the Contrast Command temp = noise_combo.Text ret = SendCommand("NF " & temp, 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Noise Filter" Ser_In.Text = Ser_In.Text & "Couldn't Set Noise Filter" & vbCrLf bool = False ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Set Noise Filter" Ser_In.Text = Ser_In.Text & "Couldn't Set Noise Filter" & vbCrLf bool = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Noise Filter Set to " & temp & vbCrLf End If 'Send the Contrast Command temp = HM_Combo.Text ret = SendCommand("HM " & temp, 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set HM Mode" Ser_In.Text = Ser_In.Text & "Couldn't Set HM Mode" & vbCrLf bool = False ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Set HM Mode" Ser_In.Text = Ser_In.Text & "Couldn't Set HM Mode" & vbCrLf bool = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> HM Mode Set To " & temp & vbCrLf End If 'Send the FPS command temp = Combo_FPS.Text If temp = 17 Then val = 2 ElseIf temp = 13 Then val = 3 ElseIf temp = 11 Then val = 4 ElseIf temp = 9 Then val = 5 ElseIf temp = 8 Then val = 6 ElseIf temp = 7 Then val = 7 ElseIf temp = 6 Then val = 8 ElseIf temp = 5 Then val = 10 ElseIf temp = 4 Then val = 12 Else bool = False End If 'send command ret = SendCommand("CR 17 " & val, 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Clock Speed (FPS)" Ser_In.Text = Ser_In.Text & "Couldn't Set Clock Speed (FPS)" & vbCrLf bool = False ElseIf Not Right(ret, 1) = ":" Then Frame_Status.Caption = "Couldn't Set Clock Speed (FPS)" Ser_In.Text = Ser_In.Text & "Couldn't Set Clock Speed (FPS)" & vbCrLf bool = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Clock Speed Set (FPS = " & temp & " )" & vbCrLf End If 'Check to see if any of the updates failed and inform the user If bool = False Then Frame_Status.Caption = "One or more reg updates failed" Else Frame_Status.Caption = "Reg updates successful" End If End Sub
Private Sub Reset_regs_Click() Table of Contents '****************************************** ' Reset all Regs to factory default '****************************************** Dim ret As String Dim flag As Boolean flag = True 'send command ret = SendCommand("CR", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Reset Registers" flag = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Registers Reset" & vbCrLf End If 'send command ret = SendCommand("HM 0", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Reset Registers" flag = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Registers Reset" & vbCrLf End If 'send command ret = SendCommand("NF 0", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Reset Registers" flag = False Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Registers Reset" & vbCrLf End If If flag = False Then Frame_Status.Caption = "Reseting Registers Failed" Else Frame_Status.Caption = "Registers Reset" End If End Sub
Private Sub Restore_window_size_Click() Table of Contents '****************************************** ' Resets the window size to normal '****************************************** Dim ret As String 'send command ret = SendCommand("SW", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Reset Window Size" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Window Size Reset to Defualt (1,1,80,143)" & vbCrLf windowsize_x1.Text = 1 windowsize_y1.Text = 1 windowsize_x2 = 80 windowsize_y2 = 143 End If End Sub
Private Sub RGB_OFF_Click() Table of Contents '********************************************* ' User wants to set RGB White Balance off '********************************************* Dim ret As String 'send command ret = SendCommand("CR 18 40", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set RGB White Balance Off Mode" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> RGB White Off Mode Set" & vbCrLf End If End Sub
Private Sub RGB_ON_Click() Table of Contents '********************************************* ' User wants to set RGB White Balance on '********************************************* Dim ret As String 'send command ret = SendCommand("CR 18 44", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set RGB White Balance On Mode" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> RGB White On Mode Set" & vbCrLf End If End Sub
Private Sub Ser_In_Change() Table of Contents '************************************ ' Advanced the Serial in text box ' down as more data is placed in it ' this way the user doesnt have to ' scroll manually '************************************ Ser_In.SelStart = Len(Ser_In.Text) End Sub
Private Sub Set_window_Size_Click() Table of Contents '********************************************* ' Set the window size to different dimensions '********************************************* Dim ret As String 'send command ret = SendCommand("SW " & windowsize_x1.Text & " " & windowsize_y1.Text & " " & windowsize_x2.Text & " " & windowsize_y2.Text, 150) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Adjust Frame Size" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " -->Frame Size Changed ( " & windowsize_x1.Text & " " & windowsize_y1.Text & " " & windowsize_x2.Text & " " & windowsize_y2.Text & ")" & vbCrLf End If End Sub
Private Sub set_servo_Click() Table of Contents '********************************************* ' Set the servo position to the desired location '********************************************* Dim ret As String 'send command ret = SendCommand("S1 " & new_servo_pos.Text, 120) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Servo Pos" Exit Sub Else Ser_In.Text = Ser_In.Text & "S1 --> Set Servo Pos (" & new_servo_pos.Text & ")" & vbCrLf tracking_Status.FillColor = RGB(0, 255, 0) End If End Sub
Private Sub Start_Tracking_Click() Table of Contents '***************************************** 'Sets the cam into manual mode '***************************************** Dim ret As String Dim InputString As String Dim mark As Integer Dim WhatPacket As String Dim Mx As String, My As String Dim X1 As String, Y1 As String, X2 As String, Y2 As String Dim PixCnt As String, ObjConf As String Dim spos As String 'Set the Tracking Light On ret = SendCommand("L1 1", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set Tracking Mode" Exit Sub Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> Tracking Mode Set To (Manual)" & vbCrLf tracking_Status.FillColor = RGB(0, 255, 0) End If 'Start Tracking that Color ret = SendCommand("TC " & L_R & " " & L_G & " " & L_B & " " & U_R & " " & U_G & " " & U_B, 300) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Init Tracking Mode" Exit Sub Else Ser_In.Text = Ser_In.Text & "TC --> Tracking Mode Initialized" & vbCrLf tracking_Status.FillColor = RGB(0, 255, 0) End If 'Init variables for the data loop Stop_Looping = False stop_loop.Visible = True looping_status.FillColor = RGB(0, 255, 0) Call Lock_Buttons Do DoEvents 'without this bad things happen InputString = COM.Input HandlePacket (InputString) Sleep (300) Loop Until Stop_Looping = True 'Shutdown loop Call Restore_Buttons 'Restore Buttons Upon Loop Termination Call reset_bu_Click 'call board reset stop_loop.Visible = False 'hide the stop loop 'Shutdown loop Call reset_bu_Click 'call board reset stop_loop.Visible = False 'hide the stop loop Frame_Status.Caption = "Idle..." End Sub
Private Sub stop_loop_Click() Table of Contents '************************************ ' Stop the current packet loop we are ' in '************************************ Stop_Looping = True End Sub
Private Sub YcrCb_off_Click() Table of Contents '********************************************* ' User wants to set YCrCb White Balance off '********************************************* Dim ret As String 'send command ret = SendCommand("CR 18 32", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set YCrCb White Balance Off Mode" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> YCrCb White Off Mode Set" & vbCrLf End If End Sub
Private Sub YcrCb_on_Click() Table of Contents '********************************************* ' User wants to set YCrCb White Balance On '********************************************* Dim ret As String 'send command ret = SendCommand("CR 18 36", 100) 'check the result and inform user If ret = "-1" Then Frame_Status.Caption = "Couldn't Set YCrCb White Balance On Mode" Else Ser_In.Text = Ser_In.Text & Mid(ret, 5, Len(ret) - 5) & " --> YCrCb White On Mode Set" & vbCrLf End If End Sub '************************************************************************ '********************************************************* '****************************************** ' Menu Bottums below here '****************************************** '********************************************************* '************************************************************************
Private Sub menu_autotracking_Click() Table of Contents Call button_auto_tracking_Click End Sub
Private Sub menu_crcboff_Click() Table of Contents Call YcrCb_off_Click End Sub
Private Sub menu_crcbon_Click() Table of Contents Call YcrCb_on_Click End Sub
Private Sub menu_dumpframe_Click() Table of Contents Call DumpFrame_BU_Click End Sub
Private Sub menu_enabletracking_Click() Table of Contents Call Start_Tracking_Click End Sub
Private Sub menu_firmversion_Click() Table of Contents Call version_bu_Click End Sub
Private Sub menu_getmean_Click() Table of Contents Call Mean_Color_value_Click End Sub
Private Sub menu_mmoff_Click() Table of Contents Call command_middle_mass_off_Click End Sub
Private Sub menu_mmon_Click() Table of Contents Call command_middle_mass_on_Click End Sub
Private Sub menu_mmonservo_Click() Table of Contents Call command_middle_mass_on_servo_to_Click End Sub
Private Sub menu_ping_Click() Table of Contents Call ping_bu_Click End Sub
Private Sub menu_resboard_Click() Table of Contents Call reset_bu_Click End Sub
Private Sub menu_resetregs_Click() Table of Contents Call Reset_regs_Click End Sub
Private Sub menu_restorewindow_Click() Table of Contents Call Restore_window_size_Click End Sub
Private Sub menu_rgboff_Click() Table of Contents Call RGB_OFF_Click End Sub
Private Sub menu_rgbon_Click() Table of Contents Call RGB_ON_Click End Sub
Private Sub menu_line_Click() Table of Contents Call poll_mode_Click End Sub
Private Sub menu_setservopos_Click() Table of Contents Call set_servo_Click End Sub
Private Sub menu_setwinsowsize_Click() Table of Contents Call Set_window_Size_Click End Sub
Private Sub menu_trackcenterobject_Click() Table of Contents Call TrackCenter_BU_Click End Sub
Private Sub menu_updatreregs_Click() Table of Contents Call Reg_Update_Click End Sub
Private Sub menu_disabletracking_Click() Table of Contents Call button_disable_tracking_Click End Sub
Private Sub Output_Change() Table of Contents Output.SelStart = Len(Output.Text) End Sub