Calculate rotation (getTachoCount())

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Calculate rotation (getTachoCount())

Postby freeall » Fri Nov 02, 2007 9:44 am

Hi.

This should be fairly basic, but for some reason I cannot get Motor.A.getTachoCount() to give me anything but 0.

I have tried rotate(x), rotateTo(x, true/false), forward(), backward(). Each of them tried something like sleeping for a while, then printing getTachoCount().

So for example this code:
Code: Select all
   Motor.A.setSpeed(50);
   Motor.A.regulateSpeed(true);
   Motor.A.resetTachoCount();
   Motor.A.forward();

   for (int i=0; i<50; i++) {
      // SLEEP
      try {
         Thread.sleep(milisec);
      } catch(Exception e) { }

      // OUTPUT
      LCD.clear();
      LCD.drawInt(Motor.A.getTachoCount(), 0, 0);
      LCD.refresh();
   }

   Motor.A.stop();


This code and other variations of it with the methods I mentioned above keeps outputting 0. And rotate() and rotateTo() just never stops unless I use really small values like 1..3.

Anyone have suggestions? There is navigator/pilot but in this example I really need to control just one motor and I just can't.
freeall
New User
 
Posts: 6
Joined: Fri Oct 05, 2007 6:13 am

Postby roger » Sun Nov 04, 2007 7:16 am

The units of the parameter in setSpeed( ) are degrees per second according to the API, so speed(50) is 20 ms per degree. Just have patience.
Run
Code: Select all
  public static void main(String[] args)
   {
      Motor.A.setSpeed(50);
      Motor.A.rotateTo(500);
      LCD.drawInt(Motor.A.getTachoCount(),0,0);
      LCD.refresh();
      Button.waitForPress();
   }

and after about 10 seconds the will LCD show about 489. If you try it you will see that speed regulation is not good at very slow speeds. This is because the power required to maintain a very low speed is not enough to overcome starting friction. The regulator keeps increasing power till the motor starts turning, but then has to reduces it because the motor is running too fast. If you want a steady rotation at very low speeds, you will have to run the motor faster and use gear reduction.
Perhaps you were not trying for slow speed, but, not having read the API, just assumed that speed in NXJ was the same as in the lLego oftware.
Moral: read the API

Roger
roger
Moderator
 
Posts: 359
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA

Postby freeall » Sun Nov 04, 2007 10:25 am

Hi Roger.

Thanks for the reply. And yes, I did read the API (the examples in the API doesn't even work).

The code you gave me doesn't work either. What I can say is that the setspeed() does not seem to do anything, when using rotateTo(). I looked in Motor.java and from there on in the interfaces and stuff in Lejos like MotorPort.java. I can see that it all comes down to whether this function
Code: Select all
public static native int getTachoCountById(int aMotor);

works or not. And for me it does not. I always get 0 in return. Which also makes sense because that would cause rotateTo() to create an infinete loop since it cannot read the tacho count.

I think this might just be my problem and not a general one. I have often used TachoNavigator and Pilot and those seem to work for me. Also, I have tried this on both Windows and Linux and with two different NXT's. Somehow it just doesn't seem to work...

Any help from anyone? Where could I have a bug. And if you have some code that most definetly works with one motor then reply with the code and I will see if it also fails with that.
freeall
New User
 
Posts: 6
Joined: Fri Oct 05, 2007 6:13 am

found the bug

Postby freeall » Sun Nov 04, 2007 10:40 am

Just flashed this nxt and did this code:
Code: Select all
   Motor.A.setSpeed(500);
   Motor.A.rotateTo(180, true);
   while (Motor.A.isRotating()) {
       LCD.clear();
       LCD.drawInt(Motor.A.getTachoCount(),0,0);
       LCD.refresh();
       wait(100);
   }
   Button.waitForPress();

wait is just a functions that wraps try..Thread.sleep()..catch...
And it kept writing -1... some bug somewhere. Either in my setup or in lejos. A bit weird, innit?

This table I sit has a mix of RCX and NXT things. And cables from RCX can be used in NXT as well... but some information might not be sent properly through those cables cause my Motor did not work. Changing the cables did the trick.

The moral: Do not use cables from RCX on NXJ.
freeall
New User
 
Posts: 6
Joined: Fri Oct 05, 2007 6:13 am

Postby roger » Mon Nov 05, 2007 5:50 pm

Hi freeall,
I'm glad to know you solved the problem. Sounds as if your table is almost as messy as mine.
Roger
roger
Moderator
 
Posts: 359
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

more stuff