Maker Pro
Maker Pro

Calculating gyroscope turn regardless of angle

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
Hi,

I am using an electronic gyroscope and accelerometer and I want to calculate the degrees the device has turned regardless of any angle changes whilst it is turning. So for example with the Z gyroscope I can calculate a 90 degree turn accurately, but of course when I tilt the device, the Z gyroscope readings slow down relative to the angle. The steeper the angle the slower the readings. I guess tilt compensation is possible using trigonometry, but I have tried various things and I have not been able to get it right.

I want to be able to measure the degrees turned around a particular axis regardless of how the device is tilting during that turn.

I have also tried summing all the X, Y and Z values together, which might work but the gyroscope values change during any angle change, and that is added to the equation.

any ideas?

thanks
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
any ideas?

Mathematics and coordinate transformation.

You need to calculate the initial and final orientation in space, and then determine the amount of rotation about one axis has occurred.

If the axis through which you are measuring rotation has shifted (i.e. no longer points in the same direction) then you need to define what rotation around that axis actually means.

You might consider the following... If the axis of rotation shifts, then it will have rotated through some axis. This axis will be parallel with lines passing through the XY plane of the object and intersecting the axis of rotation both before and after the rotation. You could compare these lines against the object and describe the difference as the rotation of the object.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
OK.

Assuming a setting of 2000 dps when the MPU is flat (X acceleration = 0, Y acceleration = 0, Z acceleration = 1) when it is tilted on the X axis by 45 degrees, will the Z gyro output now be effectively 1000 dps?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
So do what I suggest.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
So do what I suggest.
Thanks, but I do not understand what is required. I thought perhaps cosine might be relative. At 45 degrees pitch the relevant gyro output is halved, but the cosine of 45 degrees is 0.707. I don't know how I use that to produce a doubling of the output.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Your gyros will give you an amount of rotation in the X, Y, and Z axis,

If the z axis is vertical (so the axis of rotation is along the Z axis, all you need to do is look at the rotation about the Z axis.

If you tilt the axis of rotation (and let's say the tilt is in the 90 degrees in the ZX plane), rotation will now be seen as rotation in the X axis (and it will be negative if the tilt is -90 degrees.)

A tilt between 0 and 90 degrees will result in the rotation being seen partially in the Z and partially in the X axis. The rotation through the Y axis can be ignored.

A tilt in the ZY plane is similar. The rotation will be measured partially in the Z and Y axies, and the rotation in the X axis can be ignored.

The more general case of tilt that is not aligned to either the ZX or ZY plane is more complex because the rotation is partially in all three axies, and the tilt is in two axies.

You need to do some 3D geometry to subtract the tilt from the rotation, leaving the rotation in the z axis.

If you look here you will find some information that will help. try to understand the 2D stuff before you go on to the 3D.

Here is a worked answer.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
I see. thanks. I understand that tilt will affect the gyro output. Assuming the tilt is 45 degrees in the ZX plane, then the Z gyro output will be halved, correct?, and the X gyro will be outputting the same as the Z gyro.

The resources look good, but beyond my ability in the short term, and maybe the long term.

Is there a simple mathematical relationship when the tilt is only on the ZX or ZY planes.

"subtract the tilt from the rotation"

I have the tilt and I have the gyro Z output. What is the mathematical relationship or formula for adjusting the gyro output as the tilt changes.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
I expect it would be Zr cos Yr + Xr sin Yr for an axis remaining in the ZX plane, but shifted in the Y axis by Yr.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
I expect it would be Zr cos Yr + Xr sin Yr for an axis remaining in the ZX plane, but shifted in the Y axis by Yr.
Zr cos Yr + Xr sin Yr
is that Zr = cos(Yr) + Xr * sin(Yr)?

or Zr =( Zr * cos(Yr)) + (Xr * sin(Yr))
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The later, a cos on its own wouldn't do you to much good.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
OK so assuming it is flat (acceleration x and y = 0, Z = 1) and outputting 200 dps around the Z axis. When it is tilted 45 degrees on the Y axis, there will be 100 dps around the Z axis and 100 dps around the Y axis, correct?

So the formula Zr =( Zr * cos(Yr)) + (Xr * sin(Yr)) gives

Zr = (100 * cos(100)) + (0 * sin(100) = -17

What am I doing wrong?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Cos 45 and sin 45. These functions work on angles!

I'm not saying that is the correct formula, you need to look up how to do those transformations yourself. The web site I have you send to have code examples.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
OK, so it becomes this

OK so assuming it is flat (acceleration x and y = 0, Z = 1) and outputting 200 dps around the Z axis. When it is tilted 45 degrees on the Y axis, there will be 100 dps around the Z axis and 100 dps around the Y axis, correct?

So the formula Zr =( Zr * cos(Yr)) + (Xr * sin(Yr)) gives

Zr = (100 * cos(45)) + (0 * sin(45) = 70.7

is that correct?

Can I get an answer to the following question please ->
An output of 200 dps is measured on the Z gyro output when the MPU is flat (X acceleration = 0, Y acceleration = 0, Z acceleration = 1) and rotating around the Z axis. When it is tilted on the Y axis by 45 degrees, will the Z gyro output now be effectively halved at 100 dps, and the Y gryo will also be outputting 100dps. I mean is it half, or is it 0.707?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You have asked them distinct questions.

The first was for a rotation in space with a Tillie's axis.

The second is to calculate the speed of rotation.

The former is the question I tried to answer -- pointing you to the mathematics you need to understand.

Bring that, I'm speculating because I also can't be bothered to do the actual math. My guess with the sin and cos is based on what if expect to see if basic vector math applied to this.

Your assertion that for a constant rate of rotation (200 degreed per second?) You read 200 on the z acid if vertical and 100 is at 45 degrees suggests that you can simply sum rotation rate about the x, y, and z axis to get a total rate of rotation.

Your assertion doesn't match my intuition for a whole lot of reasons. I would recommend you investigate the math yourself.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
thanks. Was that yes its half the rate at 45 degrees , or yes it is 0.707 at 45 degrees, or something else.
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
When the device is on a 45 degree angle the output must have reduced by a specific amount. If you don't know what the answer is, then best for you not to answer at all rather than to confuse the issue.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
When the device is on a 45 degree angle the output must have reduced by a specific amount. If you don't know what the answer is, then best for you not to answer at all rather than to confuse the issue.

You have asserted that if the axis is rotated to 45 degrees, the output is reduced to half.

I am in no position to dispute your assertion. I have stated that this is not what I would expect.

Why would you ask me how much it reduces by if you have already told me?
 

Tim Brown

Dec 31, 2017
23
Joined
Dec 31, 2017
Messages
23
I will explain it to you. My physical tests show that at 45 degrees the output is half. I don't think it can be disputed. I have the device rotating on a turnable and I am measuring the output around the Z axis at 200 degrees per second. When I place the device on a 45 degree angle, the output drops to 100 degrees per second.

However, I am unable to find a straight forward mathematical equation to show that the turntable is still rotating at the same speed. And so I was looking for an answer, and also for confirmation that my testing was correct.

However, you seemed to ignore the question and so I kept asking it. You eventually said "it is not what you would expect". So what would you expect the output to be?
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
Isn't the 'cage' of the gyroscope fixed to the turntable? i.e. the turntable itself is one of the axis? In standard gyroscopes (navigational) this is (I think) the case.....
 
Top