Repository navigation
GyroAverageFilter
Up | Previous | Next | Русский
Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file GyroAverageFilter.java: the production code stays clean and the explanations live in the wiki.
package com.velitask.plugin.official.processing.filters;
import com.velitask.sdk.data.GyroscopeSensorAtom;
/* Smoothing by average for the gyroscope: angular velocity on three axes. */
public final class GyroAverageFilter extends VectorAverageFilter<GyroscopeSensorAtom> {
/* Stable step name in the import plans. */
public static final String NAME = "gyroAverage";
/* Step logic version is 1; atoms are GyroscopeSensorAtom. */
public GyroAverageFilter() {
super(NAME, 1, GyroscopeSensorAtom.class);
}
/* Three components: x, y, z. */
@Override
protected int components() {
return 3;
}
/* Index 0, 1, 2 is the x, y, z axis; any other index throws IndexOutOfBoundsException. */
@Override
protected double component(GyroscopeSensorAtom atom, int index) {
return switch (index) {
case 0 -> atom.x;
case 1 -> atom.y;
case 2 -> atom.z;
default -> throw new IndexOutOfBoundsException(index);
};
}
/* The x, y, z fields are double, the value is written without rounding. */
@Override
protected void setComponent(GyroscopeSensorAtom atom, int index, double value) {
switch (index) {
case 0 -> atom.x = value;
case 1 -> atom.y = value;
case 2 -> atom.z = value;
default -> throw new IndexOutOfBoundsException(index);
}
}
}The "Smoothing by average: rotation" step replaces every angular velocity value with the average over a window around it. It removes sensor noise and vibration, but also softens short impacts (the Plugin.ImportStep.gyroAverage.description string). An implementation of VectorAverageFilter for GyroscopeSensorAtom.
The algorithm is in VectorAverageFilter. The class defines the composition of the atom: three components x, y, z (double, angular velocity in °/s, as in the tolerance label of GyroToleranceCompress); the values are written as they are, without rounding; period() is not overridden.
It is used by the GoPro import plan: a window of 0.04 s, the sensor is disabled in the plan by default; the next stage is GyroToleranceCompress. The step is also registered in BuiltinScenarios.steps().
- The axes are smoothed independently.
- The fields are
double: unlike the accelerometer there is no rounding, so after averaging the values may differ from the original ones in the last digits and be written even when the series is almost constant. - The default window is 0: without an explicit value in the plan the step changes nothing.