Repository navigation
SpeedDriftFilter
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 SpeedDriftFilter.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;
/* Zeroing of the speed drift at a stop. */
public final class SpeedDriftFilter extends DriftFilter<SpeedSensorAtom> {
/* Stable step name in the plans and settings. */
public static final String NAME = "speedDrift";
/* The speed in the atom is stored in thousandths of km/h. */
private static final double UNITS_PER_KMH = 1000d;
/* Divisor for converting km/h to m/s. */
private static final double KMH_PER_MS = 3.6;
/* Milliseconds in a second: the atom duration is stored in ms. */
private static final double MS_PER_SEC = 1000d;
public SpeedDriftFilter() {
/* Step version is 1; the sensor atom is SpeedSensorAtom. */
super(NAME, 1, SpeedSensorAtom.class);
}
@Override
/* Speed in km/h. */
protected double value(SpeedSensorAtom atom) {
return atom.speed / UNITS_PER_KMH;
}
@Override
/* Reverse conversion with 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);
}
@Override
/* Shift over the step: speed in m/s times the atom duration in seconds. */
protected double shiftMeters(SpeedSensorAtom atom) {
return value(atom) / KMH_PER_MS * atom.duration / MS_PER_SEC;
}
}SpeedDriftFilter is the "Speed drift at a stop" step. It zeroes the small speed that a GPS receiver shows while standing still. The algorithm and the speedBelow, shiftBelow parameters are in DriftFilter; here are the speed and the shift calculation for the SpeedSensorAtom atom.
-
Name and version:
speedDrift, version 1. -
value—atom.speed / 1000: the speed in km/h. -
setValue—atom.speed = (int) Math.round(value * 1000): writing back with rounding. -
shiftMeters—value(atom) / 3.6 * atom.duration / 1000: the speed in m/s (km/h divided by 3.6) multiplied by the atom duration in seconds (durationis in milliseconds). This gives an estimate of the shift over the recording step.
Where it is used. In GoproImportPlan in the speed scenario: SpeedBadPointFilter → ExplicitGaps → SpeedDriftFilter (speedBelow = 4) → SpeedExponentialFilter → SameValueCompress. The speed sensor in the GoPro plan is marked disabled().
- The shift is an estimate from the speed and the atom duration, not a distance by coordinates; it is not checked against the distance actually covered.
- In the GoPro plan
shiftBelowis not set, so the shift is not checked and the zeroing goes by the speed threshold alone. - The speed (
speed) is an integer: after writing, the values are rounded to 0.001 km/h. A zeroed speed is written as 0.