View Full Version : WheelEncoder.Count not returning a value

12-26-2010, 12:21 PM
I'm attempting to read the encoder count (programmatically using VB.NET) while running the robot. Here's my simple code:

Dim WheelEncoder_1 As WheelEncoder = New WheelEncoder(mySerializer)
WheelEncoder_1.WheelEncoderId = WheelEncoderId.Encoder1
WheelEncoder_1.UpdateFrequency = 25
labelCount.Text = WheelEncoder_1.Count.ToString

These four lines are executed from a 100 millisecond Timer control, but I don't get any value returned from the "WheelEncoder_1.Count" query. I double-checked via Hyperterminal and am able to get a count using the "getenc" command. Could it possibly be a problem with executing it in a Timer control or executing it while the robot is in motion?

12-27-2010, 09:00 AM
Could it be that wheelencoder_1.count is declared as a numeric variable and you are trying to assign it to a string? Can you print the value of wheelencoder_1.count before any string conversion?

12-27-2010, 06:54 PM
I put the wheelencoder_1.count in a MsgBox before the conversion and it shows that just a zero is being returned. Don't know if it helps, but here's how I'm calling the procedure (the Timers' Interval is 50 (milliseconds)):

Private Sub Timer_Accel_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_Accel.Tick
End Sub

Sub distanceTravelled()
Dim WheelEncoder_1 AsWheelEncoder = NewWheelEncoder(mySerializer)
WheelEncoder_1.WheelEncoderId = WheelEncoderId.Encoder1
WheelEncoder_1.UpdateFrequency = 25
labelCount.Text = WheelEncoder_1.Count.ToString
End Sub

01-05-2011, 11:16 PM
Just as a follow-up...I found the problem after many hours of debugging: the sequence of execution was incorrect. The instantiation of the WheelEncoder instance must be done before communication with the Serializer has begun (before the StartCommunication or Run command). That's it. For the benefit of others, here's my code:

Imports RoboticsConnection.Serializer
Imports RoboticsConnection.Serializer.Ids
Imports RoboticsConnection.Serializer.Sensors
Imports RoboticsConnection.Serializer.Components
Imports RoboticsConnection.Serializer.Controllers
Imports System

Public Class Form1

Public encoder_1, encoder_2 As WheelEncoder
Public bot_serializer As Serializer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bot_serializer = New Serializer
bot_serializer.PortName = "COM6"
bot_serializer.BaudRate = 19200
encoder_1 = New WheelEncoder(bot_serializer)
encoder_2 = New WheelEncoder(bot_serializer)
encoder_1.WheelEncoderId = WheelEncoderId.Encoder1
encoder_2.WheelEncoderId = WheelEncoderId.Encoder2
bot_serializer.StartCommunication() 'Must come after New WheelEncoder(serializer) command
Timer_Serializer.Enabled = True
End Sub

Private Sub Timer_Serializer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_Serializer.Tick
Label1.Text = "encoder 1 ticks: " & encoder_1.Count.ToString
Label2.Text = "encoder 2 ticks: " & encoder_2.Count.ToString
End Sub

End Class

Thanks for your help on this!