MeGyro Module: General Introduction to Gyros


#1

Hi all,

With this article, I will explain a few aspects of using a gyro and give some hints on how to start exploring it.

What is a Gyroscope
A gyro is an attitude indicator. It provides indication of yaw, pitch and roll of a vehicle. These are relative measurements, comparing the current orientation with the orientation at time of calibration of the gyro. The gyro can not be used to measure the absolute geographic orientation, like a magnetic compass. But the absolute orientation can be calculated, when the absolute orientation in space during calibration is known (not taking into account the drift here, for simplicity).

In general, a gyro is not a navigational device! It can detect the momentarily attitude of a device, but it can not be used to keep a given course or heading!

The MeGyro Module
The makeblock MeGyro module also contains an accelerometer and a gravitometer. It measures gravity and acceleration along three cartesional axes, and from these measurements it calculates the deflection of the current orientation of the module from its orientation at last calibration time.

How to Apply the MeGyro Module in Practice
When looking at the gyro module a small drawing is visible, indicating the coordinate system. The gyro delivers rotation angles along these three axes. It is important to mount the gyro so that the axes point to the right directions, in order to match the familiar coordinate systems.

The X-axis should represent the length axis of the vehicle. It will then indicate the “roll” attitude.
The Y-axis points through the sides of the vehicle. The returned values for Y represent the “pitch” attitude.
The Z-axis is the vertical axis, pointing through the vehicle. It provides the “yaw” attitude. The Z-Axis can point upwards or downwards, which will result in either positive or negative values for “right” and “left” yaw, or heading deviation.

The values returned by gyro.getAngleX/Y/Z, after gyro.update() are given in +/- degrees deviation from what has been measured/calculated at gyro.begin(), when X, Y, and Z are set to “0”. So, if Z = 3.0, it means that the vehicle has turned 3 degrees to the right (I prefer right to be positive), since the last calibration of the gyro.

Note, that values for pitch and roll (X and Y axes) are defined within a range of +/-90 deg, while the heading (Z-axis) is defined as 360 deg. When doing a looping, starting at horizontal orientation, the pitch will reach its maximum deflection angle at the vertical orientation, at 90 deg. from there onwards, the angle to the horizontal pane will decrease again, to 0. At the capsized horizontal position the pitch will be 0 again and increase towards the maximum of -90 deg, from where it increases again to 0 - the initial orientation. The same mechanism applies to the roll axis, when performing a roll.

The MeGyro Example Sketch
This sketch should be used to find out about the correct function and orientation of the module. It is important to use Makeblock Library V 3.X for this, as earlier libraries are buggy for the gyro. Just load and run the sketch and move the module, simulating pitch, yaw and roll. Observe the measurements, returned for the three angles by watching the output of the sketch in serial monitor. Once you know how to mount the module on your vehicle you are ready to go. For a start, you could write a sketch to let the module drive straight forward, self-correcting for deviations of the heading.

Heading (Z) Axis and Drift
The meGyro “gyro.getAngleZ” function delivers the heading as deflection since the last calibration (last call of gyro.begin()). However, if you turn the module several times by 360 deg you will notice that the returned values grow above 360. If you want to achieve headings between 0 and 360 deg, you could use the fmod function, like this: fmod(gyro.getAngleZ(),360.0). This will always return values between 0 and 360 or -360.

To me, the behaviour of Z is strange, the values returned by gyro.getAngleZ() should always be in the range of +/-180, but I may be wrong. Anyways, while X and Z deliver rather stable values, Z is affected by a large drift. At my module, the value drifts by almost 1 deg/sec, which is way too much for a practical usage to keep the heading of a module straight. Commercial gyros can keep the Z-value much more constant, but they cost around 50,000$ +

References
Makeblock has provided a technical reference page at Makeblock Learn.
The math behind attitude and orientation detection: Wikipedia: Euler Angles

Cheers, Stefan


Trying to understand the Extension Builder's coding concepts
Accelerometer Issues
#2

what port did you use? there is no port designation in the MeGyro gyro line of the demo code. I tried to use ports 3,4,6,7,8 and I tried to include a port number MeGyro gyro(PORT_8) with no luck.

Any suggestions?

Scott


#3

Ok problem solved - this sensor does not draw power from the USB cable. The port number is not needed, external power is.

Thanks anyway

Scott


#4

Is there a reason that the getAngleX() and getAngleY() functions return values between -90 and 90 degrees? This allows two orientations to have identical values, which does not seem correct.

Returning values between -180 and 180 degrees would allow each orientation to have a unique value - which seems more like the expected behavior.

Eli


#5

Hi Scott,

I had the same question about port while trying the gyro with Gyro rotation arduino example. I tried to connect external power and tried all ports for the sensor, but the example still doesn’t work ( I don’t see X,Y,Z angles displayed in serial monitor). Do you have any suggestions?

Thanks!


Trying to use Gyro MPU6050 with mBlock - unable to find MeGyro Extension
#6

Hi, @eli and others,

some of you wondered why X and Y axes do only provide a range of +/- 90 deg, instead of 180.

This is indeed correct and lies within the definition of the system. Remember, X and Y axes define the pitch and the roll of your bot, while Z responds the heading. Now, when your bot is pointing northward on horizontal ground, pitch (Y) is 0 and heading (Z) is also 0 (North). Think of flying a loop with your bot. Y (pitch) will increase until the sensor is at vertical orientation, where Y reaches its maximum and heading (Z) stays unchanged. Turn it further, and the heading (Z) will instantly flip to 180 (South), with the pitch showing now negitive values of -90, decreasing towards 0 until you are back to horizontal (Y=0). Continue to loop, and the Y will again increase to 90, where the heading flips back to North and the pitch going back to 0 until you reach your original levelled attitude.

In short, to have an idea of the absolute orientation of the gyro you need to always look at all three axes, not just one. We omitted looking at roll (X) in our example, to keep it simple. To learn how this works in full detail, you need to look up “Euler-angles” in Wikipedia or google for it.

I will add this to my gyro introduction article, and also the lonk to the learn page provided by makblock now (which covers the technical details).


#7

Sorry But I do not


#8

Hi

Could it be the Coriolis effect that makes the Z axis value drift?