[6.1.0]
[格式化]
This commit is contained in:
@@ -26,26 +26,37 @@ import java.util.concurrent.ConcurrentHashMap
|
|||||||
/**
|
/**
|
||||||
* 计算当前位置距离站点距离和走过的和未走过的轨迹点
|
* 计算当前位置距离站点距离和走过的和未走过的轨迹点
|
||||||
*/
|
*/
|
||||||
object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
object TrajectoryAndDistanceManager : IMoGoPlanningRottingListener {
|
||||||
|
|
||||||
private val distanceListeners: ConcurrentHashMap<String, IDistanceListener> = ConcurrentHashMap()
|
private val distanceListeners: ConcurrentHashMap<String, IDistanceListener> =
|
||||||
private val trajectoryListeners: ConcurrentHashMap<String, ITrajectoryListener> = ConcurrentHashMap()
|
ConcurrentHashMap()
|
||||||
private val trajectoryWithStationListeners: ConcurrentHashMap<String, ITrajectoryWithStationListener> = ConcurrentHashMap()
|
private val trajectoryListeners: ConcurrentHashMap<String, ITrajectoryListener> =
|
||||||
|
ConcurrentHashMap()
|
||||||
|
private val trajectoryWithStationListeners: ConcurrentHashMap<String, ITrajectoryWithStationListener> =
|
||||||
|
ConcurrentHashMap()
|
||||||
|
|
||||||
const val TAG = "DistanceManager"
|
const val TAG = "DistanceManager"
|
||||||
const val TAGDISTANCE = "BusPassengerModelDistance"
|
const val TAGDISTANCE = "BusPassengerModelDistance"
|
||||||
|
|
||||||
|
|
||||||
fun addDistanceListener(tag: String, listener: IDistanceListener) {
|
fun addDistanceListener(tag: String, listener: IDistanceListener) {
|
||||||
if (distanceListeners.containsKey(tag)) { return }
|
if (distanceListeners.containsKey(tag)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
distanceListeners[tag] = listener
|
distanceListeners[tag] = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTrajectoryListener(tag: String, listener: ITrajectoryListener) {
|
fun addTrajectoryListener(tag: String, listener: ITrajectoryListener) {
|
||||||
if (trajectoryListeners.containsKey(tag)) { return }
|
if (trajectoryListeners.containsKey(tag)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
trajectoryListeners[tag] = listener
|
trajectoryListeners[tag] = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTrajectoryWithStationListener(tag: String, listener: ITrajectoryWithStationListener) {
|
fun addTrajectoryWithStationListener(tag: String, listener: ITrajectoryWithStationListener) {
|
||||||
if (trajectoryWithStationListeners.containsKey(tag)) { return }
|
if (trajectoryWithStationListeners.containsKey(tag)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
trajectoryWithStationListeners[tag] = listener
|
trajectoryWithStationListeners[tag] = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,17 +71,18 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var mRoutePoints: MutableList<MogoLocation>? = ArrayList()
|
private var mRoutePoints: MutableList<MogoLocation>? = ArrayList()
|
||||||
|
|
||||||
// 0-1 1-2 2-3 各个轨迹点的距离
|
// 0-1 1-2 2-3 各个轨迹点的距离
|
||||||
private var mRoutePointsDistance: MutableList<Float>? = ArrayList()
|
private var mRoutePointsDistance: MutableList<Float>? = ArrayList()
|
||||||
|
|
||||||
// 所有轨迹点距离的和
|
// 所有轨迹点距离的和
|
||||||
private var maxDistanceAllPoint:Double = 0.0
|
private var maxDistanceAllPoint: Double = 0.0
|
||||||
private val stationDistance: ConcurrentHashMap<String, Float> = ConcurrentHashMap()
|
private val stationDistance: ConcurrentHashMap<String, Float> = ConcurrentHashMap()
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var lineId:Long? = null
|
private var lineId: Long? = null
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var endStationInfo: StationAndIndex = StationAndIndex(null, null, null, null)
|
private var endStationInfo: StationAndIndex = StationAndIndex(null, null, null, null)
|
||||||
@@ -92,8 +104,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
d(M_OCHCOMMON + TAG, "onAutopilotRotting: 收到轨迹")
|
d(M_OCHCOMMON + TAG, "onAutopilotRotting: 收到轨迹")
|
||||||
globalPathResp?.wayPointsList?.let {
|
globalPathResp?.wayPointsList?.let {
|
||||||
if (it.size > 0) {
|
if (it.size > 0) {
|
||||||
d(M_OCHCOMMON + TAG, "收到轨迹:轨迹个数${it.size}第一个点${it[0]}最后一个点:${it.last()} 轨迹id:${globalPathResp.lineId}")
|
d(
|
||||||
if(globalPathResp.lineId!=null) {// 适配低版本不传递lineId
|
M_OCHCOMMON + TAG,
|
||||||
|
"收到轨迹:轨迹个数${it.size}第一个点${it[0]}最后一个点:${it.last()} 轨迹id:${globalPathResp.lineId}"
|
||||||
|
)
|
||||||
|
if (globalPathResp.lineId != null) {// 适配低版本不传递lineId
|
||||||
if (globalPathResp.lineId == lineId && !mRoutePoints.isNullOrEmpty()) {
|
if (globalPathResp.lineId == lineId && !mRoutePoints.isNullOrEmpty()) {
|
||||||
d(M_OCHCOMMON + TAG, "重复轨迹")
|
d(M_OCHCOMMON + TAG, "重复轨迹")
|
||||||
startCalculateDistanceLoop()
|
startCalculateDistanceLoop()
|
||||||
@@ -120,7 +135,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
mRoutePointsDistance = ArrayList()
|
mRoutePointsDistance = ArrayList()
|
||||||
maxDistanceAllPoint = 0.0
|
maxDistanceAllPoint = 0.0
|
||||||
mRoutePoints?.forEachIndexed { index, current ->
|
mRoutePoints?.forEachIndexed { index, current ->
|
||||||
if (mRoutePoints!!.last()!=current) {
|
if (mRoutePoints!!.last() != current) {
|
||||||
val next = mRoutePoints!![index + 1]
|
val next = mRoutePoints!![index + 1]
|
||||||
val distanceItem = CoordinateUtils.calculateLineDistance(
|
val distanceItem = CoordinateUtils.calculateLineDistance(
|
||||||
current.longitude,
|
current.longitude,
|
||||||
@@ -138,8 +153,9 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
private fun removeTempData() {
|
private fun removeTempData() {
|
||||||
resetStation()
|
resetStation()
|
||||||
preCarLocationIndexInTrajectory = 0
|
preCarLocationIndexInTrajectory = 0
|
||||||
lineId = null
|
lineId = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetStation() {
|
private fun resetStation() {
|
||||||
this.endStationInfo.index = null
|
this.endStationInfo.index = null
|
||||||
this.endStationInfo.distance = null
|
this.endStationInfo.distance = null
|
||||||
@@ -157,8 +173,15 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
/**
|
/**
|
||||||
* 设置或清理站点坐标
|
* 设置或清理站点坐标
|
||||||
*/
|
*/
|
||||||
fun setStationPoint(startStationInfo: MogoLocation?,endStationInfo: MogoLocation?,lineId:Long?) {
|
fun setStationPoint(
|
||||||
d(M_OCHCOMMON+ TAG,"线路id:${lineId}设置站点:开始站点${startStationInfo}、结束站点:${endStationInfo}")
|
startStationInfo: MogoLocation?,
|
||||||
|
endStationInfo: MogoLocation?,
|
||||||
|
lineId: Long?
|
||||||
|
) {
|
||||||
|
d(
|
||||||
|
M_OCHCOMMON + TAG,
|
||||||
|
"线路id:${lineId}设置站点:开始站点${startStationInfo}、结束站点:${endStationInfo}"
|
||||||
|
)
|
||||||
if (startStationInfo == null || endStationInfo == null || lineId == -1L) {
|
if (startStationInfo == null || endStationInfo == null || lineId == -1L) {
|
||||||
removeTempData()
|
removeTempData()
|
||||||
endCalculateDistanceLoop()
|
endCalculateDistanceLoop()
|
||||||
@@ -168,20 +191,21 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
this.startStationInfo.stationPoint = null
|
this.startStationInfo.stationPoint = null
|
||||||
this.lineId = null
|
this.lineId = null
|
||||||
stationDistance.clear()
|
stationDistance.clear()
|
||||||
}else{
|
} else {
|
||||||
if(isSameStation(this.startStationInfo.stationPoint,startStationInfo)&&
|
if (isSameStation(this.startStationInfo.stationPoint, startStationInfo) &&
|
||||||
isSameStation(this.endStationInfo.stationPoint,endStationInfo)){
|
isSameStation(this.endStationInfo.stationPoint, endStationInfo)
|
||||||
if(this.lineId!=lineId){
|
) {
|
||||||
|
if (this.lineId != lineId) {
|
||||||
resetStation()
|
resetStation()
|
||||||
cleanRoutePoints()
|
cleanRoutePoints()
|
||||||
TrajectoryCache.deleteCatcheFile()
|
TrajectoryCache.deleteCatcheFile()
|
||||||
stationDistance.clear()
|
stationDistance.clear()
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
resetStation()
|
resetStation()
|
||||||
if (this.lineId == 0L || this.lineId == null) {
|
if (this.lineId == 0L || this.lineId == null) {
|
||||||
// 兼容老MAP 不返回轨迹id lineID
|
// 兼容老MAP 不返回轨迹id lineID
|
||||||
}else {
|
} else {
|
||||||
if (this.lineId != lineId) {// bus 切换站点不会切线路
|
if (this.lineId != lineId) {// bus 切换站点不会切线路
|
||||||
cleanRoutePoints()
|
cleanRoutePoints()
|
||||||
TrajectoryCache.deleteCatcheFile()
|
TrajectoryCache.deleteCatcheFile()
|
||||||
@@ -196,11 +220,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSameStation(stationOne: MogoLocation?,stationTwo: MogoLocation?):Boolean{
|
private fun isSameStation(stationOne: MogoLocation?, stationTwo: MogoLocation?): Boolean {
|
||||||
if(stationOne==null||stationTwo==null){
|
if (stationOne == null || stationTwo == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(stationOne.longitude==stationTwo.longitude&&stationOne.latitude==stationTwo.latitude){
|
if (stationOne.longitude == stationTwo.longitude && stationOne.latitude == stationTwo.latitude) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -218,7 +242,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
endCalculateDistanceLoop()
|
endCalculateDistanceLoop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(it.latitude==0.0&&it.longitude==0.0){
|
if (it.latitude == 0.0 && it.longitude == 0.0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
calculateRouteSumLength(it)
|
calculateRouteSumLength(it)
|
||||||
@@ -228,11 +252,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
/**
|
/**
|
||||||
* 暂停路距计算
|
* 暂停路距计算
|
||||||
*/
|
*/
|
||||||
fun suspendCalculate(){
|
fun suspendCalculate() {
|
||||||
endCalculateDistanceLoop()
|
endCalculateDistanceLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reStartCalculate(){
|
fun reStartCalculate() {
|
||||||
startCalculateDistanceLoop()
|
startCalculateDistanceLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,9 +264,12 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
* 启动路距计算
|
* 启动路距计算
|
||||||
*/
|
*/
|
||||||
private fun startCalculateDistanceLoop() {
|
private fun startCalculateDistanceLoop() {
|
||||||
BizLoopManager.setLoopFunction(TAGDISTANCE, LoopInfo(1, ::calculateDistance,
|
BizLoopManager.setLoopFunction(
|
||||||
scheduler = Schedulers.computation()
|
TAGDISTANCE, LoopInfo(
|
||||||
))
|
1, ::calculateDistance,
|
||||||
|
scheduler = Schedulers.computation()
|
||||||
|
)
|
||||||
|
)
|
||||||
d(M_OCHCOMMON + TAG, "开始路距计算")
|
d(M_OCHCOMMON + TAG, "开始路距计算")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +287,8 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
location: MogoLocation,
|
location: MogoLocation,
|
||||||
) {
|
) {
|
||||||
val autoPilotState = CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state
|
val autoPilotState = CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state
|
||||||
val locationInfo = "自动驾驶状态:$autoPilotState line信息:${lineId}定位信息:${location.latitude},${location.longitude},${location.heading} 当前速度:${location.gnssSpeed}"
|
val locationInfo =
|
||||||
|
"自动驾驶状态:$autoPilotState line信息:${lineId}定位信息:${location.latitude},${location.longitude},${location.heading} 当前速度:${location.gnssSpeed}"
|
||||||
if (mRoutePoints.isNullOrEmpty()) return
|
if (mRoutePoints.isNullOrEmpty()) return
|
||||||
// 计算起始站点在轨迹中的信息 这个是一个常量
|
// 计算起始站点在轨迹中的信息 这个是一个常量
|
||||||
if (startStationInfo.stationPoint != null
|
if (startStationInfo.stationPoint != null
|
||||||
@@ -270,14 +298,19 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
) {
|
) {
|
||||||
//要前往的站在轨迹中对应的点的信息
|
//要前往的站在轨迹中对应的点的信息
|
||||||
val startStationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
val startStationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
||||||
preCarLocationIndexInTrajectory, mRoutePoints!!.size,mRoutePoints!!, startStationInfo.stationPoint!!,1
|
preCarLocationIndexInTrajectory,
|
||||||
|
mRoutePoints!!.size,
|
||||||
|
mRoutePoints!!,
|
||||||
|
startStationInfo.stationPoint!!,
|
||||||
|
1
|
||||||
)
|
)
|
||||||
this.startStationInfo.isNext = startStationInfo.second
|
this.startStationInfo.isNext = startStationInfo.second
|
||||||
this.startStationInfo.index = startStationInfo.first
|
this.startStationInfo.index = startStationInfo.first
|
||||||
this.startStationInfo.distance = startStationInfo.third
|
this.startStationInfo.distance = startStationInfo.third
|
||||||
preCarLocationIndexInTrajectory = startStationInfo.first
|
preCarLocationIndexInTrajectory = startStationInfo.first
|
||||||
val calculateData = "距离起始站点最近的点:${startStationInfo.first} 点在站的后面:${startStationInfo.second} 距离点的距离:${startStationInfo.third}"
|
val calculateData =
|
||||||
writeLog(calculateData,locationInfo)
|
"距离起始站点最近的点:${startStationInfo.first} 点在站的后面:${startStationInfo.second} 距离点的距离:${startStationInfo.third}"
|
||||||
|
writeLog(calculateData, locationInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算结束站点在轨迹中的信息 这个是一个常量可以缓存
|
// 计算结束站点在轨迹中的信息 这个是一个常量可以缓存
|
||||||
@@ -288,18 +321,23 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
) {
|
) {
|
||||||
//要前往的站在轨迹中对应的点
|
//要前往的站在轨迹中对应的点
|
||||||
val endStationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
val endStationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
||||||
preCarLocationIndexInTrajectory,mRoutePoints!!.size, mRoutePoints!!, endStationInfo.stationPoint!!,3
|
preCarLocationIndexInTrajectory,
|
||||||
|
mRoutePoints!!.size,
|
||||||
|
mRoutePoints!!,
|
||||||
|
endStationInfo.stationPoint!!,
|
||||||
|
3
|
||||||
)
|
)
|
||||||
this.endStationInfo.isNext = endStationInfo.second
|
this.endStationInfo.isNext = endStationInfo.second
|
||||||
this.endStationInfo.index = endStationInfo.first
|
this.endStationInfo.index = endStationInfo.first
|
||||||
this.endStationInfo.distance = endStationInfo.third
|
this.endStationInfo.distance = endStationInfo.third
|
||||||
val calculateData = "距离结束站点最近的点:${endStationInfo.first} 点在站的后面:${endStationInfo.second} 距离点的距离:${endStationInfo.third}"
|
val calculateData =
|
||||||
|
"距离结束站点最近的点:${endStationInfo.first} 点在站的后面:${endStationInfo.second} 距离点的距离:${endStationInfo.third}"
|
||||||
writeLog(calculateData, locationInfo)
|
writeLog(calculateData, locationInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (endStationInfo.stationPoint != null
|
if (endStationInfo.stationPoint != null
|
||||||
&& endStationInfo.isNext!= null
|
&& endStationInfo.isNext != null
|
||||||
&& endStationInfo.index != null
|
&& endStationInfo.index != null
|
||||||
&& endStationInfo.distance != null
|
&& endStationInfo.distance != null
|
||||||
&& startStationInfo.stationPoint != null
|
&& startStationInfo.stationPoint != null
|
||||||
@@ -309,39 +347,44 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
) {
|
) {
|
||||||
calculateStationDistance()
|
calculateStationDistance()
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e(M_OCHCOMMON+ TAG,"计算两个站点间的距离")
|
e(M_OCHCOMMON + TAG, "计算两个站点间的距离")
|
||||||
}
|
}
|
||||||
|
|
||||||
val carLocationInfo:Triple<Int,Boolean?,Float>
|
val carLocationInfo: Triple<Int, Boolean?, Float>
|
||||||
if(endStationInfo.isNext==true){
|
if (endStationInfo.isNext == true) {
|
||||||
// 计算车的位置在轨迹中的信息 这个是一个变量可以缓存
|
// 计算车的位置在轨迹中的信息 这个是一个变量可以缓存
|
||||||
carLocationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
carLocationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
||||||
preCarLocationIndexInTrajectory,endStationInfo.index!!, mRoutePoints!!, location,2
|
preCarLocationIndexInTrajectory, endStationInfo.index!!, mRoutePoints!!, location, 2
|
||||||
)
|
)
|
||||||
}else{
|
} else {
|
||||||
carLocationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
carLocationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
|
||||||
preCarLocationIndexInTrajectory,endStationInfo.index!!+1, mRoutePoints!!, location,2
|
preCarLocationIndexInTrajectory,
|
||||||
|
endStationInfo.index!! + 1,
|
||||||
|
mRoutePoints!!,
|
||||||
|
location,
|
||||||
|
2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val calculateData = "距离结束站点最近的点:${carLocationInfo.first} 点在站的后面:${carLocationInfo.second} 距离点的距离:${carLocationInfo.third}"
|
val calculateData =
|
||||||
|
"距离结束站点最近的点:${carLocationInfo.first} 点在站的后面:${carLocationInfo.second} 距离点的距离:${carLocationInfo.third}"
|
||||||
writeLog(calculateData, locationInfo)
|
writeLog(calculateData, locationInfo)
|
||||||
if(carLocationInfo.second==null||carLocationInfo.third>1_000){
|
if (carLocationInfo.second == null || carLocationInfo.third > 1_000) {
|
||||||
preCarLocationIndexInTrajectory = 0
|
preCarLocationIndexInTrajectory = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxDisatance = 0.0f
|
var maxDisatance = 0.0f
|
||||||
if(carLocationInfo.second==true){
|
if (carLocationInfo.second == true) {
|
||||||
if(carLocationInfo.first>0) {
|
if (carLocationInfo.first > 0) {
|
||||||
maxDisatance = mRoutePointsDistance?.get(carLocationInfo.first - 1)?:0f
|
maxDisatance = mRoutePointsDistance?.get(carLocationInfo.first - 1) ?: 0f
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
maxDisatance = mRoutePointsDistance?.get(carLocationInfo.first)?:0f
|
maxDisatance = mRoutePointsDistance?.get(carLocationInfo.first) ?: 0f
|
||||||
}
|
}
|
||||||
if(carLocationInfo.third>maxDisatance){
|
if (carLocationInfo.third > maxDisatance) {
|
||||||
preCarLocationIndexInTrajectory = 0
|
preCarLocationIndexInTrajectory = 0
|
||||||
writeLog("到点的距离${carLocationInfo.third},最大距离${maxDisatance}",locationInfo)
|
writeLog("到点的距离${carLocationInfo.third},最大距离${maxDisatance}", locationInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,28 +392,28 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
|
|
||||||
// 距离回调
|
// 距离回调
|
||||||
try {
|
try {
|
||||||
if(distanceListeners.size>0) {
|
if (distanceListeners.size > 0) {
|
||||||
invokeDistance(carLocationInfo, location,locationInfo)
|
invokeDistance(carLocationInfo, location, locationInfo)
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e(M_OCHCOMMON+ TAG,"距离计算错误")
|
e(M_OCHCOMMON + TAG, "距离计算错误")
|
||||||
}
|
}
|
||||||
// 不带站点轨迹回调
|
// 不带站点轨迹回调
|
||||||
try {
|
try {
|
||||||
if(trajectoryListeners.size>0) {
|
if (trajectoryListeners.size > 0) {
|
||||||
invokeTrajectory(carLocationInfo, location)
|
invokeTrajectory(carLocationInfo, location)
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e(M_OCHCOMMON+ TAG,"轨迹线(轨迹两头)计算错误")
|
e(M_OCHCOMMON + TAG, "轨迹线(轨迹两头)计算错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只展示站点之间轨迹
|
// 只展示站点之间轨迹
|
||||||
try {
|
try {
|
||||||
if(trajectoryWithStationListeners.size>0) {
|
if (trajectoryWithStationListeners.size > 0) {
|
||||||
invokeTrajectoryWithStation(carLocationInfo, location)
|
invokeTrajectoryWithStation(carLocationInfo, location)
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e(M_OCHCOMMON+ TAG,"轨迹线(站点两头)计算错误")
|
e(M_OCHCOMMON + TAG, "轨迹线(站点两头)计算错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -381,12 +424,12 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
private fun calculateStationDistance() {
|
private fun calculateStationDistance() {
|
||||||
var lastSumLength = 0f
|
var lastSumLength = 0f
|
||||||
val key = getKey()
|
val key = getKey()
|
||||||
if (stationDistance[key] !=null) {
|
if (stationDistance[key] != null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val stationIndex = endStationInfo.index?:0
|
val stationIndex = endStationInfo.index ?: 0
|
||||||
if (startStationInfo.index!! < stationIndex-1) {
|
if (startStationInfo.index!! < stationIndex - 1) {
|
||||||
// subList 是[) 需要的是[]
|
// subList 是[) 需要的是[]
|
||||||
val subList = mRoutePoints!!.subList(startStationInfo.index!!, stationIndex + 1)
|
val subList = mRoutePoints!!.subList(startStationInfo.index!!, stationIndex + 1)
|
||||||
// 轨迹点所有的距离
|
// 轨迹点所有的距离
|
||||||
@@ -397,7 +440,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
} else {// isNext = false
|
} else {// isNext = false
|
||||||
lastSumLength += stationDistance
|
lastSumLength += stationDistance
|
||||||
}
|
}
|
||||||
if (startStationInfo.isNext==true) {// 是否是下一个 true 下一个
|
if (startStationInfo.isNext == true) {// 是否是下一个 true 下一个
|
||||||
lastSumLength += startStationInfo.distance!!
|
lastSumLength += startStationInfo.distance!!
|
||||||
} else {
|
} else {
|
||||||
lastSumLength -= startStationInfo.distance!!
|
lastSumLength -= startStationInfo.distance!!
|
||||||
@@ -409,10 +452,10 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
lastPoints!!.longitude, lastPoints.latitude
|
lastPoints!!.longitude, lastPoints.latitude
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
d(M_OCHCOMMON+ TAG,"两站点距离:$lastSumLength")
|
d(M_OCHCOMMON + TAG, "两站点距离:$lastSumLength")
|
||||||
stationDistance[key] = lastSumLength
|
stationDistance[key] = lastSumLength
|
||||||
|
|
||||||
if(distanceListeners.size>0) {
|
if (distanceListeners.size > 0) {
|
||||||
distanceListeners.forEach {
|
distanceListeners.forEach {
|
||||||
//val tag = it.key
|
//val tag = it.key
|
||||||
val listener = it.value
|
val listener = it.value
|
||||||
@@ -430,11 +473,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
carLocationInfo: Triple<Int, Boolean?, Float>,
|
carLocationInfo: Triple<Int, Boolean?, Float>,
|
||||||
location: MogoLocation,
|
location: MogoLocation,
|
||||||
locationInfo: String
|
locationInfo: String
|
||||||
){
|
) {
|
||||||
var lastSumLength = 0f
|
var lastSumLength = 0f
|
||||||
|
|
||||||
val stationIndex = endStationInfo.index?:0
|
val stationIndex = endStationInfo.index ?: 0
|
||||||
if (carLocationInfo.first < stationIndex-1) {
|
if (carLocationInfo.first < stationIndex - 1) {
|
||||||
// subList 是[) 需要的是[]
|
// subList 是[) 需要的是[]
|
||||||
val subList = mRoutePoints!!.subList(carLocationInfo.first, stationIndex + 1)
|
val subList = mRoutePoints!!.subList(carLocationInfo.first, stationIndex + 1)
|
||||||
// 轨迹点所有的距离
|
// 轨迹点所有的距离
|
||||||
@@ -457,13 +500,13 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
location.longitude, location.latitude
|
location.longitude, location.latitude
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
d(M_OCHCOMMON+ TAG,"距离终点:$lastSumLength")
|
d(M_OCHCOMMON + TAG, "距离终点:$lastSumLength")
|
||||||
if(lastSumLength>maxDistanceAllPoint){
|
if (lastSumLength > maxDistanceAllPoint) {
|
||||||
// 大于最大值需要需要删除此次计算
|
// 大于最大值需要需要删除此次计算
|
||||||
writeLog("距离终点:$lastSumLength",locationInfo)
|
writeLog("距离终点:$lastSumLength", locationInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(distanceListeners.size>0) {
|
if (distanceListeners.size > 0) {
|
||||||
distanceListeners.forEach {
|
distanceListeners.forEach {
|
||||||
//val tag = it.key
|
//val tag = it.key
|
||||||
val listener = it.value
|
val listener = it.value
|
||||||
@@ -479,15 +522,15 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
if (mRoutePoints.isNullOrEmpty()) return
|
if (mRoutePoints.isNullOrEmpty()) return
|
||||||
val routeArrivied = mutableListOf<MogoLocation>()
|
val routeArrivied = mutableListOf<MogoLocation>()
|
||||||
val routeArriving = mutableListOf<MogoLocation>()
|
val routeArriving = mutableListOf<MogoLocation>()
|
||||||
if(carLocationInfo.second==true){// isNext = true
|
if (carLocationInfo.second == true) {// isNext = true
|
||||||
routeArrivied.addAll(mRoutePoints!!.subList(0,carLocationInfo.first))
|
routeArrivied.addAll(mRoutePoints!!.subList(0, carLocationInfo.first))
|
||||||
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first,mRoutePoints!!.size))
|
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first, mRoutePoints!!.size))
|
||||||
}else{// isNext = false
|
} else {// isNext = false
|
||||||
val indexNext = carLocationInfo.first+1
|
val indexNext = carLocationInfo.first + 1
|
||||||
routeArrivied.addAll(mRoutePoints!!.subList(0,indexNext))
|
routeArrivied.addAll(mRoutePoints!!.subList(0, indexNext))
|
||||||
routeArriving.addAll(mRoutePoints!!.subList(indexNext,mRoutePoints!!.size))
|
routeArriving.addAll(mRoutePoints!!.subList(indexNext, mRoutePoints!!.size))
|
||||||
}
|
}
|
||||||
if(trajectoryListeners.size>0) {
|
if (trajectoryListeners.size > 0) {
|
||||||
trajectoryListeners.forEach {
|
trajectoryListeners.forEach {
|
||||||
//val tag = it.key
|
//val tag = it.key
|
||||||
val listener = it.value
|
val listener = it.value
|
||||||
@@ -510,10 +553,10 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
&& startStationInfo.index != null
|
&& startStationInfo.index != null
|
||||||
&& startStationInfo.distance != null
|
&& startStationInfo.distance != null
|
||||||
) {
|
) {
|
||||||
if(startStationInfo.isNext==true){
|
if (startStationInfo.isNext == true) {
|
||||||
fromCut = startStationInfo.index!!
|
fromCut = startStationInfo.index!!
|
||||||
}else{
|
} else {
|
||||||
fromCut = startStationInfo.index!!+1
|
fromCut = startStationInfo.index!! + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,25 +565,25 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
&& endStationInfo.index != null
|
&& endStationInfo.index != null
|
||||||
&& endStationInfo.distance != null
|
&& endStationInfo.distance != null
|
||||||
) {
|
) {
|
||||||
if(endStationInfo.isNext==true){
|
if (endStationInfo.isNext == true) {
|
||||||
endCut = endStationInfo.index!!
|
endCut = endStationInfo.index!!
|
||||||
}else{
|
} else {
|
||||||
endCut = endStationInfo.index!!+1
|
endCut = endStationInfo.index!! + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d(M_OCHCOMMON+ TAG,"根据站点切个:第一个点:$fromCut 最后一个点$endCut")
|
d(M_OCHCOMMON + TAG, "根据站点切个:第一个点:$fromCut 最后一个点$endCut")
|
||||||
if(carLocationInfo.second==true){// isNext = true
|
if (carLocationInfo.second == true) {// isNext = true
|
||||||
routeArrivied.addAll(mRoutePoints!!.subList(fromCut,carLocationInfo.first))
|
routeArrivied.addAll(mRoutePoints!!.subList(fromCut, carLocationInfo.first))
|
||||||
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first,endCut))
|
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first, endCut))
|
||||||
}else{// isNext = false
|
} else {// isNext = false
|
||||||
val indexNext = carLocationInfo.first+1
|
val indexNext = carLocationInfo.first + 1
|
||||||
routeArrivied.addAll(mRoutePoints!!.subList(fromCut,indexNext))
|
routeArrivied.addAll(mRoutePoints!!.subList(fromCut, indexNext))
|
||||||
routeArriving.addAll(mRoutePoints!!.subList(indexNext,endCut))
|
routeArriving.addAll(mRoutePoints!!.subList(indexNext, endCut))
|
||||||
}
|
}
|
||||||
|
|
||||||
routeArrivied.add(0, startStationInfo.stationPoint!!)
|
routeArrivied.add(0, startStationInfo.stationPoint!!)
|
||||||
routeArriving.add(endStationInfo.stationPoint!!)
|
routeArriving.add(endStationInfo.stationPoint!!)
|
||||||
if(trajectoryWithStationListeners.size>0) {
|
if (trajectoryWithStationListeners.size > 0) {
|
||||||
trajectoryWithStationListeners.forEach {
|
trajectoryWithStationListeners.forEach {
|
||||||
//val tag = it.key
|
//val tag = it.key
|
||||||
val listener = it.value
|
val listener = it.value
|
||||||
@@ -549,23 +592,23 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ChainLog(
|
// @ChainLog(
|
||||||
// linkChainLog = ChainConstant.CHAIN_TYPE_OCH,
|
// linkChainLog = ChainConstant.CHAIN_TYPE_OCH,
|
||||||
// linkCode = ChainConstant.CHAIN_SOURCE_OCH,
|
// linkCode = ChainConstant.CHAIN_SOURCE_OCH,
|
||||||
// nodeAliasCode = ChainConstant.CHAIN_CODE_OCH_COMMON_DISTANCE,
|
// nodeAliasCode = ChainConstant.CHAIN_CODE_OCH_COMMON_DISTANCE,
|
||||||
// paramIndexes = [0,1]
|
// paramIndexes = [0,1]
|
||||||
// )
|
// )
|
||||||
private fun writeLog(carLocationInfo: String, location: String) {
|
private fun writeLog(carLocationInfo: String, location: String) {
|
||||||
d(M_OCHCOMMON+ TAG,carLocationInfo)
|
d(M_OCHCOMMON + TAG, carLocationInfo)
|
||||||
d(M_OCHCOMMON+ TAG,location)
|
d(M_OCHCOMMON + TAG, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 距离站点的距离
|
* 距离站点的距离
|
||||||
*/
|
*/
|
||||||
private fun distanceWithStartStation():String{
|
private fun distanceWithStartStation(): String {
|
||||||
if (startStationInfo.stationPoint==null) {
|
if (startStationInfo.stationPoint == null) {
|
||||||
return "请选择起始结束站点"
|
return "请选择起始结束站点"
|
||||||
}
|
}
|
||||||
val currentPoint = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()
|
val currentPoint = CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02()
|
||||||
@@ -575,9 +618,9 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
startStationInfo.stationPoint!!.longitude,
|
startStationInfo.stationPoint!!.longitude,
|
||||||
startStationInfo.stationPoint!!.latitude
|
startStationInfo.stationPoint!!.latitude
|
||||||
)
|
)
|
||||||
return if(distance <= OchCommonConst.AUTOMATIC_PLANNING_MAX_DISTANCE){
|
return if (distance <= OchCommonConst.AUTOMATIC_PLANNING_MAX_DISTANCE) {
|
||||||
""
|
""
|
||||||
}else{
|
} else {
|
||||||
"距离起始站点过远:${distance}米"
|
"距离起始站点过远:${distance}米"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -644,24 +687,24 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
* 返回空为可启动自驾
|
* 返回空为可启动自驾
|
||||||
* 返回其他不可启动自驾 返回为原因
|
* 返回其他不可启动自驾 返回为原因
|
||||||
*/
|
*/
|
||||||
fun canStartAutopilot(lineId: Long?):String{
|
fun canStartAutopilot(lineId: Long?): String {
|
||||||
if(lineId==null){
|
if (lineId == null) {
|
||||||
return "请确认线路ID"
|
return "请确认线路ID"
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(mRoutePoints.isNullOrEmpty()){
|
if (mRoutePoints.isNullOrEmpty()) {
|
||||||
// 判断距离起始站的距离
|
// 判断距离起始站的距离
|
||||||
// 没有收到过轨迹
|
// 没有收到过轨迹
|
||||||
// 收到过轨迹 且底盘没有在自动驾驶中(没办法申请轨迹) 自驾中重启底盘的形式
|
// 收到过轨迹 且底盘没有在自动驾驶中(没办法申请轨迹) 自驾中重启底盘的形式
|
||||||
val redCatche = TrajectoryCache.redCatche(lineId.toString())
|
val redCatche = TrajectoryCache.redCatche(lineId.toString())
|
||||||
return if(redCatche.isNullOrEmpty()){
|
return if (redCatche.isNullOrEmpty()) {
|
||||||
distanceWithStartStation()
|
distanceWithStartStation()
|
||||||
}else{
|
} else {
|
||||||
distanceWithTrajectory(redCatche)
|
distanceWithTrajectory(redCatche)
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
} else {
|
||||||
return if (this.lineId == 0L || this.lineId == null) {
|
return if (this.lineId == 0L || this.lineId == null) {
|
||||||
distanceWithTrajectory(mRoutePoints!!)
|
distanceWithTrajectory(mRoutePoints!!)
|
||||||
} else {
|
} else {
|
||||||
@@ -673,7 +716,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user