add corner pegging

smart_log
Georg Lukas 2011-09-13 14:03:48 +02:00
rodzic 6c4c96a3ed
commit f5acfc8a8c
1 zmienionych plików z 34 dodań i 4 usunięć

Wyświetl plik

@ -195,10 +195,10 @@ class AprsService extends Service with LocationListener {
}
def smartBeaconSpeedRate(speed : Float) : Int = {
val SB_FAST_SPEED = 14 // [m/s] = ~50km/h
val SB_FAST_SPEED = 28 // [m/s] = ~100km/h
val SB_FAST_RATE = 60
val SB_SLOW_SPEED = 1 // [m/s] = 3.6km/h
val SB_SLOW_RATE = 600
val SB_SLOW_RATE = 1200
if (speed <= SB_SLOW_SPEED)
SB_SLOW_RATE
else if (speed >= SB_FAST_SPEED)
@ -207,14 +207,44 @@ class AprsService extends Service with LocationListener {
((SB_SLOW_RATE - SB_FAST_RATE) * (SB_FAST_SPEED - speed) / (SB_FAST_SPEED-SB_SLOW_SPEED)).toInt
}
// returns the angle between two bearings
def getBearingAngle(alpha : Float, beta : Float) : Float = {
val delta = math.abs(alpha-beta)%360
if (delta <= 180) delta else (360-delta)
}
// obtain max speed in [m/s] from moved distance, last and current location
def getSpeed(location : Location) : Float = {
val dist = location.distanceTo(lastLoc)
val t_diff = location.getTime - lastLoc.getTime
math.max(math.max(dist*1000/t_diff, location.getSpeed), lastLoc.getSpeed)
}
def smartBeaconCornerPeg(location : Location) : Boolean = {
if (!location.hasBearing || !lastLoc.hasBearing)
return false
val SB_TURN_TIME = 30
val SB_TURN_MIN = 10
val SB_TURN_SLOPE = 240.0
val t_diff = location.getTime - lastLoc.getTime
val turn = getBearingAngle(location.getBearing, lastLoc.getBearing)
// threshold depends on slope/speed [mph]
val threshold = SB_TURN_MIN + SB_TURN_SLOPE/(getSpeed(location)*2.23693629)
Log.d(TAG, "smartBeaconCornerPeg: %1.0f < %1.0f %d/%d".format(turn, threshold,
t_diff/1000, SB_TURN_TIME))
// need to corner peg if turn time reached and turn > threshold
(t_diff/1000 >= SB_TURN_TIME && turn > threshold)
}
// return true if current position is "new enough" vs. lastLoc
def smartBeaconCheck(location : Location) : Boolean = {
if (lastLoc == null)
return true
if (smartBeaconCornerPeg(location))
return true
val dist = location.distanceTo(lastLoc)
val t_diff = location.getTime - lastLoc.getTime
// obtain max speed from moved distance, last and current location
val speed = math.max(math.max(dist*1000/t_diff, location.getSpeed), lastLoc.getSpeed)
val speed = getSpeed(location)
//if (location.hasSpeed && location.hasBearing)
val speed_rate = smartBeaconSpeedRate(speed)
Log.d(TAG, "smartBeaconCheck: %1.0fm, %1.2fm/s -> %d/%ds - %s".format(dist, speed,