我正在开发一个驱动程序行为应用程序,我正在使用SOMotionDetector(感谢麻省理工学院)。它的给定速度和设备的运动类型(不移动,行走,跑步,汽车)。我将在我的案例中使用Automotive,因为我需要检测驾驶员行为。这是基于速度检测运动类型,其中一些阈值设置为步行,跑步,汽车或如果可用,它使用M7芯片。它会在[SOMotionDetector sharedInstance].locationChangedBlock
中大约每秒钟后(基于GPS的时间变化)更新位置。要检测激进的速度或休息,我要检查的是最后一秒的速度增加/减少。如果它从某个阈值(我正在使用kAggressiveSpeedIncrementFactor 8.0f
)增加,那么它会大幅提高速度,如果速度下降(在这种情况下差异系数为负),那么它的激进突破。对于转弯,我正在玩经度和经度点的角度,以下是我的逻辑代码:
#define kAggressiveSpeedIncrementFactor 8.0f // if 8 km/h speed was increased in last second
#define kAggressiveAngleIncrementFactor 30.0f // 30 degree turn angle
#define kAggressiveTurnIncrementFactor 5.0f . // while turn the increasing speed factor in last second
SOMotionDetector *motionDetector = [SOMotionDetector sharedInstance];
motionDetector.locationChangedBlock = ^(CLLocation *location) {
if (motionDetector.motionType == MotionTypeAutomotive) {
SOLocationManager *locationManager = [SOLocationManager sharedInstance];
float currSpeed = motionDetector.currentSpeed * 3.6f;
float lastSpeed = motionDetector.lastSpeed * 3.6f;
float currAngle = locationManager.currAngle;
float lastAngle = locationManager.lastAngle;
self.speedDiff = currSpeed-lastSpeed;
self.angleDiff = currAngle-lastAngle;
if (fabs(self.speedDiff)>kAggressiveSpeedIncrementFactor && fabs(self.angleDiff)<kAggressiveAngleIncrementFactor) {
NSString *msg = @"Aggressive Speed";
if (self.speedDiff < 0)
msg = @"Aggressive Break";
NSLog(@"%@", msg);
}
if (fabs(self.angleDiff)>kAggressiveAngleIncrementFactor && currSpeed>kAggressiveTurnIncrementFactor) {
NSLog(@"aggressive turn");
}
}
};
我在currentSpeed
课程中创建了lastSpeed
和SOMotionDetector
(为了我的速度差异),在currAngle
中创建了lastAngle
和SOLocationManager
。请看一下代码,
激进的速度有时候工作完美 我的问题是: