Search code examples
androidapp-inventor

App Inventor: Determine Backward or Forward Orientation


I would like to make a segway robot with my Android phone as the orientation sensor.

According to the App Inventor 2 reference documentation:

  • When the phone is standed up, Pitch is -90.
  • When the phone is a little bit leanback, it may be Pitch is -85
  • When the phone is a little but forward, it may be Pitch is -85 too..

How do I know if the phone is leaning back or forward??


Solution

  • Depends which sensor you use. There are motion, environmental and position sensors. You should use position and motion sensors for detecting device movements, for example orientation or accelerometer and gravity in combination.

    Lets say you want to make your own application that will receive sensor data as soon as app is started. You will get event (movement) data with onSensorChanged() method. That means you will get data about change of INITIAL device position.

    In other words, if you start your app while device is laying flat on the table you will get -90 pitch when moving device to standing position but if you turn your app while device is already standing up pitch will be 0 and 90 when laying it down. So you should be more interested in position change and not initial position.

    Most probably you will have to combine few sensors data to accomplish that you want.