From ef2e8576d16c73a78bfa3f8fd121b5446b1df58b Mon Sep 17 00:00:00 2001 From: yangyakun Date: Mon, 4 Sep 2023 19:57:06 +0800 Subject: [PATCH] [6.0.0] [auto] [pre check auto] --- .../TrajectoryAndDistanceManager.kt | 86 +++++++++++-------- .../distancemamager/TrajectoryCache.kt | 67 +++++++++++++++ 2 files changed, 115 insertions(+), 38 deletions(-) create mode 100644 OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryCache.kt diff --git a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryAndDistanceManager.kt b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryAndDistanceManager.kt index ed0a0b4c39..a428670980 100644 --- a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryAndDistanceManager.kt +++ b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryAndDistanceManager.kt @@ -22,6 +22,7 @@ import io.reactivex.schedulers.Schedulers import mogo.telematics.pad.MessagePad import java.util.concurrent.ConcurrentHashMap + /** * 计算当前位置距离站点距离和走过的和未走过的轨迹点 */ @@ -92,7 +93,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ globalPathResp?.wayPointsList?.let { if (it.size > 0) { d(M_OCHCOMMON + TAG, "收到轨迹:${it.size}第一个点${it[0]}最后一个点:${it.last()}") - if(globalPathResp.lineId!=null) { + if(globalPathResp.lineId!=null) {// 适配低版本不传递lineId if (globalPathResp.lineId == lineId && !mRoutePoints.isNullOrEmpty()) { d(M_OCHCOMMON + TAG, "重复轨迹") startCalculateDistanceLoop() @@ -114,6 +115,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ val latLngModels = CoordinateCalculateRouteUtil .coordinateConverterWgsToGcjLocations(AbsMogoApplication.getApp(), routePoints!!) mRoutePoints = latLngModels + TrajectoryCache.writeLastTrajectory2jsonFile(latLngModels, lineId.toString()) mRoutePointsDistance = ArrayList() maxDistanceAllPoint = 0.0 @@ -132,6 +134,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ } } + private fun removeTempData() { resetStation() preCarLocationIndexInTrajectory = 0 @@ -160,6 +163,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ removeTempData() endCalculateDistanceLoop() cleanRoutePoints() + TrajectoryCache.deleteCatcheFile() this.endStationInfo.stationPoint = null this.startStationInfo.stationPoint = null this.lineId = null @@ -170,6 +174,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ if(this.lineId!=lineId){ resetStation() cleanRoutePoints() + TrajectoryCache.deleteCatcheFile() stationDistance.clear() } }else{ @@ -573,15 +578,15 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ /** * 距离轨迹的距离 */ - private fun distanceWithTrajectory():String{ + private fun distanceWithTrajectory(redCatche: MutableList): String { val currentPoint = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02() // 判断距离轨迹的距离 val carLocationInfo: Triple = CoordinateCalculateRouteUtil.getNearestPointInfo( 0, - mRoutePoints!!.size - 1, - mRoutePoints!!, + redCatche.size - 1, + redCatche, currentPoint, 2, useHeading = false @@ -589,43 +594,40 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ if (carLocationInfo.third <= OchCommonConst.AUTOMATIC_PLANNING_MAX_DISTANCE) { return ""// 可以启动自驾 } else { - mRoutePoints?.let { - // 判断距离线段的距离 垂足的距离 - val nextPoint: MogoLocation - val prePoint: MogoLocation - if (carLocationInfo.second == true) { - if (carLocationInfo.first > 0) { - nextPoint = it[carLocationInfo.first] - prePoint = it[carLocationInfo.first - 1] - } else { - // 距离第一个点大于15m 过远 - return "距离第一个轨迹点超过15m:${carLocationInfo.first}米" - } + // 判断距离线段的距离 垂足的距离 + val nextPoint: MogoLocation + val prePoint: MogoLocation + if (carLocationInfo.second == true) { + if (carLocationInfo.first > 0) { + nextPoint = redCatche[carLocationInfo.first] + prePoint = redCatche[carLocationInfo.first - 1] } else { - if (carLocationInfo.first + 1 < it.size) { - nextPoint = it[carLocationInfo.first + 1] - prePoint = it[carLocationInfo.first] - } else { - nextPoint = it[carLocationInfo.first] - prePoint = it[carLocationInfo.first - 1] - } + // 距离第一个点大于15m 过远 + return "距离第一个轨迹点超过15m:${carLocationInfo.first}米" } - val pointToLine = LocationUtils.pointToLine( - prePoint.longitude, - prePoint.latitude, - nextPoint.longitude, - nextPoint.latitude, - currentPoint.longitude, - currentPoint.latitude - ) - if (pointToLine <= OchCommonConst.AUTOMATIC_PLANNING_MAX_DISTANCE) { - return "" + } else { + if (carLocationInfo.first + 1 < redCatche.size) { + nextPoint = redCatche[carLocationInfo.first + 1] + prePoint = redCatche[carLocationInfo.first] } else { - return "距离轨迹线的距离大于15m,无法启动自驾" + nextPoint = redCatche[carLocationInfo.first] + prePoint = redCatche[carLocationInfo.first - 1] } } + val pointToLine = LocationUtils.pointToLine( + prePoint.longitude, + prePoint.latitude, + nextPoint.longitude, + nextPoint.latitude, + currentPoint.longitude, + currentPoint.latitude + ) + return if (pointToLine <= OchCommonConst.AUTOMATIC_PLANNING_MAX_DISTANCE) { + "" + } else { + "距离轨迹线的距离大于15m,无法启动自驾" + } } - return "未能计算出车辆距离轨迹或站点的距离" } @@ -641,16 +643,24 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ try { if(mRoutePoints.isNullOrEmpty()){ // 判断距离起始站的距离 - return distanceWithStartStation() + // 没有收到过轨迹 + // 收到过轨迹 且底盘没有在自动驾驶中(没办法申请轨迹) 自驾中重启底盘的形式 + val redCatche = TrajectoryCache.redCatche(lineId.toString()) + return if(redCatche.isNullOrEmpty()){ + distanceWithStartStation() + }else{ + distanceWithTrajectory(redCatche) + } + }else { return if (this.lineId == 0L || this.lineId == null) { - distanceWithTrajectory() + distanceWithTrajectory(mRoutePoints!!) } else { if (lineId != this.lineId) { // 判断距离起始站的距离 distanceWithStartStation() } else { - distanceWithTrajectory() + distanceWithTrajectory(mRoutePoints!!) } } } diff --git a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryCache.kt b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryCache.kt new file mode 100644 index 0000000000..da7f1e62d5 --- /dev/null +++ b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/distancemamager/TrajectoryCache.kt @@ -0,0 +1,67 @@ +package com.mogo.och.common.module.manager.distancemamager + +import com.elegant.network.utils.GsonUtil +import com.mogo.commons.AbsMogoApplication +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_OCHCOMMON +import java.io.File +import java.io.FileReader +import java.io.FileWriter +import java.io.IOException + +object TrajectoryCache { + + private const val TAG = "TrajectoryCache" + + private val dir = "${AbsMogoApplication.getApp().cacheDir}/trajectory/" + + fun writeLastTrajectory2jsonFile(latLngModels: MutableList,name:String) { + val jsonFromObject = GsonUtil.jsonFromObject(latLngModels) + try { + val path = File(dir) + if(!path.exists()){ + path.mkdir() + }else { + path.deleteRecursively() + CallerLogger.d(M_OCHCOMMON + TAG,"删除缓存") + path.mkdir() + } + val writer = FileWriter("${path.path}/${name}") + writer.write(jsonFromObject) + writer.close() + CallerLogger.d(M_OCHCOMMON + TAG,"写入缓存") + } catch (e: IOException) { + e.printStackTrace() + } + } + + fun deleteCatcheFile(){ + try { + val path = File(dir) + if(path.exists()){ + path.deleteRecursively() + CallerLogger.d(M_OCHCOMMON + TAG,"删除缓存") + } + } catch (e: IOException) { + e.printStackTrace() + } + } + + fun redCatche(name: String): MutableList? { + try { + val path = File(dir) + if(!path.exists()){ + return null + } + val fileReader = FileReader("${path.path}/${name}") + val readText = fileReader.readText() + fileReader.close() + return GsonUtil.arrayFromJson(readText, MogoLocation::class.java) + } catch (e: IOException) { + e.printStackTrace() + } + return null + } + +} \ No newline at end of file