Using the HiTechnic gyroscope sensor to measure angles

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

Moderators: roger, imaqine, 99jonathan

janvos2506
Novice
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby janvos2506 » Thu Jul 05, 2012 4:03 pm

i did this

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?

User avatar
gloomyandy
leJOS Team Member
Posts: 4615
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby gloomyandy » Thu Jul 05, 2012 4:47 pm

Your update period is in milliseconds but your velocity is in degrees per second, so you need to convert the time period into seconds. So something like...
angle += degreesPerSecond*UpdatePeriod*0.001;
You may also need to change angle to be a float rather than an int.

janvos2506
Novice
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby janvos2506 » Thu Jul 05, 2012 5:16 pm

okay i tried that but it still just goes from a value bcd to 0 when i turn it...
i just want the same thing this guy has with the gyroscope
http://www.youtube.com/watch?v=WCTdTN7qPOg

User avatar
kirkpthompson
leJOS Team Member
Posts: 305
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby kirkpthompson » Thu Jul 05, 2012 8:19 pm

Leg Godt!

janvos2506
Novice
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby janvos2506 » Fri Jul 06, 2012 10:50 am

Thank you!!
i got it working now !!
i just used bits of code from the direction finder thingy and i got it working now :)
im so happy right now thank you all !!

Ralf
New User
Posts: 11
Joined: Fri Jan 16, 2015 4:30 am

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Ralf » Wed Apr 29, 2015 9:45 pm

I too am using the HiTechnic gyroscope and noticed that the recalibrateOffset() function takes far far longer than just 5 seconds. More around 30+ seconds.

Code: Select all

public static void main(String [] args) throws Exception {
     GyroSensor gyro = new GyroSensor(SensorPort.S1);

     while(true) {
        gyro.recalibrateOffset();
        System.out.println(gyro.readValue());
     }
  }


That is what I was trying. I'm running leJOS 0.9.1beta.

Also, it seems that using a Gyroscope is not a very good way to measure angles? I used GyroSensor in combination with GyroDirectionFinder to get an angle and turning around in circles and driving for like 30 seconds will often already give me a difference of 30° to what it should actually be. I'm not sure what it is. Maybe due to the offset drift. I only stationary calibrate once at the beginning and then leave it at that, since it takes so long.

Aswin
leJOS Team Member
Posts: 227
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Aswin » Thu Apr 30, 2015 6:30 am

Hi,

There is no GyroSensor class in leJOS 0.9.1beta. For the EV3 the preferred way to integrate gyro output to angle is described in this blog post https://lejosnews.wordpress.com/2014/06 ... om-a-gyro/
All you need to do is to apply two standard filters, the OffsetCorrectionFilter and the IntegrationFilter. The OffsetCorrectionFilter is applied first. The IntegrationFilter comes second. The OffsetCorrectionFilter uses advanced statistics to continuously update the offset error. There is no need to instruct it to recalculate it. You only have to make sure that the sensor is motionless during the first few reads ( >15 ) from the sensor.



Aswin
My NXT blog: http://nxttime.wordpress.com/

Ralf
New User
Posts: 11
Joined: Fri Jan 16, 2015 4:30 am

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Ralf » Thu Apr 30, 2015 10:08 pm

There is no GyroSensor class in leJOS 0.9.1beta

That is weird. I never had a different version.

Thanks, I'll have a look at that. Hope it works as well on the NXT.

skoehler
leJOS Team Member
Posts: 1533
Joined: Thu Oct 30, 2008 4:54 pm

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby skoehler » Thu Apr 30, 2015 10:45 pm

http://www.lejos.org/nxt/nxj/api/lejos/ ... ensor.html

There is a GyroSensor class in leJOS NXJ. Aswin was, for some reason, talking about leJOS EV3.

Aswin
leJOS Team Member
Posts: 227
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Aswin » Thu Apr 30, 2015 11:26 pm

Yes Skoehler is right. Sorry for the confusion.

To my experience to offset for the Hitechnic gyro is not (more or less) constant. It changes when I use the motors. There is an old blog post about that in my personal blog (see below).
This is a problem that is hard to deal with.
I have not seen the problem with any of the Digital gyro's I used.
My NXT blog: http://nxttime.wordpress.com/

Ralf
New User
Posts: 11
Joined: Fri Jan 16, 2015 4:30 am

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Ralf » Fri May 01, 2015 8:02 pm

Thanks, I'll have a look at that too and try some things.

Ralf
New User
Posts: 11
Joined: Fri Jan 16, 2015 4:30 am

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Ralf » Fri May 08, 2015 7:24 am

Aswin wrote:I have not seen the problem with any of the Digital gyro's I used.


Like the Dexter Industries IMU which you tested? Or is there another one you would recommend for the NXT? The Dexter Industries IMU seemed to perform well.

Aswin
leJOS Team Member
Posts: 227
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: Using the HiTechnic gyroscope sensor to measure angles

Postby Aswin » Fri May 08, 2015 5:49 pm

The Dexter IMU is fine. I assume the Absolute IMU from MindSensors is fine too, but I haven't tested that one personally.
My NXT blog: http://nxttime.wordpress.com/


Return to “NXJ Software”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest