Repository navigation
AttitudeAverageFilter
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 AttitudeAverageFilter.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.AttitudeSensorAtom;
/* Smoothing by average for orientation angles: yaw, pitch, roll in degrees. */
public final class AttitudeAverageFilter extends VectorAverageFilter<AttitudeSensorAtom> {
/* Stable step name in the import plans. */
public static final String NAME = "attitudeAverage";
/* Step logic version is 1; atoms are AttitudeSensorAtom. */
public AttitudeAverageFilter() {
super(NAME, 1, AttitudeSensorAtom.class);
}
/* Three components: yaw, pitch, roll. */
@Override
protected int components() {
return 3;
}
/* Period is 360 degrees: the base class unwraps the angles before averaging. */
@Override
protected double period() {
return 360;
}
/* Index 0, 1, 2 is yaw, pitch, roll; any other index throws IndexOutOfBoundsException. */
@Override
protected double component(AttitudeSensorAtom atom, int index) {
return switch (index) {
case 0 -> atom.yaw;
case 1 -> atom.pitch;
case 2 -> atom.roll;
default -> throw new IndexOutOfBoundsException(index);
};
}
/* The yaw, pitch, roll fields are double, the value is written without rounding. */
@Override
protected void setComponent(AttitudeSensorAtom atom, int index, double value) {
switch (index) {
case 0 -> atom.yaw = value;
case 1 -> atom.pitch = value;
case 2 -> atom.roll = value;
default -> throw new IndexOutOfBoundsException(index);
}
}
}The "Smoothing by average: angles" step replaces every angle value with the average over a window around it. It removes sensor noise and vibration, but also softens short impacts (the Plugin.ImportStep.attitudeAverage.description string). An implementation of VectorAverageFilter for AttitudeSensorAtom: yaw (yaw), pitch (pitch) and roll (roll) of the body or gimbal of a drone (for example, from DJI telemetry).
The algorithm is in VectorAverageFilter; the class differs from the other subclasses by the overridden period(), which returns 360. Because of this the base class:
- unwraps every angle along the recording segment, so that the transition 359° → 1° is not taken as a jump by 358°;
- averages the unwrapped series through WindowAverage;
- brings the result to the range (−180; 180] and writes the changed values.
It is used by the DJI import plans (video with telemetry) and DJI SRT: window 0, that is, smoothing is off in the plans; it is followed by AttitudeToleranceCompress with a tolerance of 1°. The step is also registered in BuiltinScenarios.steps().
- All three angles are treated as periodic with a period of 360, including pitch and roll.
- If the original angles lie outside (−180; 180] (for example, yaw 0…360), then with a window greater than 0 the smoothed values will be written in the range (−180; 180], even if the average hardly differs from the original.
- The default window is 0: without an explicit value in the plan the step changes nothing and does not recalculate the increments.