Using the HiTechnic gyroscope sensor to measure angles

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

Moderators: 99jonathan, roger, imaqine

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?
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

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.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4240
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

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
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the HiTechnic gyroscope sensor to measure angles

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

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

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 !!
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Previous

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff