From c5bf3381bdec6045c05e7c61f14222e4506112e1 Mon Sep 17 00:00:00 2001 From: xuxinchao Date: Mon, 8 Jul 2024 19:04:38 +0800 Subject: [PATCH] =?UTF-8?q?[6.5.0]=E8=B0=83=E6=95=B4=E8=B5=B7=E6=AD=A5?= =?UTF-8?q?=E6=8F=90=E9=86=92/=E6=8F=90=E5=89=8D=E5=87=8F=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datacenter/v2x/TrafficLightDispatcher.kt | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt index f93fdb1125..61d7b636a0 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/datacenter/v2x/TrafficLightDispatcher.kt @@ -18,10 +18,14 @@ import com.mogo.eagle.core.data.config.HmiBuildConfig import com.mogo.eagle.core.data.deva.chain.ChainConstant import com.mogo.eagle.core.data.enums.DataSourceType import com.mogo.eagle.core.data.enums.TrafficLightEnum +import com.mogo.eagle.core.data.map.MogoLocation import com.mogo.eagle.core.data.multidisplay.TelematicConstant import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotIdentifyListener +import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener import com.mogo.eagle.core.function.api.datacenter.union.IMoGoTrafficLightListener import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager +import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils @@ -31,6 +35,7 @@ import com.mogo.eagle.core.utilcode.util.GsonUtils import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.zhjt.service.chain.ChainLog import perception.FusionTrafficLightOuterClass +import kotlin.math.abs fun TrafficLightStatus.convert(): TrafficLightEnum { return when { @@ -57,7 +62,8 @@ fun convert(state: FusionTrafficLightOuterClass.FusionLightState): TrafficLightE * @优先级:OBU,云,工控 * @since: 2022/4/28 */ -class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLightListener { +class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLightListener, + IMoGoChassisLocationGCJ02Listener { companion object { const val TAG = "TrafficLightDispatcher" @@ -89,12 +95,17 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight private var lightCountDownTimer: CountDownTimer? = null private var lastLightTime: Long = System.currentTimeMillis() + private var currentSpeed: Float = 0f + private var isPrompted: Boolean = false //是否提示过起步提醒/提前减速,每个路口仅提示一次 + fun initServer(context: Context) { mContext = context //注册监听AI云.OBU,路侧获取红绿灯状态 CallerTrafficLightListenerManager.addListener(TAG, this) //注册监听工控机感知红绿灯 CallerAutopilotIdentifyListenerManager.addListener(TAG, this) + //注册获取当前车速 + CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 1, this) } /** @@ -114,7 +125,7 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight } if (!hasObuLightStatus) { if (!hasAiLightStatus) { - trafficLights?.let { + trafficLights?.let { it -> var light: FusionTrafficLightOuterClass.FusionTrafficLight? = null if (it.hasStraight()) { light = it.straight @@ -161,6 +172,7 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight if(convert(light.state) == TrafficLightEnum.BLACK){ //隐藏当前红绿灯以及额外提示框 CallerTrafficLightListenerManager.disableTrafficLight() + isPrompted = false }else{ //有下一和下二灯态,则为融合V2N红绿灯数据 onFusionTrafficLight(convert(light.state),light.duration.toInt(), @@ -180,16 +192,44 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight * 车辆行驶中,若判断当前绿灯自车基于当前速度需提速10%以上才可通过时,提示“蘑菇提醒您及时减速,避免路口急刹” * 车辆行驶中,若判断当前红灯自车基于当前速度需降低60%以上才可通过时,提示“蘑菇提醒您及时减速,避免路口急刹” */ - if(AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)){ + if(AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode) && !isPrompted){ + //车辆等红灯,在红/黄灯剩余5s且下一灯态为绿灯时,提示“红灯即将变绿”;并在变为绿灯时有提示起步的动效 if((light.state == FusionTrafficLightOuterClass.FusionLightState.STATE_YELLOW_FUSION || light.state ==FusionTrafficLightOuterClass.FusionLightState.STATE_RED_FUSION) && light.duration < 5 && light.nextState == FusionTrafficLightOuterClass.FusionLightState.STATE_GREEN_FUSION){ - //语音播放 + //语音播放:红灯即将变绿 AIAssist.getInstance(mContext).speakTTSVoice("红灯即将变绿") + isPrompted = true + } + //车辆行驶中,若判断当前绿灯自车无法通过,在绿灯剩余5s且下一灯态为红/黄灯时,提示“蘑菇提醒您及时减速,避免路口急刹” + if(light.state == FusionTrafficLightOuterClass.FusionLightState.STATE_GREEN_FUSION && light.duration < 5){ + CallerMapRoadListenerManager.getStopLineDistance()?.let { dis-> + if(currentSpeed*light.duration < dis){ + //语音播放:蘑菇提醒您及时减速,避免路口急刹 + AIAssist.getInstance(mContext).speakTTSVoice("蘑菇提醒您及时减速,避免路口急刹") + isPrompted = true + } + } + } + //车辆行驶中,若判断当前绿灯自车基于当前速度需提速10%以上才可通过时,提示“蘑菇提醒您及时减速,避免路口急刹” + if(light.state == FusionTrafficLightOuterClass.FusionLightState.STATE_GREEN_FUSION){ + CallerMapRoadListenerManager.getStopLineDistance()?.let{distance-> + if(currentSpeed*light.duration*1.1 < distance){ + //语音播放:蘑菇提醒您及时减速,避免路口急刹 + AIAssist.getInstance(mContext).speakTTSVoice("蘑菇提醒您及时减速,避免路口急刹") + isPrompted = true + } + } + } + //车辆行驶中,若判断当前红灯自车基于当前速度需降低60%以上才可通过时,提示“蘑菇提醒您及时减速,避免路口急刹” + if(light.state ==FusionTrafficLightOuterClass.FusionLightState.STATE_RED_FUSION){ + CallerMapRoadListenerManager.getStopLineDistance()?.let{distance-> + if(currentSpeed*0.4*light.duration > distance){ + //语音播放:蘑菇提醒您及时减速,避免路口急刹 + AIAssist.getInstance(mContext).speakTTSVoice("蘑菇提醒您及时减速,避免路口急刹") + isPrompted = true + } + } } - //TODO 需要知道当前车速和当前位置距离路口的距离 -// if(light.state == FusionTrafficLightOuterClass.FusionLightState.STATE_GREEN_FUSION && light.duration < 5){ -// -// } } @@ -464,6 +504,15 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener, IMoGoTrafficLight CallerTrafficLightListenerManager.removeListener(TAG) //取消注册监听工控机感知红绿灯 CallerAutopilotIdentifyListenerManager.removeListener(TAG) + //取消注册获取当前车速 + CallerChassisLocationGCJ02ListenerManager.removeListener(TAG) + } + + /** + * 当前车速 + */ + override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { + currentSpeed = abs(mogoLocation?.gnssSpeed ?: 0f) } } \ No newline at end of file