Repository navigation
SpeedAverageFilter
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 SpeedAverageFilter.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.SpeedSensorAtom;
/* Smoothing by average for speed. The speed atom stores an integer in thousandths of km/h. */
public final class SpeedAverageFilter extends AverageFilter<SpeedSensorAtom> {
/* Stable step name in the import plans and in the saved settings. */
public static final String NAME = "speedAverage";
/* How many storage units are in one km/h. */
private static final double UNITS_PER_KMH = 1000d;
/* Step logic version is 1; works with SpeedSensorAtom atoms. */
public SpeedAverageFilter() {
super(NAME, 1, SpeedSensorAtom.class);
}
/* For the calculation the speed is converted to km/h. */
@Override
protected double value(SpeedSensorAtom atom) {
return atom.speed / UNITS_PER_KMH;
}
/* The rounded integer is written back. */
@Override
protected void setValue(SpeedSensorAtom atom, double value) {
atom.speed = (int) Math.round(value * UNITS_PER_KMH);
}
}The "Smoothing by average: speed" step replaces every speed value with the average over a window around it. It removes jitter, but also softens sharp accelerations (the description from the string Plugin.ImportStep.speedAverage.description). This is the only concrete implementation of AverageFilter.
The whole algorithm is in the base classes: AverageFilter (the windowSec parameter, the calculation through WindowAverage) and ValueFilter (reading, writing, recalculation of the increments). The class adds two methods:
-
value(atom)returnsatom.speed / 1000— the speed in km/h; -
setValue(atom, value)writesMath.round(value * 1000)toatom.speed(typeint, thousandths of km/h).
The increment speedDelta is recalculated by the base class (SpeedSensorAtom.setDeltaTo).
The step is registered in BuiltinScenarios.steps(), that is, it is available as a processing stage. It is not used now in any of the built-in import plans (processing/plans): the user or the plugin author adds it themselves, the windowSec parameter defaults to 0.
- The accuracy after smoothing is 0.001 km/h (rounding to an integer in storage units).
- The value is written only if it changed compared with the original.
- The speed is smoothed as an ordinary number: if you need to remove outliers rather than noise, rejection of bad points (
SpeedBadPointFilter) is placed before the average.