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..
