[dev_arch_opt_3.0]

[Change]
[
1、修复在斑马线修改了高德坐标系的自车位置导致,其它地方监听异常。
]

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2023-03-17 18:00:04 +08:00
committed by yangyakun
parent 167cf71911
commit ac8b4164ba
4 changed files with 80 additions and 58 deletions

View File

@@ -324,6 +324,50 @@ public class MogoLocation implements Cloneable {
return this;
}
public MogoLocation copy(MogoLocation lastLocation, double longitude, double latitude) {
MogoLocation mogoLocation = new MogoLocation();
mogoLocation.accuracy = lastLocation.accuracy;
mogoLocation.adCode = lastLocation.adCode;
mogoLocation.address = lastLocation.address;
mogoLocation.aoiName = lastLocation.aoiName;
mogoLocation.buildingId = lastLocation.buildingId;
mogoLocation.cityCode = lastLocation.cityCode;
mogoLocation.cityName = lastLocation.cityName;
mogoLocation.description = lastLocation.description;
mogoLocation.district = lastLocation.district;
mogoLocation.errorCode = lastLocation.errorCode;
mogoLocation.errorInfo = lastLocation.errorInfo;
mogoLocation.floor = lastLocation.floor;
mogoLocation.gpsAccuracyStatus = lastLocation.gpsAccuracyStatus;
mogoLocation.lastReceiveTime = lastLocation.lastReceiveTime;
mogoLocation.locationDetail = lastLocation.locationDetail;
mogoLocation.locType = lastLocation.locType;
mogoLocation.poiName = lastLocation.poiName;
mogoLocation.provider = lastLocation.provider;
mogoLocation.province = lastLocation.province;
mogoLocation.satellite = lastLocation.satellite;
mogoLocation.street = lastLocation.street;
mogoLocation.streetNum = lastLocation.streetNum;
MessagePad.GnssInfo gnssInfo =
MessagePad.GnssInfo.newBuilder()
.setLongitude(longitude) //经度
.setLatitude(latitude)//纬度
.setAltitude(lastLocation.gnssInfo.getAltitude()) //海拔
.setHeading(lastLocation.gnssInfo.getHeading()) //航向角
.setAcceleration(lastLocation.gnssInfo.getAcceleration()) //加速度
.setYawRate(lastLocation.gnssInfo.getYawRate()) //曲率
.setGnssSpeed(lastLocation.gnssInfo.getGnssSpeed()) //惯导车速 m/s
.setVehicleSpeed(lastLocation.gnssInfo.getVehicleSpeed()) //车辆车速 m/s
.setSatelliteTime(lastLocation.gnssInfo.getSatelliteTime()) //gps时间 单位秒s
.setSystemTime(lastLocation.gnssInfo.getSystemTime()) //系统时间 单位秒s
.build();
mogoLocation.gnssInfo = gnssInfo;
return mogoLocation;
}
public long getLastReceiveTime() {
return lastReceiveTime;
}

View File

@@ -19,7 +19,7 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
private const val TAG = "CallerChassisLocationGCJ20ListenerManager"
@Volatile
private var mGnssInfo: MogoLocation? = null
private var mGnssInfo: MogoLocation = MogoLocation()
/**
* 添加监听并指定回掉频率
@@ -36,8 +36,8 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
setListenerHz(tag, callBackHz)
}
fun getChassisLocationGCJ02(): MogoLocation? {
return mGnssInfo
fun getChassisLocationGCJ02(): MogoLocation {
return mGnssInfo.clone()
}
/**
@@ -47,46 +47,42 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
@Synchronized
fun invokeChassisLocationGCJ02(gnssInfo: MogoLocation?, sourceType: DataSourceType) {
gnssInfo?.let {
// 克隆定位数据,防止原数据被篡改导致位置跳变
mGnssInfo = gnssInfo.clone()
// 转换 WGS84-->GCJ02 坐标
val gcj20Location =
CoordinateTransform.WGS84ToGCJ02(gnssInfo.longitude, gnssInfo.latitude)
mGnssInfo?.let {
mGnssInfo!!.longitude = gcj20Location[0]
mGnssInfo!!.latitude = gcj20Location[1]
// 克隆定位数据,防止原数据被篡改导致位置跳变
mGnssInfo = gnssInfo.copy(gnssInfo, gcj20Location[0], gcj20Location[1])
M_LISTENERS.forEach {
val tag = it.key
// 获取数据监听需要的HZ
val hz = M_LISTENERS_HZ[tag]
if (hz != null && hz > 0) {
val hzTime = (1.0 / hz.toDouble()) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
M_LISTENERS.forEach {
val tag = it.key
// 获取数据监听需要的HZ
val hz = M_LISTENERS_HZ[tag]
if (hz != null && hz > 0) {
val hzTime = (1.0 / hz.toDouble()) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
//Logger.d(TAG, "没设置监听频率使用默认5HZ")
val hzTime = (1.0 / 5) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
//Logger.d(TAG, "没设置监听频率使用默认5HZ")
val hzTime = (1.0 / 5) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
}
}

View File

@@ -17,7 +17,7 @@ object CallerChassisLocationWGS84ListenerManager : CallerBase<IMoGoChassisLocati
private var mGnssInfo: MogoLocation = MogoLocation()
fun getChassisLocationWGS84(): MogoLocation {
return mGnssInfo
return mGnssInfo.clone()
}
/**

View File

@@ -24,7 +24,6 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import com.mogo.commons.debug.DebugConfig;
@@ -34,7 +33,7 @@ import com.mogo.eagle.core.data.map.CenterLine;
import com.mogo.eagle.core.data.map.MapRoadInfo;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager;
import com.mogo.eagle.core.function.call.map.CallerMapDevaListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager;
@@ -212,28 +211,11 @@ public class AMapViewWrapper implements IMogoMapView,
@Override
public void onStopLineInfo(@androidx.annotation.Nullable StopLine stopLine) {
MogoLocation carLoc = CallerChassisLocationGCJ02ListenerManager.INSTANCE.getChassisLocationGCJ02();
MogoLocation carLoc = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84();
if (stopLine != null && stopLine.road_id != null && !stopLine.road_id.isEmpty() && stopLine.points != null && stopLine.points.size() > 0) {
ArrayList<LonLatPoint> points = stopLine.points;
if (carLoc != null) {
/**
* //地图组提供的高德坐标切到WGS84坐标系
* var cal = LonLatPoint(point!!.lon, point!!.lat)
* if(!point!!.provider.equals(MapAutoApi.GPS_FLAG)){
* cal = MapTools.switchLonLatWGS84(cal)
* }
*/
String provider = carLoc.getProvider();
//CallerLogger.INSTANCE.d(M_MAP + TAG, "car_loc: " + carLoc + "");
if (!MapAutoApi.GPS_FLAG.equals(provider)) {
//CallerLogger.INSTANCE.d(M_MAP + TAG, "convert before: car_loc: {lon: " + carLoc.getLongitude() + ", lat: " + carLoc.getLatitude() + "}");
LonLatPoint p = new LonLatPoint(carLoc.getLongitude(), carLoc.getLatitude());
p = MapTools.INSTANCE.switchLonLatWGS84(p);
carLoc.setLongitude(p.longitude);
carLoc.setLatitude(p.latitude);
//CallerLogger.INSTANCE.d(M_MAP + TAG, "convert after: car_loc: {lon: " + carLoc.getLongitude() + ", lat: " + carLoc.getLatitude() + "}");
}
//CallerLogger.INSTANCE.d(M_MAP + TAG, "onStopLineInfo:stop_line" + stopLine + ", car_loc:{lon: " + carLoc.getLatitude() + ", lat: " + carLoc.getLongitude() + "}");
// //CallerLogger.INSTANCE.d(M_MAP + TAG, "onStopLineInfo:stop_line" + stopLine + ", car_loc:{lon: " + carLoc.getLatitude() + ", lat: " + carLoc.getLongitude() + "}");
MapRoadInfo.StopLine stopInfo = convert(stopLine);
LonLatPoint p1 = points.get(0);
LonLatPoint p2 = points.get(points.size() - 1);