For the actual measurement of tram speeds we used two methods:
- Use the accelerometer data and integrate
- Use the GPS on the phone and get the speed from that measurement
To get an acceptable result we needed to combine these two measurements, as sometimes the GPS is quite inaccurate, and sometimes the integration from the accelerometer drifts off.
For the accelerometer we then also made a couple of assumptions (based on measurements of data on the tram and testing the App in progress):
- The tram mainly moves forward, so we only take into account one axis of acceleration for the integration. This ensures that we don’t get additional noise from three different axes, but of course limits the way in which you can mount the phone.
- When the tram moves, the “sideways axis” and the gravity axis of acceleration shakes quite a bit, when the tram is standing still, this vibration is not present. We can use this to detect whether or not the tram is moving or not. When the tram is not moving, we can make sure that the calculated speed goes to zero, and thus reset the integration constant
- When the tram is standing still, we also reset the offset of acceleration, to account for any kind of drift of the sensor itself over time.
- When the tram is on an incline or decline (a hill, a bridge, or going down into a tunnel), we get a bit of an offset so we need to compensate for this.
This added to a couple of other things like calculating means and standard deviations over a certain time window, taking a moving average, resulted in the final App, which can be downloaded from github:
https://github.com/sensestage/Guesstimate-Velocity-Better
Settings which worked best with the Samsung Galaxy S2 phones:
Sensor: accelero
Forward axis: Y
Sideways axis: Z
Gravity axis: X
Window size: 200 Delta time: 10
THRESHOLDS:
Gravity Tresh: 0.05 Gravity MA: 0.8
Still forward: 0.06 Still side: 0.06
Motion forward: 0.1 Motion side: 0.06
Accel std: 0.2 Accel mean: 0.1
Decel std: 0.3 Decel mean: -0.1
Mean weight: 0.95 Raw weight: 0.05
Offset MA: 0.999 Speed decay: 0.99
Mean MA: 0.99 Prec. MA: 0.2