Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow down automatic rotation of 3d View #2465

Closed
thefeiter opened this issue Jan 7, 2021 · 14 comments
Closed

Slow down automatic rotation of 3d View #2465

thefeiter opened this issue Jan 7, 2021 · 14 comments

Comments

@thefeiter
Copy link
Contributor

Use case

When I use the 3d view when locked to location, the map automatically rotates according to magnetic compass but this is reacting too fast / reacts to very small movements. This makes it difficult to tap on specific tasks since they move too quick.

Proposed Solution

Create a maximum rotation speed to slow down the rotation / make it rotate more smoothly.

@smichel17
Copy link
Member

Related: #2191

@westnordost
Copy link
Member

It is already slowed down. The quality or noise of the compass sensor is very much dependent on the device and probably whether the compass is calibrated a lot. Try calibrating your compass. I think it is calibrated automatically by Android when you make invisible eights in the air with your smartphone in the hand.

@westnordost
Copy link
Member

The code is here: https://github.com/streetcomplete/StreetComplete/blob/master/app/src/main/java/de/westnordost/streetcomplete/map/Compass.kt

Maybe instead of a static factor, it could be adaptive, based on how much noise is experienced. But what would be the algorithm that detects the amount of noise? That algorithm must be able to distinguish a fast rotation of the device from other noise.

@thefeiter
Copy link
Contributor Author

It is already slowed down. The quality or noise of the compass sensor is very much dependent on the device and probably whether the compass is calibrated a lot. Try calibrating your compass. I think it is calibrated automatically by Android when you make invisible eights in the air with your smartphone in the hand.

That didn't help for me.

@westnordost westnordost added the help wanted help by contributors is appreciated; might be a good first contribution for first-timers label Jan 7, 2021
@westnordost
Copy link
Member

westnordost commented Jan 7, 2021

So I'd mark this as help wanted, currently I have no idea how to build an algorithm that adapts the "SMOOTHEN_FACTOR"

Maybe define a "max rotation speed" and adapt the factor somehow based on whether the current speed is above it or not... don't know.

Keywords to search for in the web would probably include "adaptive low-pass filter"

@mnalis
Copy link
Member

mnalis commented Jan 7, 2021

Just to note that it's very jittery for me too in SC on Huawei P30 Pro, but I almost always run in static north-is-up (or manually rotated) birds-eye view, so not quite a big deal here.

You might want to look is OsmAnd, as similar feature there seems much less jittery to me. I have Use Kalman filter = on and Use magnetic sensor = Off in settings there.

@westnordost
Copy link
Member

what else than the magnetic sensor is used??

@mnalis
Copy link
Member

mnalis commented Jan 8, 2021

I have no idea, one would have to look into OsmAnd source. But AFAIR that was some directional API introduced in some android version that was also using more stuff like gyros and accelerators, so perhaps they meant that it is used instead of direct magnetic sensor reading?

@mnalis
Copy link
Member

mnalis commented Jan 8, 2021

After some searching:

<string name="use_magnetic_sensor_descr">
For the compass reading, use the magnetic sensor instead of the orientation sensor.
</string>

perhaps this helps explain it?

@smichel17
Copy link
Member

smichel17 commented Jan 8, 2021

@westnordost
Copy link
Member

Okay, thanks @smichel17. I don't get why there is even a setting for that in OsmAnd. The orientation sensor is software only (i.e. actually uses a combination of the geomagnetic and acceleration sensor in the background) and has been deprecated since Android 2.2 (Froyo)!

The algorithm to smoothen the orientation in OsmAnd is exactly the same as in StreetComplete. The formula looks different, but just rearrange it and it is the same - minus the constant factor and the number of times per second it is called:

With sensorValue being the angle reported from the sensor, previousValue the last angle being displayed and newValue the angle that should be displayed now...

StreetComplete:

// called 30 times per second
newValue = previousValue + 0.1 * (sensorValue - previousValue)

OsmAnd:

// called as many times per second as the sensor reports that the sensor value changed (much higher than 30 FPS)
newValue = (1 - 0.04) * previousValue + 0.04 * sensorValue 

In StreetComplete, it is limited to 30 FPS because every change in rotation can trigger a rerender of the map view (especially in the "uatomatic rotation 3d view") and we don't want to do that much more often than necessary.

@FloEdelmann
Copy link
Member

Maybe it'd just help then to reduce the constant to something around 0.04 like OSMAnd does?

@westnordost
Copy link
Member

See

// called as many times per second as the sensor reports that the sensor value changed (much higher than 30 FPS)

@westnordost
Copy link
Member

But anyway, the original request was not to smoothen the compass in general, but the rotation in that "follow my orientation view". So I added more smoothing for that.

@westnordost westnordost removed the help wanted help by contributors is appreciated; might be a good first contribution for first-timers label Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants