[auto]
[pre check auto]
This commit is contained in:
yangyakun
2023-09-04 19:57:06 +08:00
parent 3776a864d4
commit ef2e8576d1
2 changed files with 115 additions and 38 deletions

View File

@@ -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<MogoLocation>): String {
val currentPoint =
CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()
// 判断距离轨迹的距离
val carLocationInfo: Triple<Int, Boolean?, Float> =
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!!)
}
}
}

View File

@@ -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<MogoLocation>,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<MogoLocation>? {
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
}
}