Using a gyro to measure rotation

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

Moderators: 99jonathan, roger, imaqine

gyro

Postby sebalitter » Sun Feb 20, 2011 10:08 pm

Hi, i want to use the gyro sensor to display the angle in degrese, just like a compass

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.
sebalitter
New User
 
Posts: 20
Joined: Mon Feb 02, 2009 10:32 pm
Location: Argentina

Postby kirkpthompson » Sun Feb 20, 2011 11:20 pm

Try searching for "gyro". There are lots of posts concerning gyroscopes. I am working on a GyroSensor class that will provide a relative angular vector. An old post is at http://lejos.sourceforge.net/forum/viewtopic.php?t=708

-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

how to use lejos.nxt.GyroSensor in 0.85

Postby sebalitter » Mon Feb 21, 2011 2:10 am

thanks for the info kirkpthompson, and for the development this is exactly what i was searching.

i have 0.85 lejos but the class to calculate the heading with gyro is in release 0.5 lejos. how can i do to use this class?

thanks.
sebalitter
New User
 
Posts: 20
Joined: Mon Feb 02, 2009 10:32 pm
Location: Argentina

Postby kirkpthompson » Tue Feb 22, 2011 3:13 pm

I don't have the [new] class released yet. The first one should work with 0.85, it just has some accuracy problems. It will at least give you an idea of how I approached the drift problem.

-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Using a gyro to measure rotation

Postby Coppola » Mon Oct 17, 2011 12:55 pm

Thanks to your posts i could solve my issue. You got a rather detailed report.thanks for letting me know it.:) levitra online
Last edited by Coppola on Thu Dec 22, 2011 6:22 am, edited 1 time in total.
Coppola
New User
 
Posts: 2
Joined: Mon Oct 17, 2011 12:53 pm

Re: Using a gyro to measure rotation

Postby Marteria » Wed Oct 26, 2011 11:26 am

Thanks for the advise, it saved me loads of time and money.A lot of people will be benefited from your writing. I have a presentation incoming week, and I am on the lookout for such information.
Cheers! :)
Marteria
New User
 
Posts: 1
Joined: Wed Oct 26, 2011 11:24 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff