Tachocount not working - returns nothing or 0

View previous topic View next topic Go down

Tachocount not working - returns nothing or 0

Post  Joachim_374 on Mon Apr 16, 2012 12:40 am

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:

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

View user profile

Back to top Go down

TachoCount works fine

Post  theedge on Mon Jan 21, 2013 12:33 am

This is how I read TachoCount.

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

View user profile

Back to top Go down

Re: Tachocount not working - returns nothing or 0

Post  Joachim_374 on Thu Jan 24, 2013 9:09 am

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:

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

View user profile

Back to top Go down

Re: Tachocount not working - returns nothing or 0

Post  theedge on Thu Jan 24, 2013 7:45 pm

You're welcome.

I have the same problem with ResetMotorPosition() as you can see in:
http://mindsqualls.subject-expert.com/t18-problem-with-resetmotorposition#40

theedge

Posts : 3
Join date : 2013-01-21

View user profile

Back to top Go down

Re: Tachocount not working - returns nothing or 0

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum