i did somethink like this.
- Code: Select all
import lejos.util.Timer;
import lejos.util.TimerListener;
import lejos.nxt.*;
import lejos.nxt.addon.GyroSensor;
public class Gyro2 {
static GyroSensor gs;// = new GyroSensor(SensorPort.S3);
static double g, tita = 0, tita_ant, w = 0, w_ant=0 ,T = 0, T_ant, deltaT;
static Timer Tiempo = new Timer(1,new TimerListener(){
public void timedOut() {
T++;
}
});
public static void main(String Arg[]) throws Exception{
gs = new GyroSensor(SensorPort.S3);
gs.setOffset(575);
Tiempo.start();
while(!Button.ENTER.isPressed()){
w_ant = w;
w = gs.readValue();
if(w<4 && w>-4)
w = 0;
deltaT = (T-T_ant);
T_ant= T;
tita = tita_ant + (w-w_ant)*(deltaT);
//tita = (tita_ant + w_ant*(deltaT) + 0.5 * ((w-w_ant)/(deltaT))*(deltaT * deltaT));
while(tita>=360 || tita<0)
{
if(tita>=360)
tita -= 360;
if(tita<0)
tita += 360;
}
if(Button.ESCAPE.isPressed())
tita = 0; //reset the angle
tita_ant = tita;
LCD.drawString("Gyro: " + w, 0, 5);
LCD.drawString("Angle: " + tita, 0, 7);
LCD.drawString("Tiempo: " + deltaT, 0, 3);
}
Tiempo.stop();
}
}
this is not accurate. someone can help me.
