nn::hid::CTR::GyroscopeReader Classclass GyroscopeReader : private nn::util::NonCopyable< GyroscopeReader >
Class for loading sampling data from the gyro sensor.
Samples the angular velocity of the gyro sensor an average of every 10 milliseconds. If you want to monitor the exact timing of sampling, you can use the Gyroscope class to know precisely when sampling occurs.
GyroscopeStatus structure. This structure contains not just the angular velocity, but also attitude information calculated from the angular velocity. Because attitude is calculated when the Read or ReadLatest function is called, one of these functions must be called regularly (ideally in every frame). Data stored in the internal buffer can become discontinuous, resulting in less accurate attitude information, if too much time elapses between calls to either of these functions.
The gyro sensor halts sampling and transitions to sleep in two cases: when the system itself is in Sleep Mode, and when there are no instances of the GyroscopeReader class anywhere in the application. To explicitly stop sampling you must destroy all instances.
It takes up to approximately 160 milliseconds for the sensor to transition from sleep to the active state where sampling is possible. No sampling is done during this transition time, and calls to the Read and ReadLatest functions do not yield valid results. To be sure to obtain sampling results, Nintendo recommends using the nn::hid::CTR::HidBase::WaitSampling function in the Gyroscope class to wait until sampling has been performed at least once. Starting from the second instance, this sampling wait time is the same as the wait until the next sample, which is a maximum of approximately 10 milliseconds.
As mentioned, creating or destroying instances serves as a trigger to switch the gyro sensor between the sleeping and active states. Frequent switching places a load on the device and results in more wear and tear on the device and higher power consumption. Try as much as possible to use the same instance throughout intervals where you are using gyro sensor output values, and avoid frequently creating or destroying instances. Below is an example of what you should avoid.
void GetGyroscopeValue(f32* x,f32* y,f32* z)
{
GyroscopeReader reader; // Instance created: device is activated
GyroscopeStatus status;
reader.ReadLatest( &status ); // Get value
*x = status.speed.x;
*y = status.speed.y;
*z = status.speed.z;
return; // "reader" destroyed: device put to sleep
}
void MainLoop() // Loop called once per frame
{
... some sort of processing .....
GetGyroscopeValue( &x, &y, &z ); // Value obtained once in every frame
... some sort of processing .....
}
In the bad example above, an instance of GyroscopeReader is created and destroyed on the stack in every frame. It is impossible to get appropriate values because the gyro sensor has not met the launch time to go from Sleep Mode to active mode. The design should be revised, for example, by creating the instance in the heap, so that the instance continues to exist during the period when the application needs to get the angular velocity.
This class includes the following correction processing for getting information more accurately.
| Acceleration Correction | Uses the accelerometer to improve the accuracy of CTR attitude calculations. |
|---|---|
| Zero-Point Drift Correction | The gyro sensor's zero point can drift due to environmental factors. This correction automatically detects zero-point drift and adjusts angular velocity values accordingly. |
This class includes the following features to process output values.
| Zero-Point Play Tolerance | When the sampling results are within any radius centered on the zero-point, that is output as the zero-point. This is used when, for example, you don't want to reflect small movements in the output. |
|---|---|
| Axial Rotation | The sampling results are multiplied by any rotational matrix and then output. You can get output that reflects placement of the gyro sensor at an angle. |
The default gyro sensor axes are as follows.
| X+ | A clockwise rotation about the direction indicated by the Left Button on the +Control Pad. |
|---|---|
| Y+ | A clockwise rotation about the direction normal to and outward from the Touch Screen. |
| Z+ | A clockwise rotation about the direction indicated by the Up Button on the +Control Pad. |
A future update to the HOME menu will add a feature enabling users to recalibrate the accelerometer whenever they like.
As a result, correction in accordance with the user's environment may start while the user is transitioned from the application to the HOME Menu using the HOME Button.
After this operation, the values obtained by the Read and ReadLatest functions are the corrected values. In most cases, the corrected values accurately reflect the user's environment.
The applications, however, need not take any special measures to deal with this.
This class maintains an internal instance of AccelerometerReader for acceleration correction, so generating an instance of this class activates the accelerometer.
| S | MAX_READ_NUM | const s8 | The maximum number of data samples that can be read. |
|---|
| Constructors and Destructors | ||
|---|---|---|
GyroscopeReader
|
Constructor. | |
~GyroscopeReader
|
Destructor. | |
| Reading Sampling Data | ||
Read
|
Loads sampling data from the gyro sensor, starting with the most recent data. Does not load any data that has been previously loaded. | |
ReadLatest
|
Loads the most recent sampling data from the gyro sensor. Unlike the Read function, this function can load the same sampling data more than once. |
|
| Reset | ||
Reset
|
Initializes internal settings. | |
| Output Value Settings | ||
SetAngle
|
Resets to an arbitrary value the angle member of the GyroscopeStatus Structure (obtained by the Read and ReadLatest functions). |
|
SetDirection
|
Resets to an arbitrary value the direction member of the GyroscopeStatus structure (obtained by the Read and ReadLatest functions). |
|
SetAngleMagnification
|
Sets individual scaling factors to apply for each axis when calculating angular velocity. | |
SetDirectionMagnification
|
Sets the scaling factor to apply to the angular velocity used when calculating the direction member of the GyroscopeStatus structure, which is obtained by the Read and ReadLatest functions. |
|
| Zero-Point Play Tolerance | ||
EnableZeroPlay
|
Enables zero-point play tolerance. | |
DisableZeroPlay
|
Disables the zero-point play tolerance. | |
IsEnableZeroPlay
|
Checks whether zero-point play tolerance is enabled. | |
GetZeroPlayEffect
|
Gets the strength of correction applied by the zero-point play tolerance. | |
SetZeroPlayParam
|
Sets the zero-point (at-rest) play tolerance. | |
GetZeroPlayParam
|
Gets the zero-point play tolerance. | |
ResetZeroPlayParam
|
Initializes the zero-point play tolerance. | |
| Zero-Point Drift Correction | ||
EnableZeroDrift
|
Enables zero-point drift correction. | |
DisableZeroDrift
|
Disables zero-point drift correction. | |
IsEnableZeroDrift
|
Checks whether zero-point drift correction is enabled. | |
GetZeroDriftEffect
|
Gets the strength of zero-point drift correction. | |
ResetZeroDriftMode
|
Initializes the zero-point drift correction mode. | |
SetZeroDriftMode
|
Sets the zero-point drift correction mode. | |
GetZeroDriftMode
|
Gets the zero-point drift correction mode. | |
| Acceleration Correction | ||
EnableAccRevise
|
Enables acceleration correction. | |
DisableAccRevise
|
Disables acceleration correction. | |
IsEnableAccRevise
|
Checks whether acceleration correction is enabled. | |
GetAccReviseEffect
|
Gets the strength of acceleration correction. | |
SetAccReviseParam
|
Sets the weight and enabled range for acceleration correction. | |
GetAccReviseParam
|
Gets the weight and enabled range for acceleration correction. | |
ResetAccReviseParam
|
Initializes the weight and enabled range for acceleration correction. | |
| Axial Rotation | ||
EnableAxisRotation
|
Enables axial rotation. | |
DisableAxisRotation
|
Disables axial rotation. | |
IsEnableAxisRotation
|
Checks whether axial rotation is enabled or disabled. | |
SetAxisRotationMatrix
|
Sets the rotation matrix used for axial rotation. | |
GetAxisRotationMatrix
|
Gets the rotation matrix used for axial rotation. | |
ResetAxisRotationMatrix
|
Initializes the rotation matrix used for axial rotation. When this function is called, the rotation matrix is set to a nn::math::MTX34 identity matrix. This setting is equivalent to disabling axial rotation. |
|
nn::util::NonCopyable
nn::hid::CTR::GyroscopeReader
CONFIDENTIAL