Recording the car route.

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

Moderators: roger, 99jonathan, imaqine

Recording the car route.

Postby nilton » Wed Sep 26, 2012 10:41 pm

Hi, I'm new at forum and at LeJOS. I need some help, my project is to make a route with a simple car with 2 motors. And my program try to record the angles that motors does in 20 seconds. After that i just play and the car does the same route. But it is not working so good...
Here are my codes if any have an idea, to help thanks.

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;

   /**
    * @Autor Nilton Mendes
    */
public class Refaz {

   public static void main(String[] args) throws InterruptedException {
      Motor.A.resetTachoCount();
      Motor.B.resetTachoCount();
      
      Motor.A.flt(true);
      Motor.B.flt(true);
      
      int i = 0;
      int[] posicoes = new int[60];
      int[] posicoes2 = new int[60];
      LCD.drawString("Inicio da gravacao.\nAperte ENTER para inciar.", 0, 0);
      LCD.refresh();
      Button.ENTER.waitForPress();
      LCD.drawString("Gravando.", 0, 2);
      
      while(i < 20){
         posicoes[i] = Motor.A.getTachoCount();
         posicoes2[i] = Motor.B.getTachoCount();
         System.out.println(i);
         Thread.sleep(1000);
         i++;
         
      }
      
      i=0;
      LCD.clear();
      LCD.drawString("Aperte o botao do\ncentro para retornar.", 0, 0);
      LCD.refresh();
      Button.ENTER.waitForPress();
      Motor.A.resetTachoCount();
      Motor.B.resetTachoCount();
      //Motor.A.rotateTo(inicio1);
      //Motor.B.rotateTo(inicio2);
      
      Threads t1 = new Threads(posicoes, Motor.A);
      Threads t2 = new Threads(posicoes2, Motor.B);
      t1.start();
      t2.start();
      
      System.out.println("Fim. Aperte Escape para restornar.");
      Button.ESCAPE.waitForPress();
   }

}


And i used threads to use the method "rotateTo" with the 2 motors at the same time (was the idea..)..

Code: Select all
import lejos.nxt.NXTRegulatedMotor;

public class Threads extends Thread {
   private int[] posicoes;
   private NXTRegulatedMotor x;
   public Threads(int[] posicoes, NXTRegulatedMotor x){
      this.posicoes = posicoes;
      this.x = x;
      this.x.setSpeed(200);
   }
   public void run() {
      int i = 0;
      
      while(i < 20){
         x.rotateTo(posicoes[i]);
         i++;
         System.out.println(posicoes[i]);
         
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
   }
}

Thanks.. 8)
Last edited by nilton on Thu Sep 27, 2012 2:00 am, edited 1 time in total.
nilton
New User
 
Posts: 2
Joined: Tue Sep 25, 2012 7:57 pm

Re: Record the track.HELP.

Postby halfbit » Thu Sep 27, 2012 1:10 am

What doesn't work well?
As I understand it you want to just move the nxt and it should record the movement, then it should drive the same way again, right? What happens instead of that ie what's wrong?
halfbit
New User
 
Posts: 4
Joined: Wed Sep 26, 2012 8:37 am

Re: Record the track.HELP.

Postby nilton » Thu Sep 27, 2012 1:46 am

The car always not go on the route that i did... The motors run separately of another, the curves are not good..
nilton
New User
 
Posts: 2
Joined: Tue Sep 25, 2012 7:57 pm

Re: Recording the car route.

Postby roger » Fri Sep 28, 2012 6:37 am

Lejos has some high level classes for controlling 2 wheeled vehicles that might be useful for your project. Take a look at DifferentialPilot , Navigator and OdometryPoseProvider.
roger
Moderator
 
Posts: 308
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 6 guests

more stuff