Problem with travel()

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

Moderators: roger, imaqine, 99jonathan

ck
New User
Posts: 5
Joined: Mon Feb 05, 2007 2:41 am

Problem with travel()

Postby ck » Wed Mar 14, 2007 10:35 am

Hi everyone,

Correct me if I am wrong on this one but the travel() method in class SimpleNavigator
doesn't make the motors go backwards when dist is negative.

This happens because at left.rotate(-counts); right.rotate(-counts);
"counts" is already negative, so it becomes positive again!!!

Code: Select all

 public void travel(int dist) {
        int counts = (int)(dist * COUNTS_PER_CM);
        
        left.resetTachoCount();
        right.resetTachoCount();
       
         if(dist > 0) {
            left.rotate(counts);
            right.rotate(counts);
         } else
         if(dist < 0) {
            left.rotate(-counts);
            right.rotate(-counts);
         }
         while (left.isRotating() || right.isRotating());
         moving = true;
         stop();
      }

I tried out the following version of travel() and works fine
(given that COUNTS_PER_CM is always positive) :

Code: Select all

 public void travel(int dist) {
      int counts = (int)(dist * COUNTS_PER_CM);
        
      left.resetTachoCount();
      right.resetTachoCount();
                   
      left.rotate(counts);
      right.rotate(counts);
              
      while (left.isRotating() || right.isRotating());
      moving=true;
      stop();
    }

Am I right? ...or have I just caused more problems?

User avatar
bbagnall
Site Admin
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Postby bbagnall » Fri Mar 16, 2007 7:31 pm

I think you're working with the now very outdated leJOS NXJ code. Much of this has been changed or fixed by now in our main code. If you browse subversion on our Sourceforge project there's a snapshot project that has updated stuff.

ck
New User
Posts: 5
Joined: Mon Feb 05, 2007 2:41 am

Postby ck » Sat Mar 17, 2007 9:10 pm

Could you send me the link for that...
I searched the SourceForge web site and I can't find anything exept from lejos_NXJ_win32_0_1_0alpha.zip (2007-01-10)

Thanks
Constantinos

migerh
New User
Posts: 6
Joined: Wed Mar 07, 2007 9:09 am

Postby migerh » Sun Mar 18, 2007 9:38 am

You can get information about SVN access here.


Return to “NXJ Software”

Who is online

Users browsing this forum: No registered users and 3 guests