《车载碰撞和侧翻算法实现.docx》由会员分享,可在线阅读,更多相关《车载碰撞和侧翻算法实现.docx(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、车载的侧翻算法根据上面的公式实现,而碰撞时根据三个方向的加速度的值。主要利用了传感器的onSensorChanged来实现。package com.leadcore.edr.packet; import java.util.*; import android.content.Context;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;impor
2、t java.lang.Math;import android.util.Log; public class GSensorService private static final String TAG = GSensorService; private Context mContext = null; private boolean mIsRolloverWarning = false; private boolean mIsCrashWarning = false; public GSensorService(Context context) mContext = context; pri
3、vate final SensorEventListener mSensorListener = new SensorEventListener() Override public void onSensorChanged(SensorEvent event) if (Sensor.TYPE_ACCELEROMETER = event.sensor.getType() float xAxis = event.values0; float yAxis = event.values1; float zAxis = event.values2; float max_accelerometer = G
4、lobalData.getCrashacceleration() * SensorManager.STANDARD_GRAVITY / 10; boolean isOverAccelerometer = Math.abs(xAxis) max_accelerometer | Math.abs(yAxis) max_accelerometer | Math.abs(zAxis) max_accelerometer; if (isOverAccelerometer & !mIsCrashWarning) mIsCrashWarning = true; GlobalData.setWarningFl
5、ag(JTT808.MSG_WARN_CRASH_WARN); Log.i(TAG, crash warning.); else if (!isOverAccelerometer & mIsCrashWarning) mIsCrashWarning = false; GlobalData.ClearWarningFlag(JTT808.MSG_WARN_CRASH_WARN); double rad2 = Math.atan(xAxis / Math.sqrt(yAxis * yAxis + zAxis * zAxis); double degree2 = Math.toDegrees(rad
6、2); int max_degree = GlobalData.getCrashDegree(); if (Math.abs(degree2) = max_degree & !mIsRolloverWarning) mIsRolloverWarning = true; GlobalData.setWarningFlag(JTT808.MSG_WARN_ROLLOVER); Log.i(TAG, Roll over warning.); else if (Math.abs(degree2) max_degree & mIsRolloverWarning) GlobalData.ClearWarn
7、ingFlag(JTT808.MSG_WARN_ROLLOVER); mIsRolloverWarning = false; Override public void onAccuracyChanged(Sensor sensor, int accuracy) / Not used. ; private void registerListener() SensorManager sm = (SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE); sm.registerListener(mSensorListener, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); public void start() registerListener();
限制150内