Tachocount not working - returns nothing or 0
2 posters
MindSqualls :: Questions :: Using the motors :: NXT motors
Page 1 of 1
Tachocount not working - returns nothing or 0
Hi,
I tried to get the tachocount from the NXTmotor but everytime it returns 0
Please - can anyone explain how the tachocount and the triggertachocount it working?
This is my code:
Thanks!
Joachim
I tried to get the tachocount from the NXTmotor but everytime it returns 0
Please - can anyone explain how the tachocount and the triggertachocount it working?
This is my code:
- Code:
Imports NKH.MindSqualls
Imports NKH.MindSqualls.MotorControl
Sub Test()
' Attach motors to port B and C on the NXT.
Brick.MotorA = New NxtMotor()
Brick.MotorB = New NxtMotor()
'Not sure - before or after connect the brick?!?
'Poll it every 50 milliseconds.
Brick.MotorA.PollInterval = 50
Brick.MotorB.PollInterval = 50
' Connect to the NXT brick.
dim Brick As NxtBrick = New NxtBrick(NxtCommLinkType.USB, 0)
Brick.Connect()
System.Threading.Thread.Sleep(500)
'Not sure - before or after connect the brick?!?
'Poll it every 50 milliseconds.
Brick.MotorA.PollInterval = 50
Brick.MotorB.PollInterval = 50
Brick.MotorA.ResetMotorPosition(False)
Brick.MotorB.ResetMotorPosition(True)
Brick.MotorA.TriggerTachoCount = 0
Brick.MotorB.TriggerTachoCount = 0
Brick.MotorA.Run(100, 360)
Brick.MotorB.Run(100, 360)
System.Threading.Thread.Sleep(500)
Brick.MotorA.Idle()
Brick.MotorB.Idle()
If Brick.MotorA.TriggerTachoCount <> 0 Then Stop
If Brick.MotorB.TriggerTachoCount <> 0 Then Stop
If Brick.MotorA.TachoCount <> 0 Then Stop
If Brick.MotorB.TachoCount <> 0 Then Stop
Stop
end sub
Thanks!
Joachim
Joachim_374- Posts : 3
Join date : 2012-02-23
TachoCount works fine
This is how I read TachoCount.
In which languge is your code written?
- Code:
public int getTachoB() {
int tc = -1;
try {
motorB.Poll();
return (int)motorB.TachoCount;
} catch (Exception) {
error = true;
errorCode = 1;
return tc;
}
}
In which languge is your code written?
theedge- Posts : 3
Join date : 2013-01-21
Re: Tachocount not working - returns nothing or 0
Dear edge,
thanks for your code. My code is writen in vb.net. You can convert vb.net and C# code very easy on this page:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
I tried to use your code and it is working fine:
I tested the "getTachoCount" with this little function:
It was working fine - but I cannot reset the tachocount value to zero. I tried to do this with:
Brick.MotorA.ResetMotorPosition(True)
Brick.MotorA.TriggerTachoCount = 0
but that was not working.
Do you know how to reset the Tachocount?
Joachim
thanks for your code. My code is writen in vb.net. You can convert vb.net and C# code very easy on this page:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
I tried to use your code and it is working fine:
- Code:
''' <summary>
''' This function reads the tachocount from a NXTmotor
''' </summary>
''' <param name="Motor">The Motor as object</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function getTachoCount(Motor As NxtMotor) As Integer
Try
Motor.Poll()
Return CInt(Motor.TachoCount)
Catch generatedExceptionName As Exception
Return 0
End Try
End Function
I tested the "getTachoCount" with this little function:
- Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Brick.MotorA = New NxtMotor()
Brick.Connect()
Brick.MotorA.PollInterval = 50
Brick.MotorA.ResetMotorPosition(True)
Brick.MotorA.TriggerTachoCount = 0
Brick.MotorA.Run(25, 0)
Dim MA As Integer
Do Until MA >= 1000
MA = getTachoCount(Brick.MotorA)
Button1.Text = MA
Button1.Refresh()
Loop
Brick.MotorA.Idle()
End Sub
It was working fine - but I cannot reset the tachocount value to zero. I tried to do this with:
Brick.MotorA.ResetMotorPosition(True)
Brick.MotorA.TriggerTachoCount = 0
but that was not working.
Do you know how to reset the Tachocount?
Joachim
Joachim_374- Posts : 3
Join date : 2012-02-23
Re: Tachocount not working - returns nothing or 0
You're welcome.
I have the same problem with ResetMotorPosition() as you can see in:
https://mindsqualls.danskforum.net/t18-problem-with-resetmotorposition#40
I have the same problem with ResetMotorPosition() as you can see in:
https://mindsqualls.danskforum.net/t18-problem-with-resetmotorposition#40
theedge- Posts : 3
Join date : 2013-01-21
MindSqualls :: Questions :: Using the motors :: NXT motors
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|