ROBOTC.net forums
http://www.robotc.net/forums/

Gyro Senosr
http://www.robotc.net/forums/viewtopic.php?f=52&t=2804
Page 2 of 3

Author:  mightor [ Sun Dec 05, 2010 11:43 am ]
Post subject:  Re: Gyro Senosr

No, the Gyro is an analogue sensor, there is *no* I2C involved, of any kind, at all :)

The NXT has a digital (I2C) interface -and- an (two, actually) analogue interface. This sensor makes use of the analogue interface.

- Xander

Author:  MHTS [ Mon Dec 06, 2010 4:02 am ]
Post subject:  Re: Gyro Senosr

Thanks for the clarification. That's what I suspect. The RJ connector isn't just for I2C but has analog pins as well. So the inaccuracy isn't the gyro firmware but the NXT firmware because the NXT firmware is the one who reads the raw A/D and translates it to degrees/sec in integer. If that's the case, doesn't NXT have a raw sensor mode (raw value) where I don't tell NXT what kind of sensor it is and just ask for the raw value from the A/D? (The equivalent of SensorRaw[]). I am sorry about being ignorant on the internals of NXT, just curious on how this works.

Author:  mightor [ Mon Dec 06, 2010 4:10 am ]
Post subject:  Re: Gyro Senosr

The AD conversion is done by the NXT hardware, all the firmware does is read the raw value from this. There really is nothing more raw than the raw AD value. No conversion is done.

- Xander

Author:  MHTS [ Mon Dec 06, 2010 11:16 pm ]
Post subject:  Re: Gyro Senosr

So you are saying the raw value is in the unit of degrees/sec as an integer in the range of 0-1023? If that's the case, it is a very coarse and inaccurate gyro. (i.e. The gyro resolution is 1 degree/sec). The FRC gyro is spec'd at a resolution of 0.69 degree/sec.

Author:  mightor [ Tue Dec 07, 2010 2:17 am ]
Post subject:  Re: Gyro Senosr

I believe the gyro is spec'd at about 300 degrees per second max. The value the gyro returns is the number of degrees per second + offset (around 620).

- Xander

Author:  Aswin [ Tue Dec 07, 2010 4:22 am ]
Post subject:  Re: Gyro Senosr

Coarse and inaccurate, the gyro?

First, it is not the gyro that determines how coarse the readings are. It is the NXT, as it is the NXT that does the conversion to digital values. All analogue sensors on the NXT will have readings between 0 and 1023.

Second. Using values between 0 and 1023 and a unit of degrees a second will tell you The difference between something that is rotating 1000 full circles an hour and something that is rotating at a rate of 10012 circles an hour. Or 1 extra rotation each five minutes. Or speed differences as small as 0,1 %. As minimum and maximum output values are fixed between 0 and 1023 there is a trade of between resolution and range. This goes for all analogue sensors. So the other sensor must have a smaller range :-)

Third. Accuracy has nothing to do with coarseness. If I tell you that one liter of water weights 1 kilogram I am very accurate but nor very precise. If I state it weights 678.321 gram I am very precise but also very wrong. It is up to you to make the gyro accurate by interpretating it's readings well.

Fourth. The 0-1023 scale limits the coarseness of your readings. But this limit is not fixed. If you take the average of more readings you can decrease coarseness.

So stop nagging about this sensor. Try to understand it and it's limitations. Do they really bother you to reach your goals? Or are there other limitations in your system (robot, sensors, software) that bother you first. Then try to solve the problem that bothers you most. I can assure you it won't be the gyro.

Author:  MHTS [ Tue Dec 07, 2010 1:25 pm ]
Post subject:  Re: Gyro Senosr

Didn't mean to nag :). I was just curious on how it works. I have a better picture now.

Thanks.

Author:  karan.hiremath [ Sat Jan 08, 2011 8:40 pm ]
Post subject:  Re: Gyro Senosr

I haven't personally seen any issues with the Gyro sensor... it seems to work perfectly fine for me... i have it doing perfect 90 degree turns with a small buffer (1-2 degrees, based on how well the robot im using turns)

Here is the code i'm using (currently for a robot using an SMUX):
Code:
/*
Function Name- getGyroData();

Purpose - read data from a HiTechnic Gyroscopic Sensor

Notes:
When using, be sure to initalize the Gyroscopic sensor using HTGYROstartCal() (in initializeRobot())
Make sure to name gyroscopic sensor "HTGYRO" or "msensor_S2_1"
*/
float getGyroData()
{
  float heading = 0.0;
  long currTime;
  long prevTime = nPgmTime;

  currTime = nPgmTime;
  heading += ((float)HTGYROreadRot(msensor_S2_1))*(currTime - prevTime)/1000;      // Integrate values from the gyroscopid sensor
  prevTime = currTime;                                                             //
  return heading;
}

/*
Function Name- gyroTurn

Purpose - turn using a HiTechnic Gyroscopic Sensor

Arguments:
target = # of degrees to turn
buffer = # of degrees to buffer +- the target, prevents "wiggle"
power = motor power of the turn
leftMotor = name of the motor on the left
rightMotor = name of the motor on the right
HTGYRO = name of the Gyroscopic sensor to use

Notes:
When using, be sure to initalize the Gyroscopic sensor using HTGYROstartCal(HTGYRO)
Make sure to name gyroscopic sensor "HTGYRO"
*/
void gyroTurn(long target, long buffer, int power, long leftMotor, long rightMotor)
{
  while(true)
  {
    float heading = getGyroData();                                                   // Read Gyroscopic sensor

    if(heading < (target - buffer))                                                  // LOGIC- If to the right of target, turn left
    {                                                                                //
      motor[leftMotor] = power;                                                      //
      motor[rightMotor] = -power;                                                    //
    }else if(heading > (target + buffer))                                            // LOGIC- If to the left of target, turn right
    {                                                                                //
      motor[leftMotor] = -power;                                                     //
      motor[rightMotor] = power;                                                     //
    }else if(heading < (target + buffer) && heading > (target - buffer))             // LOGIC- If within the buffer zone, stop
    {                                                                                //
      motor[leftMotor] = 0;                                                          //
      motor[rightMotor] = 0;                                                         //
      return;                                                                        // Exit the function
    }
  }
}

Author:  MHTS [ Sat Jan 08, 2011 8:55 pm ]
Post subject:  Re: Gyro Senosr

The gyro is working fine for me now because I have written a calibration routine that will determine the bias as well as the noise level so that I can compensate for them. It is running straight and turning perfect 90 for me.

Author:  karan.hiremath [ Sat Jan 08, 2011 9:07 pm ]
Post subject:  Re: Gyro Senosr

I'm using HTGyroStartCal(); to calibrate and as far as determining the noise, could you show how you did this? Sounds interesting

are you basically taking a series of values while sitting still and averaging them? i was thinking of doing that but didn't see a need to. Is there a particular reason you are doing so? I found a buffer to be ideal for the situations we are using them for, as we are also using line tracking which will make us relatively at the right orientation when at the bridge, and then i have the robot align itself to the line across the bridge.

Author:  MHTS [ Sun Jan 09, 2011 4:49 pm ]
Post subject:  Re: Gyro Senosr

Averaging the gyro readings will give you the bias. For determining the noise level, you also determine the max and min readings while the robot sit still. I double that range as my deadband range.

Here is our gyro code.
http://proj.titanrobotics.net/hg/Ftc/20 ... lib/gyro.h

We are using the gyro to calculate our heading. Since gyro gives you turn rate, we need to integrate it against time to get the heading. The gyro noise will cause the integration to cumulate error. In other words, the heading will drift even if the robot is not moving. Therefore, you must determine the noise range and make it into a deadband.

Author:  mightor [ Tue Jan 25, 2011 5:25 am ]
Post subject:  Re: Gyro Senosr

The gyro is an analogue sensor. If you want to know what it looks like on the inside, check out this article on my blog: [LINK]. There is only one chip on there and it's the sensor. It does not use an I2C interface (I know this for a fact because I wrote a driver for it).

- Xander

Author:  zerroTC [ Wed Dec 19, 2012 10:12 am ]
Post subject:  Re: Gyro Senosr

This code every time when you call getGyroData() return zero, becouse (currTime - prevTime)==0.
And on my robot i have inif loop.

Code:
Code:
/*
Function Name- getGyroData();

Purpose - read data from a HiTechnic Gyroscopic Sensor

Notes:
When using, be sure to initalize the Gyroscopic sensor using HTGYROstartCal() (in initializeRobot())
Make sure to name gyroscopic sensor "HTGYRO" or "msensor_S2_1"
*/
float getGyroData()
{
  float heading = 0.0;
  long currTime;
  long prevTime = nPgmTime;

  currTime = nPgmTime;
  heading += ((float)HTGYROreadRot(msensor_S2_1))*(currTime - prevTime)/1000;      // Integrate values from the gyroscopid sensor
  prevTime = currTime;                                                             //
  return heading;
}

/*
Function Name- gyroTurn

Purpose - turn using a HiTechnic Gyroscopic Sensor

Arguments:
target = # of degrees to turn
buffer = # of degrees to buffer +- the target, prevents "wiggle"
power = motor power of the turn
leftMotor = name of the motor on the left
rightMotor = name of the motor on the right
HTGYRO = name of the Gyroscopic sensor to use

Notes:
When using, be sure to initalize the Gyroscopic sensor using HTGYROstartCal(HTGYRO)
Make sure to name gyroscopic sensor "HTGYRO"
*/
void gyroTurn(long target, long buffer, int power, long leftMotor, long rightMotor)
{
  while(true)
  {
    float heading = getGyroData();                                                   // Read Gyroscopic sensor

    if(heading < (target - buffer))                                                  // LOGIC- If to the right of target, turn left
    {                                                                                //
      motor[leftMotor] = power;                                                      //
      motor[rightMotor] = -power;                                                    //
    }else if(heading > (target + buffer))                                            // LOGIC- If to the left of target, turn right
    {                                                                                //
      motor[leftMotor] = -power;                                                     //
      motor[rightMotor] = power;                                                     //
    }else if(heading < (target + buffer) && heading > (target - buffer))             // LOGIC- If within the buffer zone, stop
    {                                                                                //
      motor[leftMotor] = 0;                                                          //
      motor[rightMotor] = 0;                                                         //
      return;                                                                        // Exit the function
    }
  }
}

Author:  MHTS [ Thu Dec 20, 2012 5:19 am ]
Post subject:  Re: Gyro Senosr

zerroTC wrote:
This code every time when you call getGyroData() return zero, becouse (currTime - prevTime)==0.
And on my robot i have inif loop.

Please remember the NXT can run really fast. nPgmTime has a resolution of 1 msec. This is a long time for the processor. It allows your infinite loop to run multiple times before nPgmTime advances to the next msec. Therefore, when you do integration, you need to add a wait1Msec(LOOP_PERIOD) in your infinite loop where LOOP_PERIOD should be substantially > 1 (e.g. 10 or more).

Author:  zerroTC [ Thu Dec 20, 2012 9:02 am ]
Post subject:  Re: Gyro Senosr

MHTS wrote:
zerroTC wrote:
This code every time when you call getGyroData() return zero, becouse (currTime - prevTime)==0.
And on my robot i have inif loop.

Please remember the NXT can run really fast. nPgmTime has a resolution of 1 msec. This is a long time for the processor. It allows your infinite loop to run multiple times before nPgmTime advances to the next msec. Therefore, when you do integration, you need to add a wait1Msec(LOOP_PERIOD) in your infinite loop where LOOP_PERIOD should be substantially > 1 (e.g. 10 or more).

Thanks for information. I concluded that when i strat playing with above code.
I can not found a good solution and i am working on that 3 days. If you have code for gyro sensore to navigate the robot with out drifts and errors, i will appreciate it?
Thanks.

Page 2 of 3 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/