开发者

absolute strength of the magnetic field : Android

开发者 https://www.devze.com 2023-02-07 21:54 出处:网络
Similar to GPS Status application in android I want to get the \"absolute strength of the magnetic field\" and \"theoretical strength\". I am able to get the theoretical strength using Geom开发者_如何

Similar to GPS Status application in android I want to get the "absolute strength of the magnetic field" and "theoretical strength". I am able to get the theoretical strength using Geom开发者_如何转开发agneticField getFieldStrength() method .

But I am not sure how to get the "absolute strength of the magnetic field" from sensors.

Please help.

Thanks.


If you are looking for an absolute value of the magnetic field strength, you could simply calculate it as follows:

private final SensorEventListener mySensorListener = new SensorEventListner() {
   public void onSensorChange(SensorEvent event) {
       sensorRead = event.value;
       int sensorType = event.sensor.getType();

       if(sensorType = Sensor.TYPE_MAGNETIC_FIELD) {
          mag = sensorRead;
          magAbsVal = Math.sqrt(mag[0]*mag[0] + mag[1]*mag[1] + mag[2]*mag[2]);
       }
   }
}

This will give you the absolute uT value read from the magnetometer. If you are looking for a percentage value, you can use percentMag = largestMag/magAbsVal .

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消