GyroSensor recalibrateOffset

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

Moderators: 99jonathan, roger, imaqine

GyroSensor recalibrateOffset

Postby ruperty » Tue Sep 17, 2013 7:16 pm

I have tried recalibrateOffset(), but it doesn't seem to affect readValue() as the doc says,

Samples the stationary (make sure it is) Gyro Sensor to determine the offset. Will reset the offset for ReadValue() to 0 (zero). Takes 5 seconds.


However, it does set getAngularVelocity() to zero. Should the above read,

Samples the stationary (make sure it is) Gyro Sensor to determine the offset. Will reset the offset for getAngularVelocity() to 0 (zero). Takes 5 seconds.


?
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby gloomyandy » Tue Sep 17, 2013 9:13 pm

Hi,
Hmm looking at the source:
https://sourceforge.net/p/lejos/code/HE ... ensor.java
I think I can see the issue there are actually two different types of calibration/offset in use here. Calling the recallibrateOffset method seems to zero the one used by readValue and set the one used by getAngularVelocity. Not totally convinced this is correct. I suspect the expectation is that you use recalibrateOffset only if you plan to use getAngularVelocity and not getValue...

Perhaps Lawrie or Kirk would care to comment.

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

Re: GyroSensor recalibrateOffset

Postby kirkpthompson » Wed Sep 18, 2013 2:01 pm

Hi All. I'll take a shot at this. I'm not able to dig in too deep right now but this is what I remember:

I added active offset calibration code to Lawrie's code. This uses some statistical analysis to determine the bias (offset) value based on a baseline taken when the gyro is static (motionless) for 5 seconds. From that baseline, when the stddev of a new sample falls within a specific range, that value is used to continually calc the offset since that value changes as the gyro heats up and resistance changes, etc. This has the effect of dynamically accounting for bias drift.

Apparently this did not work for Brian's segway so he added another way to set the offset that worked faster, not using dynamic offset calibration. You should also note that if a motor has not been "activated" before the gyro is calibrated, when a motor comes on, it's current draw changes the A/D value read from the Gyro which messes up the dynamic offset calc (done when using readValue()) since it shifts the read value (from the AVR) outside the baseline value too much.

Hope this helps.

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

Re: GyroSensor recalibrateOffset

Postby kirkpthompson » Wed Sep 18, 2013 2:09 pm

ruperty wrote:I have tried recalibrateOffset(), but it doesn't seem to affect readValue() as the doc says,

Samples the stationary (make sure it is) Gyro Sensor to determine the offset. Will reset the offset for ReadValue() to 0 (zero). Takes 5 seconds.


By "resetting the offset to 0", the javadoc means the offset that is used to adjust the value returned by readValue(). If the bias/offset value didn't change, the readValue() will not either.

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

Re: GyroSensor recalibrateOffset

Postby ruperty » Fri Nov 08, 2013 12:47 pm

Hi,

I have been looking into this further in order to understand what was going on with the gyro and the segoway demo. I was finding that the the gyro angle would increase from 0 to about -45 in the first 60 seconds of balancing.

Looking at the gyro values in a static situation, although after recalibrateOffset a call to getAngularVelocity returns a velocity of zero once in the main loop getAngularVelocity initially returns a value of about -2. This is consistent over many runs (and for recalibrateOffsetAlt).

Clearly a non-zero value would affect the gyro angle (time integral) adversely. I note that in the segoway code there is a correction to the velocity value with a smoothed offset,

Code: Select all
gOffset = EMAOFFSET * gyroRaw + (1 - EMAOFFSET) * gOffset;


The value of gOffset starts at -2 and moves to 0. However over this period the gyro angle moves from 0 to -45, even though the gyro doesn't move.

Although this offset correction is useful to correct the initial mismatch of the velocity reading a side-effect is that when the gyro is moved the new angle value is "corrected" back to the stabilisation value of -45, resulting in incorrect values for the angle.

Alternatively if I skip the calibration and set an offset of 587 then I get velocity readings of around 0. And if I avoid the offset smoothing then the gyro angle is reflected correctly.

Where does the offset of -2 come from?

Is there any benefit to using recalibrateOffset?
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby gloomyandy » Fri Nov 08, 2013 2:20 pm

Hi,
I assume the value of -2 is after the initial gyro calibration performed by the segoway? -45 degrees seems like a pretty big error to accumulate. I would have hoped that after the inital calibration there would not be that amount of drift.

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

Re: GyroSensor recalibrateOffset

Postby Aswin » Fri Nov 08, 2013 4:28 pm

Hi Rupert,

Which gyro do you use?
I know the analogue gyro from Hitechnic has issues with the offset as Kirk explained above. I also have seen some digital gyro's that have "spikes" in the signal, these spikes can ruin offset calculation.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 188
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: GyroSensor recalibrateOffset

Postby ruperty » Fri Nov 08, 2013 8:12 pm

gloomyandy wrote:Hi,
I assume the value of -2 is after the initial gyro calibration performed by the segoway? -45 degrees seems like a pretty big error to accumulate. I would have hoped that after the inital calibration there would not be that amount of drift.


Actually, after initial calibration the velocity gives 0, but in the main loop the readings are -2. It takes about a minute for gOffset to build up to -2 and correct the reading to 0. While this is going on because the velocity is non-zero the sum of (integral) the velocity adds up to -45.

In my earlier post I meant that "gOffset starts at 0 and moves to -2" rather than "gOffset starts at -2 and moves to 0"
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby gloomyandy » Fri Nov 08, 2013 8:52 pm

Does this impact the balance of the robot at all? I have the same gyro and that seems to work fine in terms of balancing. You may need to calibrate things a little longer to allow the offset to settle. It may also be down to the voltage drop when the motors are running. You may want to compare the battery voltage alongside the gyro reading and perhaps use that to compensate...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: GyroSensor recalibrateOffset

Postby ruperty » Fri Nov 08, 2013 9:08 pm

Hi Aswin,

Aswin wrote:Which gyro do you use?
I know the analogue gyro from Hitechnic has issues with the offset as Kirk explained above. I also have seen some digital gyro's that have "spikes" in the signal, these spikes can ruin offset calculation.

It's the HiTechnic sensor. I did try "activating" the motors but that didn't seem to have any effect.
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby ruperty » Fri Nov 08, 2013 9:18 pm

gloomyandy wrote:Does this impact the balance of the robot at all?


No, the balance is fine. Though as there is constant control error over the first minute the unit doesn't stay in the same position.

But what I am wanting to do is rely upon the gyroangle value, which I think I can get without the calibration or the smoothed offset.
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby gloomyandy » Fri Nov 08, 2013 9:27 pm

I'm not really sure how you will get a reliable angle if the offset is drifting (which it will do). You will need to adjust the offset over time. You may be able to use a fixed initial offset, but all in effect you are doing by using that is in effect using a longer period to establish calibration point.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: GyroSensor recalibrateOffset

Postby kirkpthompson » Sat Nov 09, 2013 5:45 pm

The auto-offset algorithm should take care of the drifting offset problem but there must be multiple subsequent time periods of non-movement for it to work. Like has been said or implied, I don't think you can rely upon the gyro angle value to do your balancing. The spikes and other signal weirdness will mess with the integration of the angle as well.

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

Re: GyroSensor recalibrateOffset

Postby ruperty » Tue Nov 19, 2013 6:13 pm

On investigating further I don't seem to find any drift, when the unit (gyro attached to robot) is not balancing. I can move the unit by about 90 degrees and back again and the angle returns to zero.

It is a different matter when the unit is balancing, though the drift doesn't appear to be consistent. For example, this image,

Image

shows periods of drift and non-drift (3 minutes).

Is this expected? Is there any explanation for this inconsistent drifting (if that is what it is)?
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: GyroSensor recalibrateOffset

Postby kirkpthompson » Tue Nov 19, 2013 7:35 pm

Hi ruperty.

From a post above:
This uses some statistical analysis to determine the bias (offset) value based on a baseline taken when the gyro is static (motionless) for 5 seconds. From that baseline, when the stddev of a new sample falls within a specific range, that value is used to continually calc the offset since that value changes as the gyro heats up and resistance changes, etc. This has the effect of dynamically accounting for bias drift.

My guess is since the bot is moving during the balancing (however so slightly it may be), the constantly calculated offset is creeping due to the design of the statistical sampling to use values that are assumed to be a motionless reading. Try to grok that code to make sense of what may be happening.

Best,
-K

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

Next

Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff