室内模拟导航路线,工控机返回数据验证,数据不精确待联调,数据反馈上线时间7月份

This commit is contained in:
liujing
2022-06-27 19:42:56 +08:00
parent 22fc36d14a
commit 26d3e2c31f
4 changed files with 142 additions and 79 deletions

View File

@@ -1,12 +1,7 @@
package com.mogo.eagle.core.function.smp;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAP;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_V2X;
import static com.mogo.module.common.constants.DataTypes.TYPE_MARKER_CLOUD_STOP_LINE_DATA;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.util.AttributeSet;
@@ -18,18 +13,14 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.CoordinateConverter;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
@@ -52,23 +43,21 @@ import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.navi.model.RouteOverlayOptions;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.mogo.cloud.commons.utils.CoordinateUtils;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
import com.mogo.eagle.core.data.map.MogoLatLng;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningListener;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager;
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager;
import com.mogo.eagle.core.function.map.R;
import com.mogo.eagle.core.function.smp.view.ISmallMapDirectionView;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.eagle.core.widget.RoundLayout;
import com.mogo.map.MogoMarkerManager;
import com.mogo.map.marker.IMogoMarkerManager;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import com.mogo.module.common.utils.DrivingDirectionUtils;
import com.zhidao.support.adas.high.AdasManager;
import org.jetbrains.annotations.NotNull;
@@ -76,6 +65,9 @@ import java.util.ArrayList;
import java.util.List;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
/**
* 小地图的方向View
@@ -86,14 +78,16 @@ import mogo.telematics.pad.MessagePad;
*/
public class AMapCustomView
extends RelativeLayout
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener, IMoGoAutopilotPlanningListener {
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener {
public static final String TAG = "SmallMapDirectionView";
private AMapNaviView mAMapNaviView;
protected AMapNavi mAMapNavi;
private AMap mAMap;
protected NaviLatLng mStartLatlng = new NaviLatLng();
protected NaviLatLng mEndLatlng = new NaviLatLng();
//328路线测试数据
protected NaviLatLng mStartLatlng = new NaviLatLng(39.969111, 116.411903);
protected NaviLatLng mEndLatlng = new NaviLatLng(40.037209, 116.314358);
// protected NaviLatLng mStartLatlng = new NaviLatLng(39.969111, 116.411903);
// protected NaviLatLng mEndLatlng = new NaviLatLng(40.037209, 116.314358);
//顺义国展测试数据
// mStartLatlng = new NaviLatLng(40.09383,116.51899);
// mEndLatlng = new NaviLatLng(40.09964,116.54570);
@@ -108,6 +102,7 @@ public class AMapCustomView
private Context mContext;
private float tilt = 40f;
private TextView overLayerView;
private boolean calculate = false;
public AMapCustomView(Context context) {
this(context, null);
@@ -128,8 +123,6 @@ public class AMapCustomView
private void initView(Context context) {
mContext = context;
sList.add(mStartLatlng);
eList.add(mEndLatlng);
//测试代码:路线指定路径328线路
// mWayPointList.add(new NaviLatLng(39.968847, 116.406952));
// mWayPointList.add(new NaviLatLng(39.969058, 116.407346));
@@ -141,6 +134,7 @@ public class AMapCustomView
// mWayPointList.add(new NaviLatLng(40.037239, 116.337172));
// mWayPointList.add(new NaviLatLng(40.035897, 116.329582));
// mWayPointList.add(new NaviLatLng(40.036396, 116.322166));
Log.d(TAG, "initView:" + mWayPointList.toString());
//顺义国展路线
// mWayPointList.add(new NaviLatLng(40.097621,116.526495));
@@ -156,6 +150,8 @@ public class AMapCustomView
mAMapNavi = AMapNavi.getInstance(context);
mAMapNavi.addAMapNaviListener(this);
mAMapNaviView.setAMapNaviViewListener(this);
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
CallerAutopilotPlanningListenerManager.INSTANCE.addListener(TAG, moGoAutopilotPlanningListener);
initAMapView(context);
// 注册定位监听
CallerMapLocationListenerManager.INSTANCE.addListener(TAG, this);
@@ -165,11 +161,113 @@ public class AMapCustomView
});
}
private final IMoGoAutopilotStatusListener mGoAutopilotStatusListener = new IMoGoAutopilotStatusListener() {
@Override
public void onAutopilotIpcConnectStatusChanged(int status, @org.jetbrains.annotations.Nullable String reason) {
}
@Override
public void onAutopilotGuardian(@org.jetbrains.annotations.Nullable MogoReportMsg.MogoReportMessage guardianInfo) {
}
@Override
public void onAutopilotSNRequest() {
}
@Override
public void onAutopilotArriveAtStation(@org.jetbrains.annotations.Nullable MessagePad.ArrivalNotification arrivalNotification) {
}
@Override
public void onAutopilotStatusResponse(@NotNull AutopilotStatusInfo autoPilotStatusInfo) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (autoPilotStatusInfo == null) return;
int state = autoPilotStatusInfo.getState();
//0 不能自动驾驶 1 可以自动驾驶,但是在人工干预 2 自动驾驶中
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
Log.d(TAG, "自动驾驶中= %s" + String.valueOf(state));
if (sList.size() == 0 && eList.size() == 0 && mWayPointList.size() == 0) {
Log.d(TAG, "sendGlobalPathReq");
AdasManager.getInstance().sendGlobalPathReq();
}
} else {
int type = mAMapNavi.getNaviType();
Log.d(TAG, "非自动驾驶状态,导航类型==" + String.valueOf(type));
if (type == NaviType.GPS || type == NaviType.EMULATOR) {
mAMapNavi.stopNavi();
}
}
}
});
}
};
private final IMoGoAutopilotPlanningListener moGoAutopilotPlanningListener = new IMoGoAutopilotPlanningListener() {
@Override
public void onAutopilotTrajectory(@NotNull List<MessagePad.TrajectoryPoint> trajectoryInfos) {
Log.d(TAG, "onAutopilotTrajectory");
}
/**
* 根据全路径获取起始点和经停点进行导航路线绘制
* 自动驾驶启动后获得数据,获取全路径的具体时间要进行路测
* 室内某个bag包自动驾驶启动8s后返回
*/
@Override
public void onAutopilotRotting(@org.jetbrains.annotations.Nullable MessagePad.GlobalPathResp globalPathResp) {
if (calculate == true) {
return;
}
calculate = true;
Log.d(TAG, "onAutopilotRotting");
List list = globalPathResp.getWayPointsList();
int minCount = 2;
if (list.size() >= minCount && sList.size() == 0 && eList.size() == 0 && mWayPointList.size() == 0) {
calculate = true;
MessagePad.Location sLocation = (MessagePad.Location) list.get(0);
MessagePad.Location eLocation = (MessagePad.Location) list.get(list.size() - 1);
mStartLatlng = new NaviLatLng(sLocation.getLatitude(), sLocation.getLongitude());
mEndLatlng = new NaviLatLng(eLocation.getLatitude(), eLocation.getLongitude());
sList.clear();
eList.clear();
sList.add(mStartLatlng);
eList.add(mEndLatlng);
mWayPointList.clear();
for (int i = 1; i < list.size() - minCount; i++) {
MessagePad.Location wayLoc = (MessagePad.Location) list.get(i);
NaviLatLng way = new NaviLatLng(wayLoc.getLatitude(), wayLoc.getLongitude());
mWayPointList.add(way);
}
}
int strategy = 0;
try {
//再次强调最后一个参数为true时代表多路径否则代表单路径
strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
} catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG, "全局路径" + list.size() + ",起点:" + sList.toString() + ",终点:" + eList.toString() + ",经点:" + mWayPointList.toString());
//指定路径绘制导航路线
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
}
};
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
// 注册定位监听
CallerMapLocationListenerManager.INSTANCE.removeListener(TAG);
CallerAutoPilotStatusListenerManager.INSTANCE.removeListener(TAG);
CallerAutopilotPlanningListenerManager.INSTANCE.removeListener(TAG);
}
private void initAMapView(Context context) {
@@ -243,7 +341,7 @@ public class AMapCustomView
@Override
public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) {
Log.d(TAG, "高精定位onLocationChanged" + location.toString());
}
private void removeLocation(Location latLng) {
@@ -349,6 +447,7 @@ public class AMapCustomView
@Override
public void onInitNaviFailure() {
calculate = false;
Log.d(TAG, "onInitNaviFailure");
}
@@ -371,7 +470,7 @@ public class AMapCustomView
@Override
public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
Log.d(TAG, "高德地图经纬度:" + aMapNaviLocation.getCoord().getLongitude() + "," + aMapNaviLocation.getCoord().getLatitude());
// Log.d(TAG, "高德地图经纬度:" + aMapNaviLocation.getCoord().getLongitude() + "," + aMapNaviLocation.getCoord().getLatitude());
}
@@ -595,42 +694,4 @@ public class AMapCustomView
}
@Override
public void onAutopilotTrajectory(@NotNull List<MessagePad.TrajectoryPoint> trajectoryInfos) {
}
/**
* 根据全路径获取起始点和经停点进行导航路线绘制
* 自动驾驶启动后获得数据,获取全路径的具体时间要进行路测
* 室内某个bag包自动驾驶启动8s后返回
*/
@Override
public void onAutopilotRotting(@org.jetbrains.annotations.Nullable MessagePad.GlobalPathResp globalPathResp) {
List list = globalPathResp.getWayPointsList();
int minCount = 2;
if (list.size() >= minCount) {
Location sLocation = (Location) list.get(0);
Location eLocation = (Location) list.get(list.size() - 1);
mStartLatlng = new NaviLatLng(sLocation.getLongitude(), sLocation.getLatitude());
mEndLatlng = new NaviLatLng(eLocation.getLongitude(), eLocation.getLatitude());
sList.add(mStartLatlng);
eList.add(mEndLatlng);
for (int i = 1; i < list.size() - minCount; i++) {
Location wayLoc = (Location) list.get(i);
NaviLatLng way = new NaviLatLng(wayLoc.getLongitude(), wayLoc.getLatitude());
mWayPointList.add(way);
}
}
int strategy = 0;
try {
//再次强调最后一个参数为true时代表多路径否则代表单路径
strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
} catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG, "calculateDriveRoute ADAS全局路径坐标:" + list.size() + "," + sList.toString() + "," + eList.toString() + "," + mWayPointList.toString());
//指定路径绘制导航路线
mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
}
}