[Fix]修复闯红灯和绿波通行预警的问题

This commit is contained in:
chenfufeng
2021-11-16 20:35:15 +08:00
parent fca38dbb06
commit ee82ffda89
2 changed files with 17 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.utilcode.util.SPUtils
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.module.common.enums.EventTypeEnum
import com.mogo.utils.logger.Logger
@@ -25,7 +26,7 @@ class RedLightWarningManager : IMoGoTrafficLightListener {
override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) {
getCurrentRoadTrafficLight(trafficLightResult)?.let {
handleRedLightWarning(it)
handleRedLightWarning(it, trafficLightResult.flashYellow)
}
}
@@ -33,21 +34,28 @@ class RedLightWarningManager : IMoGoTrafficLightListener {
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
}
private fun handleRedLightWarning(trafficLightStatus: TrafficLightStatus) {
private fun handleRedLightWarning(trafficLightStatus: TrafficLightStatus, yellowLightTime: Int = 0) {
// 如果是Vip则不处理
if (SPUtils.getInstance().getLong("vip") > 0) {
return
}
// 路口100m闯红灯预警
CallerMapLocationListenerManager.getCurrentLocation()?.let {
// 单位m/s
val speed = it.speed
// 车停止或者速度非常慢,可能返回负数或者很小的值,需要过滤
if (speed <= 2.5f) return// 小于等于9km/h不处理
val distance = 100
val remainTime = trafficLightStatus.remain
val speed = it.speed
if (speed == 0f) return
val arriveTime = distance / speed
Logger.d(TAG, "speed is:$speed,remainTime is:$remainTime,arriveTime is:$arriveTime,yellowTime is:$yellowLightTime")
when {
trafficLightStatus.isRed() -> {
// 到达路口时红灯还没走完
if (arriveTime <= remainTime) {
redLightWarning()
} else if (arriveTime > remainTime) {
} else if (arriveTime > remainTime + yellowLightTime) {// 到达时红、黄灯都走完
greenLightWarning()
}
}
@@ -55,6 +63,8 @@ class RedLightWarningManager : IMoGoTrafficLightListener {
// 到达路口时黄灯还没走完
if (arriveTime <= remainTime) {
redLightWarning()
} else {
greenLightWarning()
}
}
trafficLightStatus.isGreen() -> {

View File

@@ -16,6 +16,7 @@ data class TrafficLightResult(
val lightId: Int, //红绿灯ID
val laneNo: Int, //车道号
val arrowNo: Int, //当前车道对应地面要素转向
val laneList: TrafficLightDetail //灯态具体信息
val laneList: TrafficLightDetail, //灯态具体信息
val flashYellow: Int// 黄灯总时间
) {
}