Measuring a distance using DifferentialPilot.getTravelSpeed

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

Moderators: 99jonathan, roger, imaqine

Measuring a distance using DifferentialPilot.getTravelSpeed

Postby jt18 » Mon Mar 12, 2012 11:25 pm

I'm trying to calculate the distance traveled using the following code. I've omitted the stopwatch function, but it uses System.currentTimeMillis().

Anyway using the equation d=s*t therefore p.getTravelSpeed()*s.getElapsedTimeSec() however its inaccurate.
It is more accurate over larger distances but over small ones its massivley out.

With a 30cm gap between the two lines the returned value was ~15cm with a 90cm gap size it was ~84CM any ideas or improvements?
Cheers.
Code: Select all
   public static void pilot2(){
      DifferentialPilot p = new DifferentialPilot(3.245, 17.82, Motor.C, Motor.B, false);  // parameters in cm
      p.forward();
      while(cs.getColorID() != 7)
      {
         //halt code until start of black line
      }
      s.start(); //stopwatch start
      Sound.beep();
      while(cs.getColorID()== 7)
      {
         //halt code until passed black line
      }
      while(cs.getColorID() != 7)
      {
         //halt code until next black line
         
      }
      s.stop();
      p.stop();
      Sound.beep();
      System.out.println(p.getTravelSpeed()*s.getElapsedTimeSec());
      Button.waitForAnyPress();
   }


Also if it makes any difference I'm using caterpillar tracks.
jt18
New User
 
Posts: 2
Joined: Wed Mar 07, 2012 11:58 pm

Re: Measuring a distance using DifferentialPilot.getTravelSp

Postby skoehler » Mon Mar 12, 2012 11:36 pm

DifferentialPilot used to have a method called getTravelDistance(). However, it seems to be gone now.
I believe you have to use getMove().getDistanceTraveled(). But I'm not sure how to use it.
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Measuring a distance using DifferentialPilot.getTravelSp

Postby foliot » Mon Mar 26, 2012 2:02 am

If you still haven't gotten this ironed out, it would be p.getMovementIncrement() that you're looking for, which returns distance traveled since movement last started. The problem with your code is likely that it doesn't take acceleration into consideration, an error which would be significant at short distances but very small at large distances.
foliot
New User
 
Posts: 17
Joined: Fri Mar 16, 2012 10:21 pm


Return to NXJ Software

Who is online

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

more stuff