View unanswered posts | View active topics It is currently Sat Jan 19, 2019 5:19 am

Reply to topic  [ 3 posts ] 
Pikachu is cool 
Author Message

Joined: Tue Jan 31, 2012 11:02 am
Posts: 1
Post Pikachu is cool
Edit: Thread is closed

Last edited by Chaud on Wed Mar 21, 2012 12:23 pm, edited 1 time in total.

Tue Jan 31, 2012 11:06 am
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Gyro XV 3500CB angular rate sensor + PIC need some help
I've never worked with that specific sensor, so I don't know if I can help you with getting more accurate values, but I can try and answer some of your questions.
Chaud wrote:
And another question, if i rotate gyro to right , for example imagine i get 1,39V, but when hes stable again he backs to 1,34V, for what i read from gyroscopes isnt suposed to maintain 1,39V till gyro get back to original position (1,34V) ??

A gyroscope measures angular rate, so it has no idea what position it is at. It can only tell you how fast you're turning it. So when you turn it right, it will inform you that it is turning, and when you stop moving it, it will tell you that it is stopped. The gyro cannot tell the difference between being stopped at 0 degrees and being stopped at 90 degrees. The only way to determine angular position is to write your own program to integrate the gyro values and determine where the sensor is pointing.
You said that you have trouble getting consistent and accurate values. It is very hard to turn the gyro at the same angular velocity every time. Perhaps that is the source of your error?
As for not getting any value change when turning slowly, that sound like a threshold issue. Is there any way to change the threshold on that specific sensor, like a jumper or something?

sudo rm -rf /

Tue Jan 31, 2012 11:24 am
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 409
Post Re: Gyro XV 3500CB angular rate sensor + PIC need some help
This is a program that simulates how we poll the official VEX Gryo. You will probably need to do some tweaking, but it should help:

#pragma config(Sensor, in3,    gyro,           sensorGyro)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//                                                         Gyro Driver Test
// This program emulates the gyro value calculation of ROBOTC's internal driver. It only emulates the value calculation.
// It does not emulate the calculation of the bias values and relies upon the value calculated by the internal driver.
// When gyro driver starts up, it first calculates the internal bias value. The bias value is the analog value output
// by the gyroscope while it is perfectly still. The steps to calculate the bias.
// 1. Delay for 200 milliseconds. This is to allow the gyro to stabilize when it is first powered up. The datasheet
//    indicates that this may take 50 milliseconds so we'll run it a little longer.
// 2. Measure the analog value every 0.001 seconds and calculate the sum over 1024 samples.
// 3. The bias can be calculated. Take the sum from (2) and divide by 1024.
// 4. Normally the remainder from (3) is non-zero. The remainder term is called the "small bias" by ROBOTC firmware.
// 5. Driver is now ready to calculate the gyro value.
// The gyro does not output an analog value representing angular position. Instead the value represents angular velocity.
// To calculate angular position, you have to integrate periodically measured samples. The internal ROBOTC driver does
// this is follows:
// 1. Every millisecond it sums the "difference" of the current analog gyro value with the calculated bias value. This
//    effectively integrates the gyro velocity values into a gyro rotation value.
// 2. In (4) above there was a residual error (i.e. the small bias) calculated. So on every 1024 sums, the 'small bias'
//    is subtracted from the accumulated sum.
// 3. When user application program requests the gyro value, the accumulated sum is divided by the 'SensorScale' setting
//    to scale the result in tenths of a degree.
// 4. The analog gyro value has a lot of jitter; i.e. if the bias value is 1823 then the analog readings on a non-moving
//    gyro may be 1820 to 1826. The jitter does not appear to be uniformly distributed around the bias value. So the driver
//    has a "jitter filter" to ignore analog values that are within '4' (see '#define' for 'kJitterIgnoreRange') of the
//    bias value. This eliminates the
// 5. Even with point (4) above, there is a small drift in the gyro. This is typical of these gyro ICs. Over several minutes
//    the gyro value range -15 to +15 degrees (i.e. value of 150 in tenths of a degree) .
long nNumbOfADCConversionCycles = 0; // Performed by special debugging hook in firmware

long nCycles = 0;
long nElapsedTime;

long nFilteredRawValueSum = 0;

long nGyroValue;
volatile long nFilteredRawValue;
long nNonJitterCycles = 0;

typedef enum
} TCountsIndices;

long nGyroRawAnalogValue;
long nGyroBias;
long nSensorSmallBias; // Performed by special debugging hook in firmware
long nGyroSensorScale;
long nGyroFullCount;
long nCounts[(TCountsIndices) 13];
short nMaxValueCurr10Seconds;
short nMinValueCurr10Seconds;
short nPrev10SecondTime = -1;
short nCurr10SecondTime;
const int kHistogramSize = 600;
short nMaxValues[kHistogramSize];
short nMinValues[kHistogramSize];
long nLoopStartTime;
long nPrevTime;
long nCurrTime;

const int kJitterIgnoreRange = 4;

task main()
   // Firmware retains sensor type setting between invocations of program. Explicitly setting to 'sensorNone' and
  // then back to 'sensorGyro' will explicitly force the firmware driver to recalculate the biase settings. Which
  // you may want to do via the Debugger's "STOP" and "START" buttons.

  SensorType[gyro] = sensorNone;
  SensorType[gyro] = sensorGyro;

  memset(&nCounts[0], 0, sizeof(nCounts));
  memset(&nMaxValues, 0, sizeof(nMaxValues));
  memset(&nMinValues, 0, sizeof(nMinValues));
  nNumbOfADCConversionCycles = 0;
  nFilteredRawValueSum = 0;
  while (SensorBias[gyro] == 0)
  SensorValue[gyro] = 0;

  nGyroBias           = SensorBias[gyro];
  nSensorSmallBias    = SensorSmallBias[gyro];
  nGyroSensorScale    = SensorScale[gyro];
  nGyroFullCount      = SensorFullCount[gyro];

  nLoopStartTime = nPgmTime;
  while (true)
    short nDifference;
      nGyroValue          = SensorValue[gyro];
    nGyroRawAnalogValue = getSensorRawADValue(gyro);

    nDifference         = nGyroRawAnalogValue - nGyroBias;
    if ((nDifference < -kJitterIgnoreRange) || (nDifference > +kJitterIgnoreRange))
      nFilteredRawValueSum += nDifference;
       if ((nNonJitterCycles % 1024) == 0)
         nFilteredRawValueSum -= nSensorSmallBias;
     if (nDifference < -6)
       nDifference = -6;
     else if (nDifference > +6)
       nDifference = +6;
     ++nCounts[bias + nDifference];

    nFilteredRawValue   = nFilteredRawValueSum / nGyroSensorScale;

    // Calculate statistics and value histogram

      nCurrTime = nPgmTime;
      nElapsedTime        = nCurrTime - nLoopStartTime;
      nCurr10SecondTime      = nElapsedTime / 10000;
      if (nCurr10SecondTime != nPrev10SecondTime)
         if (nPrev10SecondTime >= 0)
            nMaxValues[nPrev10SecondTime] = nMaxValueCurr10Seconds;
            nMinValues[nPrev10SecondTime] = nMinValueCurr10Seconds;
         nMaxValueCurr10Seconds = nGyroValue;
         nMinValueCurr10Seconds = nGyroValue;
      if (nGyroValue > nMaxValueCurr10Seconds)
         nMaxValueCurr10Seconds = nGyroValue;
      else if (nGyroValue < nMinValueCurr10Seconds)
         nMinValueCurr10Seconds = nGyroValue;
      nPrev10SecondTime = nCurr10SecondTime;

      while (nCurrTime == nPrevTime)
        nCurrTime = nPgmTime;
      nPrevTime = nCurrTime;

Jesse Flot
CMU Robotics Academy
ROBOTC Support

Mon Feb 06, 2012 11:44 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.