Hi guys,
I am working on a project that includes an Android application that is used for control / steering.
- Speed: . When you tilt your phone forward / backward (step), it simulates gas flow and disturbance.
- Direction: When tilting the phone left / right (roll), it simulates steering left and right.
I already wrote code that seemed to work fine. But when I looked closer, I found that some of the values โโact strangely.
When I tilt the phone forward / back to handle speed, it works great, I get the expected values โโof speed and direction. But when I tilt the phone left / right to handle the direction, it seems to distort some values. When it tilts left / right, which not only changes the direction value (roll), but also affects the speed value (step).
For more information:
- Programming for Android 2.2
- The device is Google Nexus One.
- Hold device in portrait
The most appropriate code that I use to read the sensor values โโis as follows:
public void onSensorChanged(SensorEvent sensorEvent)
{
synchronized (this)
{
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float azimuth = sensorEvent.values[0];
float pitch = sensorEvent.values[1];
float roll = sensorEvent.values[2];
System.out.println("pitch: " + pitch);
System.out.println("roll: " + roll);
System.out.println("--------------------");
float speed = (pitch * 2.222f) + 200;
float direction = roll * -2.222f;
, , . / , , . ? , "roll'-ing"? , / / .
.