Friday, July 13, 2007

Interface Completed

My interface to the robot from my computer is completed. (Using phidgets)
My program has buttons for driving and a video feed from a webcam. Outputs are directly controlled from that program and inputs are detected there for the robot to respond accordingly.
Check the comments for this post to see pictures and Visual Basic code.

2 comments:

Eric said...

' reminder: requires certain dll's '
'Made By Eric Forkosh'
Option Explicit
Dim WithEvents IFKit As PhidgetInterfaceKit 'Phidgets Identifier'
Private WithEvents Cd1 As ccrpCountdown 'Setting up Timer identifiers'
Private WithEvents Cd2 As ccrpCountdown
Private WithEvents Cd3 As ccrpCountdown



Private Sub Check1_Click() ' Turn On all Outputs Checkbox Control'
Dim i As Long
Dim state As Boolean
If chkOn.Value = Checked Then state = True Else state = False
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = state
Next i
End Sub
'Clear All Outputs Command'
Private Sub Clear_Click()
Dim q As Long
For q = 0 To 15
Output(q).Value = Unchecked
Next q
chkOn.Value = Unchecked
Dim w As Long

For w = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(w) = False
Next w
With Player(5)
.Command = "Close"
.filename = "C:\Voice\cleared.wav" ' Set the file to be played'

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file


End With
End Sub
'Back To Home Command Control'
Private Sub Command1_Click()
Start.Show
Unload Me
End Sub
'Exit Control'
Private Sub Close_Click()
Unload Me
End Sub

'Abort command Control'
Private Sub Command3_Click()
Output(0).Value = Unchecked
Output(1).Value = Unchecked
Output(2).Value = Unchecked
Output(3).Value = Unchecked
Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False
Next i
Arrow1.Picture = LoadPicture("C:\Voice\blank.gif")
Arrow2.Picture = LoadPicture("C:\Voice\blank.gif")
With Player(4)
.Command = "Close"
.filename = "C:\Voice\stop.wav" ' Set the file to be played'
.Command = "Open" ' Open the file

.Command = "Play" ' Play the file


End With



End Sub

Private Sub Command5_Click(Index As Integer)
'Forward Command Control'
Output(0).Value = Checked
Output(1).Value = Unchecked
Output(2).Value = Checked
Output(3).Value = Unchecked


Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False 'Turn off all outputs'
Next i
For i = 0 To IFKit.NumOutputs - 1 'Only Turn on Output 0 and Output 2'
IFKit.OutputState(0) = True
IFKit.OutputState(2) = True
Next i
With Cd2
.Enabled = False
End With
With Cd3
.Enabled = False
End With
With Cd1
.Enabled = True


End With
Arrow1.Picture = LoadPicture("C:\Voice\2.gif") 'Load Forward Motor Direction Arrow'
Arrow2.Picture = LoadPicture("C:\Voice\2.gif")
With Player(0)
.Command = "Close"
.filename = "C:\Voice\goingforward.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With

End Sub
'Right Command Control'
Private Sub Command6_Click(Index As Integer)
Output(0).Value = Checked
Output(1).Value = Unchecked
Output(2).Value = Unchecked
Output(3).Value = Checked

Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False
Next i
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(0) = True
IFKit.OutputState(3) = True
Next i
With Cd1
.Enabled = False
End With

With Cd3
.Enabled = False
End With
With Cd2
.Enabled = True


End With
Arrow1.Picture = LoadPicture("C:\Voice\2.gif")
Arrow2.Picture = LoadPicture("C:\Voice\1.gif")

With Player(1)
.Command = "Close"
.filename = "C:\Voice\goingright.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
End Sub

'Reverse Command Control'
Private Sub Command7_Click()
Output(0).Value = Unchecked
Output(1).Value = Checked
Output(2).Value = Unchecked
Output(3).Value = Checked
Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False
Next i
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(1) = True
IFKit.OutputState(3) = True
Next i
With Cd1
.Enabled = False
End With

With Cd2
.Enabled = False
End With
With Cd3
.Enabled = True


End With
Arrow1.Picture = LoadPicture("C:\Voice\1.gif")
Arrow2.Picture = LoadPicture("C:\Voice\1.gif")

With Player(3)
.Command = "Close"
.filename = "C:\Voice\goingreverse.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
End Sub




'Left Command Control'
Private Sub Command8_Click()

Output(0).Value = Unchecked
Output(1).Value = Checked
Output(2).Value = Checked
Output(3).Value = Unchecked
Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False
Next i
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(1) = True
IFKit.OutputState(2) = True

With Cd1
.Enabled = False
End With

With Cd3
.Enabled = False
End With
With Cd2
.Enabled = True


End With
Next i
Arrow1.Picture = LoadPicture("C:\Voice\1.gif")
Arrow2.Picture = LoadPicture("C:\Voice\2.gif")
With Player(5)
.Command = "Close"
.filename = "C:\Voice\goingleft.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
End Sub






Private Sub Form_Load()

Set Cd1 = New ccrpCountdown
Set Cd2 = New ccrpCountdown
Set Cd3 = New ccrpCountdown

'Set Up Durations and Intervals of Countdowns'

With Cd1 'Forward Command
.Duration = 4000 ' 4 seconds
.Interval = 100 ' 0.1 seconds
.Enabled = False


End With
With Cd2 'Turning Command
.Duration = 2000 ' 2 seconds
.Interval = 100 ' 0.1 seconds
.Enabled = False


End With
With Cd3 'Backward Command
.Duration = 3000 ' 3 seconds
.Interval = 100 ' 0.1 seconds
.Enabled = False


End With
With Player(0)
.Command = "Close"
.filename = "C:\Voice\yesmaster.wav" ' Set the file to be played when program starts

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
Set IFKit = New PhidgetInterfaceKit 'Get the phidget manager going
chkOn.Enabled = False 'interactive only when the phidget is attached
IFKit.Open

End Sub

'Toggle all outputs on or off.
Private Sub chkOn_Click()
Dim state As Boolean
If chkOn.Value = Checked Then state = True Else state = False
Dim E As Long
For E = 0 To 15
IFKit.OutputState(E) = state

If chkOn.Value = Checked Then GoTo Label Else: GoTo NoLabel
Label: Output(E).Value = Checked
With Player(0)
.Command = "Close"
.filename = "C:\Voice\AllOn.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
GoTo Next1
NoLabel: Output(E).Value = Unchecked
Next1: Next E
End Sub

'An InterfaceKit was found. Start everything up
Private Sub IFKit_OnAttach()
Dim i As Long
'make the sensors less sensitive so that we don't get flooded with events
For i = 0 To IFKit.NumSensors - 1
IFKit.SensorChangeTrigger(i) = 30
Next i
chkOn.Enabled = True
lblSerialNumber.Caption = "Serial Number : " & IFKit.SerialNumber
lblVersion.Caption = "Device Version : " & IFKit.DeviceVersion

End Sub

'The Interface kit was detached. Clean up, and stop polling.
Private Sub IFKit_OnDetach()
Dim Ans As String

chkOn.Enabled = False
Ans = MsgBox("Phidgets Interface Kit Has Been Disconnected!", 16, "Phidget Disconnected!")
End Sub

'Report the value of the input whenever it changes
Private Sub IFKit_OnInputChange(ByVal Index As Long, ByVal NewState As Boolean)
Display " Input " & Index & " = " & NewState
If (Index > 15) Then Exit Sub

If (NewState) Then
InputD(Index).Value = 1
Else
InputD(Index).Value = 0
End If

If InputD(0).Value = Checked Then Shape2(0).FillStyle = 0 Else Shape2(0).FillStyle = 1
If InputD(1).Value = Checked Then Shape2(1).FillStyle = 0 Else Shape2(1).FillStyle = 1
If InputD(2).Value = Checked Then Shape2(2).FillStyle = 0 Else Shape2(2).FillStyle = 1
If InputD(3).Value = Checked Then Shape2(3).FillStyle = 0 Else Shape2(3).FillStyle = 1
If InputD(4).Value = Checked Then Shape2(4).FillStyle = 0 Else Shape2(4).FillStyle = 1
End Sub

'Report the value of the output whenever it changes
Private Sub IFKit_OnOutputChange(ByVal Index As Long, ByVal NewState As Boolean)
Display "Output " & Index & " = " & NewState
End Sub

'Report the value of the sensor whenever it changes
Private Sub IFKit_OnSensorChange(ByVal Index As Long, ByVal SensorValue As Long)
Display "Sensor " & Index & " = " & SensorValue
End Sub

Private Sub Display(Entry As String)
Text1.Text = Entry & vbCrLf & Text1.Text
End Sub

Private Sub nav_Click()
Output(0).Value = Checked
Output(1).Value = Unchecked
Output(2).Value = Checked
Output(3).Value = Unchecked


Dim i As Long
Dim state As Boolean
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(i) = False
Next i
For i = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(0) = True
IFKit.OutputState(2) = True
Next i


Arrow1.Picture = LoadPicture("C:\Voice\2.gif")
Arrow2.Picture = LoadPicture("C:\Voice\2.gif")
With Player(0)
.Command = "Close"
.filename = "C:\Voice\cruise.wav" ' Set the file to be played

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file

End With
End Sub

Private Sub Output_Click(Index As Integer)
IFKit.OutputState(Index) = Output(Index).Value
End Sub


Private Sub Cd1_timer()
'Clear All Outputs'
Dim q As Long
For q = 0 To 15
Output(q).Value = Unchecked
Next q
chkOn.Value = Unchecked
Dim w As Long

For w = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(w) = False
Next w
With Player(4)
.Command = "Close"
.filename = "C:\Voice\stop.wav" ' Set the file to be played- Cape Cod camera Test http://www.capecodlivecam.com/hyannisharbor.shtml'

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file


End With
Arrow1.Picture = LoadPicture("C:\Voice\blank.gif")
Arrow2.Picture = LoadPicture("C:\Voice\blank.gif")
End Sub

Private Sub Cd2_timer()
'Clear All Outputs'
Dim q As Long
For q = 0 To 15
Output(q).Value = Unchecked
Next q
chkOn.Value = Unchecked
Dim w As Long

For w = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(w) = False
Next w
With Player(4)
.Command = "Close"
.filename = "C:\Voice\stop.wav" ' Set the file to be played- Cape Cod camera Test http://www.capecodlivecam.com/hyannisharbor.shtml'

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file


End With
Arrow1.Picture = LoadPicture("C:\Voice\blank.gif")
Arrow2.Picture = LoadPicture("C:\Voice\blank.gif")
End Sub

Private Sub Cd3_timer()
'Clear All Outputs'
Dim q As Long
For q = 0 To 15
Output(q).Value = Unchecked
Next q
chkOn.Value = Unchecked
Dim w As Long

For w = 0 To IFKit.NumOutputs - 1
IFKit.OutputState(w) = False
Next w
With Player(4)
.Command = "Close"
.filename = "C:\Voice\stop.wav" ' Set the file to be played- Cape Cod camera Test http://www.capecodlivecam.com/hyannisharbor.shtml'

.Command = "Open" ' Open the file

.Command = "Play" ' Play the file


End With
Arrow1.Picture = LoadPicture("C:\Voice\blank.gif")
Arrow2.Picture = LoadPicture("C:\Voice\blank.gif")
End Sub

Eric said...

I know some of it is a bit repetitive, but I left it on for now.