PDA

View Full Version : real time plot of sensor data (in VB 2008)



cloud_skyblue
05-25-2010, 08:26 PM
Hi all,

Newbie on the line! I'm working with two sharp IR sensors and the Serializer WL board. Software wise, I'm programming in VB 2008 Express. Currently, I can get the two sensors to display real-time numerical data, but I'm having trouble generating real-time point graphs of the data. My code without the plotting is as below:

Imports System
Imports System.math
Imports RoboticsConnection.Serializer
Imports RoboticsConnection.Serializer.Components
Imports RoboticsConnection.Serializer.Controllers
Imports RoboticsConnection.Serializer.Ids
Imports RoboticsConnection.Serializer.Sensors
Imports System.Windows.Forms.DataVisualization.Charting

Public Class Form1

Public serializer As New Serializer
Public MySharp1 As New GP2D12(serializer)
Public MySharp2 As New GP2D12(serializer)

Public dir As String = "S"
Public SPD As Integer = 50

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
serializer.StopCommunication()
End Sub



Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
REM Set Up Serializer
serializer.BaudRate = 19200
serializer.PortName = "COM13"
AddHandler serializer.CommunicationStarted, AddressOf Serializer_communicationStarted
serializer.StartCommunication()

End Sub

Private Sub Serializer_communicationStarted(ByVal sender As RoboticsConnection.Serializer.Serializer)
LBLStatus.Text = "Comms Started"
serializer.Units = Units.Metric



REM Sharp1 Distance and Value
MySharp1.Pin = AnalogPinId.Pin0
MySharp1.DistanceChangedThreshold = 0.1
MySharp1.ValueChangedThreshold = 1
MySharp1.UpdateFrequency = 50
AddHandler MySharp1.DistanceChanged, AddressOf MySharp1_Distance_Changed
AddHandler MySharp1.ValueChanged, AddressOf MySharp1_Value_Changed
LBLIR1.Text = "New IR Distance is : " & CStr(527.41 * 9.5 * 1 / MySharp1.Value)
LBLIRValue1.Text = "New IR Value is : " & CStr(MySharp1.Value)

REM Sharp2 Distance and Value
MySharp2.Pin = AnalogPinId.Pin1
MySharp2.DistanceChangedThreshold = 0.1
MySharp2.ValueChangedThreshold = 1
MySharp2.UpdateFrequency = 50
AddHandler MySharp2.DistanceChanged, AddressOf MySharp2_Distance_Changed
AddHandler MySharp2.ValueChanged, AddressOf MySharp2_Value_Changed
LBLIR2.Text = "New IR Distance is : " & CStr(527.41 * 9.5 * 1 / MySharp2.Value)
LBLIRValue2.Text = "New IR Value is : " & CStr(MySharp2.Value)

REM Enable timer to pump serializer events
Timer1.Enabled = True

End Sub

REM Use this to declare address for MySharp1

Private Sub MySharp1_Distance_Changed(ByVal sender As SerializerComponent)
LBLIR1.Text = "New IR Distance1 is : " & CStr(527.41 * 9.5 * 1 / MySharp1.Value)
If MySharp1.Distance < 30 And dir = "B" Then
dir = "S"

End If
End Sub

Private Sub MySharp1_Value_Changed(ByVal sender As SerializerComponent)
LBLIRValue1.Text = "New IR Value1 is : " & CStr(MySharp1.Value)
End Sub


REM use this to declare address for MySharp2

Private Sub MySharp2_Distance_Changed(ByVal sender As SerializerComponent)
LBLIR2.Text = "New IR Distance2 is : " & CStr(527.41 * 9.5 * 1 / MySharp2.Value)
If MySharp2.Distance < 30 And dir = "B" Then
dir = "S"

End If
End Sub

Private Sub MySharp2_Value_Changed(ByVal sender As SerializerComponent)
LBLIRValue2.Text = "New IR Value2 is : " & CStr(MySharp2.Value)
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
serializer.PumpEvents()
End Sub

Private Sub Chart1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chart1.Click

End Sub
End Class


I'm planning to use MS Chart Controls since it's free, but searching online hasn't gotten me anywhere close to the answer. Personally I find the documentation on MS chart controls to be a big vague =( Would anyone be able to lend a hand to the rookie? Much thanks in advance!