[6.5.0][道路事件] 部分代码提交

This commit is contained in:
renwj
2024-06-27 16:56:21 +08:00
parent 3f65bc3976
commit 1f06c9a89e
14 changed files with 505 additions and 207 deletions

View File

@@ -67,8 +67,9 @@ dependencies {
kapt rootProject.ext.dependencies.androidxroomcompiler
implementation rootProject.ext.dependencies.androidxroomktx
implementation rootProject.ext.dependencies.localbroadcastmanager
implementation rootProject.ext.dependencies.jts_core
compileOnly project(':core:function-impl:mogo-core-function-map')
compileOnly project(":libraries:mogo-map")
implementation project(':foudations:mogo-commons')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-network')

View File

@@ -26,19 +26,25 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListen
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerV2XListenerManager.V2NCarTypeCheck
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.hmi.CallerRoadV2NEventWindowListenerManager
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager.saveMsgBox
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.util.CoordinateTransform
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils
import com.mogo.eagle.function.biz.v2x.V2XBizTrace
import com.mogo.eagle.function.biz.v2x.v2n.scenario.scene.airoad.AiRoadMarker
import com.mogo.eagle.function.biz.v2x.v2n.scenario.scene.airoad.AiRoadMarker.Marker
import com.mogo.eagle.function.biz.v2x.v2n.utils.V2NUtils
import com.mogo.eagle.function.biz.v2x.v2n.utils.V2XEventAnalyticsManager
import com.mogo.map.entities.Lane
import mogo.telematics.pad.MessagePad.Header
import mogo.telematics.pad.MessagePad.TrackedObject
import mogo.v2x.MogoV2X
import mogo.v2x.MogoV2X.RSI_PB
import mogo.v2x.MogoV2X.RTEData_PB
import java.lang.Math.abs
/**
* V2N上车相关事件绘制
@@ -64,7 +70,7 @@ internal object V2NIdentifyDrawer {
Log.d("V2NIdentifyDrawer", "---callback -- drawShiGu --- 1 ---")
}
val car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val filtered = events.filterIsInstance(TrackedObject::class.java).filter { itx ->
val filtered = events.filterIsInstance<TrackedObject>().filter { itx ->
DrivingDirectionUtils.getDegreeOfCar2Poi(
car.longitude,
car.latitude,
@@ -140,33 +146,62 @@ internal object V2NIdentifyDrawer {
)
)
)
CallerHmiManager.warningV2X(
poiType,
alertContent,
ttsContent,
object : IMoGoWarningStatusListener {
override fun onShow() {
super.onShow()
runCatching { CallerHmiManager.notifyXiaoZhiStatusChanged(V2N(EventTypeEnumNew.getEnumType(poiType)), State.START) }
CallerVisualAngleManager.changeAngle(
RoadEvent(
itx.longitude,
itx.latitude,
itx.angle
)
)
// CallerHmiManager.warningV2X(
// poiType,
// alertContent,
// ttsContent,
// object : IMoGoWarningStatusListener {
// override fun onShow() {
// super.onShow()
// runCatching { CallerHmiManager.notifyXiaoZhiStatusChanged(V2N(EventTypeEnumNew.getEnumType(poiType)), State.START) }
// CallerVisualAngleManager.changeAngle(
// RoadEvent(
// itx.longitude,
// itx.latitude,
// itx.angle
// )
// )
// }
//
// override fun onDismiss() {
// super.onDismiss()
// runCatching { CallerHmiManager.notifyXiaoZhiStatusChanged(V2N(EventTypeEnumNew.getEnumType(poiType)), State.STOP) }
// CallerVisualAngleManager.changeAngle(Default())
// }
// },
// ALERT_WARNING_TOP,
// 10000,
// false
// )
if (polygon.isNotEmpty()) {
val decision = V2NUtils.computeOccupyLanesInfo(Triple(car.longitude, car.latitude, car.heading.toFloat()), Triple(itx.longitude, itx.latitude, itx.heading.toFloat()), polygon.map { kotlin.Pair(it.first, it.second) })
if (decision != null) {
val isDriver = AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)
val total = decision.total
val occupy = decision.occupy
val laneId = decision.laneId
val sb = StringBuilder()
if (laneId != null) {
val isOccupy = occupy.find { it.id == laneId } != null
if (isOccupy) {
if (isDriver) {
val bestLane = computeBestLane(laneId, occupy, total)
sb.append("发现前方${distance.toInt()}${ if (poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType) "车道施工" else "车道事故" }, 蘑菇建议您尽快${bestLane.second}")
} else {
sb.append("发现前方${distance.toInt()}${ if (poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType) "车道施工" else "车道事故" }, 蘑菇时刻为您守护")
}
} else {
if (isDriver) {
sb.append("发现前方${distance.toInt()}${ if (poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType) "车道施工" else "车道事故" }, 蘑菇提醒您小心${ if (computeDirection(laneId, occupy) > 0) "右侧" else "左侧" }行人及来车")
} else {
sb.append("发现前方${distance.toInt()}${ if (poiType == EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType) "车道施工" else "车道事故" }, 蘑菇时刻为您守护")
}
}
}
override fun onDismiss() {
super.onDismiss()
runCatching { CallerHmiManager.notifyXiaoZhiStatusChanged(V2N(EventTypeEnumNew.getEnumType(poiType)), State.STOP) }
CallerVisualAngleManager.changeAngle(Default())
}
},
ALERT_WARNING_TOP,
10000,
false
)
val alert = sb.toString()
CallerRoadV2NEventWindowListenerManager.show("${itx.longitude}-${itx.latitude}", itx.systemTime.toLong(), EventTypeEnumNew.getMarker3DRes(poiType), alert, isDriver, itx.cameraIp, itx.longitude, itx.latitude)
}
}
//消息埋点
V2XEventAnalyticsManager.triggerV2XEvent(
poiType, alertContent, ttsContent,
@@ -184,7 +219,7 @@ internal object V2NIdentifyDrawer {
return@Callback true
}
val car = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84()
val filtered = events.filterIsInstance(MogoV2X.RTEData_PB::class.java).filter { itx ->
val filtered = events.filterIsInstance<RTEData_PB>().filter { itx ->
val eventLon =
itx.eventPos?.offsetLL?.positionLatLon?.lon?.let { it * 1.0 / 10_000_000 }
?: 0.0
@@ -291,6 +326,55 @@ internal object V2NIdentifyDrawer {
true
}
private fun computeDirection(laneId: Int, occupy: List<Lane>): Int {
val left = occupy.first()
return if (laneId <= left.id) {
1
} else {
-1
}
}
private fun computeBestLane(laneId: Int, occupy: List<Lane>, total: List<Lane>): kotlin.Pair<Int, String> {
if (occupy.size == total.size) {
return kotlin.Pair(Int.MIN_VALUE, "更换路线")
}
val map = HashMap<Int, String>()
if (total.size % 2 == 0) {
val half = total.size / 2
for (i in 0 until half) {
val left = total[i]
val right = total[half + i]
map[left.id] = "驶入左${i + 1}车道"
map[right.id] = "驶入右${i + 1}车道"
}
} else {
val middle = total.size / 2
map[total[middle].id] = "驶入中间车道"
for (i in 0 until middle) {
val left = total[i]
val right = total[middle + i + 1]
map[left.id] = "驶入左${i + 1}车道"
map[right.id] = "驶入右${i + 1}车道"
}
}
val ids = occupy.map { it.id }
val freeLanes = total.filter { itx -> !ids.contains(itx.id) }
if (freeLanes.isNotEmpty()) {
var best = Int.MIN_VALUE
var delta = Int.MAX_VALUE
for (lane in freeLanes) {
val abs = kotlin.math.abs(lane.id - laneId)
if (abs < delta && lane.id != laneId) {
best = lane.id
delta = abs
}
}
return kotlin.Pair(best, map[best] ?: "更换路线")
}
return kotlin.Pair(Int.MIN_VALUE, "更换路线")
}
private fun getTtsContent(poiType: String, distance: Double): String {
return when (poiType) {
EventTypeEnumNew.TYPE_SOCKET_ROAD_SHIGONG.poiType -> {

View File

@@ -5,17 +5,16 @@ import android.graphics.Color
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.util.Log
import android.view.animation.DecelerateInterpolator
import androidx.core.util.Pair
import com.mogo.eagle.core.data.map.MogoLatLng
import com.mogo.eagle.core.data.map.entity.V2XRoadEventEntity
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager
import com.mogo.eagle.core.function.call.hmi.CallerRoadV2NEventWindowListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils
import com.mogo.eagle.function.biz.v2x.V2XBizTrace
import com.mogo.eagle.function.biz.v2x.v2n.V2XEventManager
import com.mogo.eagle.function.biz.v2x.v2n.consts.V2XConst
import com.mogo.eagle.function.biz.v2x.v2n.remove.MarkerRemoveManager
import com.mogo.eagle.function.biz.v2x.v2n.remove.MarkerWrapper
@@ -232,7 +231,10 @@ class AiRoadMarker {
wrapper.addLine(line)
}
wrapper.onRemoved = { id ->
aiMakers.remove(id)
aiMakers.remove(id)?.also {
val m = it.marker.get()
CallerRoadV2NEventWindowListenerManager.dismiss("${m.poi_lon}-${m.poi_lat}")
}
}
MarkerRemoveManager.addMarker(wrapper)
countDown.set(0)
@@ -257,6 +259,7 @@ class AiRoadMarker {
roadMarker.removeMarkers()
handler.removeCallbacks(checkExpiredTask)
aiMakers.remove(marker.id)
CallerRoadV2NEventWindowListenerManager.dismiss("${marker.poi_lon}-${marker.poi_lat}")
}
}

View File

@@ -0,0 +1,45 @@
package com.mogo.eagle.function.biz.v2x.v2n.utils
import android.util.Log
import androidx.annotation.WorkerThread
import com.mogo.map.MapDataWrapper
import com.mogo.map.entities.Lane
import com.zhidaoauto.map.data.road.CenterLine
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.GeometryFactory
import java.util.concurrent.CountDownLatch
object V2NUtils {
private const val TAG = "V2NUtils"
@WorkerThread
fun computeOccupyLanesInfo(car: Triple<Double, Double, Float>, point: Triple<Double, Double, Float> ,polygon: List<Pair<Double, Double>>): Decision? {
val roadInfo = MapDataWrapper.getRoadInfo(point.first, point.second, point.third)
Log.d(TAG, "road_info:$roadInfo")
val lanes = MapDataWrapper.getLaneInfo(roadInfo.tileId, roadInfo.roadId)
Log.d(TAG, "lanes: ${lanes.joinToString(",") { itx -> itx.points.joinToString(",") { "${it.first}, ${it.second}" } } }")
if (lanes.isEmpty()) {
return null
}
val occupy = ArrayList<Lane>()
val factory = GeometryFactory()
for (lane in lanes) {
val p1 = factory.createPolygon(polygon.map { Coordinate(it.first, it.second) }.toTypedArray())
val p2 = factory.createLineString(lane.points.map { Coordinate(it.first, it.second) }.toTypedArray()).buffer((lane.width.toDouble() * 0.7 * (1e-5)) / 2.0)
if (p1.intersects(p2)) {
occupy += lane
}
}
val latch = CountDownLatch(1)
var centerLine: CenterLine? = null
MapDataWrapper.getCenterLineInfo(car.first, car.second, car.third) {
centerLine = it
latch.countDown()
}
latch.await()
return Decision(centerLine?.lane_id?.toInt() , lanes, occupy)
}
data class Decision(val laneId: Int? = null,val total: List<Lane>, val occupy: List<Lane>)
}

View File

@@ -172,9 +172,9 @@ public class RouteOverlayDrawer {
}
double lon = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLongitude();
double lat = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84().getLatitude();
if (points.size() > 0) {
if (!points.isEmpty()) {
MogoLatLng top = null;
while (points.size() != 0) {
while (!points.isEmpty()) {
MogoLatLng first = points.peek();
if (first == null) {
continue;
@@ -194,7 +194,7 @@ public class RouteOverlayDrawer {
}
top = first;
}
if (points.size() == 0) {
if (points.isEmpty()) {
isExcept = true;
return;
}
@@ -251,7 +251,7 @@ public class RouteOverlayDrawer {
if (isExcept) {
setVisible(false);
}
if (points.size() > 0) {
if (!points.isEmpty()) {
for (int i = 0; i < points.size(); i++) {
MogoLatLng latLng = points.get(i);
if (latLng == null) {