Hi all,
as the use of the MeGyro module is badly explained by the makeblock team, I will try to explain a few aspects of using a gyro and give some hints on how to start exploring it. To follow this post you need to use the Arduino API, not Scratch.
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).
The makeblock MeGyro module also contains an accelerometer and a compass. When looking at src/MeGyro.cpp, one sees the accelerometer parametres (accX, accY and accZ), but no function is provided to retrieve them. As this is just C code, one could add the functions to the library, similar to the getAngleX/Y/Z() functions. The same would apply to the compass functions. Most likely this would also require some studying of appropriate filtering and drift-compensation mechanisms, in order to provide sensible values. Study the math used to achieve the angle-values, in order to get an idea…google and wikipedia are also your close friends here. E.g. with the accelerometer functions at hand, travelled distances could be calculated.
How to Apply the MeGyro Module in Practice
When looking at the gyro module a small drawing is visible, indicating the coordinate system. All the gyro does is measuring 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 right-handed 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” 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.
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.
Hope this little explanation helps for a starter.
Cheers, Stefan