Repository navigation
SpeedExponentialFilter
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 SpeedExponentialFilter.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;
/* Gradual smoothing of speed; the algorithm values are in km/h. */
public final class SpeedExponentialFilter extends ExponentialFilter<SpeedSensorAtom> {
/* Stable step name in the plans and settings. */
public static final String NAME = "speedExponential";
/* The speed in the atom is stored in thousandths of km/h. */
private static final double UNITS_PER_KMH = 1000d;
public SpeedExponentialFilter() {
/* Step version is 1; the sensor atom is SpeedSensorAtom. */
super(NAME, 1, SpeedSensorAtom.class);
}
@Override
/* Reads the speed in km/h. */
protected double value(SpeedSensorAtom atom) {
return atom.speed / UNITS_PER_KMH;
}
@Override
/* Writes the speed back: rounding to a whole number of thousandths of km/h. */
protected void setValue(SpeedSensorAtom atom, double value) {
atom.speed = (int) Math.round(value * UNITS_PER_KMH);
}
}SpeedExponentialFilter is the "Gradual smoothing: speed" step. It applies the exponential smoothing from ExponentialFilter to the speed field of the SpeedSensorAtom atom. The formula, the alpha parameter and its default (1 — no smoothing) are described in the base class; the general order of work is in ValueFilter.
-
Name and version:
speedExponential, version 1. -
value—atom.speed / 1000: the speed in km/h (in the atom it is in thousandths of km/h). -
setValue—atom.speed = (int) Math.round(value * 1000): the smoothed value is converted back and rounded to an integer.
Where it is used. In GoproImportPlan in the speed scenario: SpeedBadPointFilter → ExplicitGaps → SpeedDriftFilter → SpeedExponentialFilter (alpha = 0.4) → SameValueCompress. The speed sensor itself in the GoPro plan is marked disabled().
- The step requires a pauses step before it (the default for
FilterStep): smoothing does not cross a pause. - The speed is an integer: smoothed values are rounded to 0.001 km/h, the fractional remainder is lost.
- The step removes nothing, the number of atoms does not change.