- Code: Select all
import java.io.*;
import lejos.nxt.*;
import lejos.nxt.addon.GyroSensor;
import lejos.nxt.comm.*;
import lejos.util.Timer;
import lejos.util.TimerListener;
public class Angle {
static GyroSensor gyro;
static float degreesPerSecond;
static int angle;
static int UpdatePeriod = 10;
public static void main(String [] args) throws Exception {
gyro = new GyroSensor(SensorPort.S1);
gyro.recalibrateOffset();
while(true)
{
degreesPerSecond = gyro.getAngularVelocity();
angle += degreesPerSecond*UpdatePeriod;
System.out.println(angle);
Thread.sleep(UpdatePeriod);
}
}
}
i used the recalibrateOffset thingy
and this gives me values that adds up like i turn it and then it goes from 0 to 3000 or something and then slowly goes back to 0 ?
i never knew it was so hard to get the actually angle can someone help me with what i am doing wrong?
