From 0f4c9405245412d0acb02af1eb4b8b371fde4ef1 Mon Sep 17 00:00:00 2001 From: liujing Date: Fri, 2 Apr 2021 17:19:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=8C=BA=E5=9F=9F=E7=BB=98?= =?UTF-8?q?=E5=88=B6(=E8=87=AA=E8=BD=A6=E5=88=B0=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E7=BA=BF=E8=B7=9D=E7=A6=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/entity/V2XWarningEntity.java | 46 +++--------- .../java/com/mogo/module/v2x/V2XConst.java | 4 + .../warning/V2XFrontWarningScenario.java | 16 +++- .../scene/warning/V2XWarningMarker.java | 74 +++++++++++-------- .../scene/warning/V2XWarningWindow.java | 6 +- .../res/raw/scenario_warning_event_data.json | 6 +- 6 files changed, 78 insertions(+), 74 deletions(-) diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java index df3e48319a..9f294af585 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XWarningEntity.java @@ -58,40 +58,11 @@ public class V2XWarningEntity implements Serializable { //自组字段 //tts播报 private String tts; - //打点位置 - private MarkerLocation location; + //自车位置 + private MogoLatLng carLocation; - public void setLocation(MarkerLocation location) { - this.location = location; - } - - public MarkerLocation getLocation() { - if (location == null) { - MarkerLocation location = new MarkerLocation(); - location.setLat(getLat()); - location.setLon(getLon()); - setLocation(location); - } - return location; - } - - - public void setTipContent(int type) { - switch (type) { - case 0: - this.warningContent = "行人碰撞预警"; - break; - case 1: - case 3: - case 4: - this.warningContent = "前车碰撞预警"; - break; - case 2: - this.warningContent = "摩托车碰撞预警"; - break; - default: - break; - } + public MogoLatLng getCarLocation() { + return carLocation; } public void setTts(int type) { @@ -167,6 +138,10 @@ public class V2XWarningEntity implements Serializable { this.stopLines = stopLines; } + public void setCarLocation(MogoLatLng carLocation) { + this.carLocation = carLocation; + } + public int getType() { return type; } @@ -212,9 +187,6 @@ public class V2XWarningEntity implements Serializable { } public String getWarningContent() { - if (this.warningContent == null) { - setTipContent(type); - } return warningContent; } @@ -270,7 +242,7 @@ public class V2XWarningEntity implements Serializable { ", systemTime=" + systemTime + ", satelliteTime=" + satelliteTime + ", tts='" + tts + '\'' + - ", location=" + location + + ", carLocation=" + carLocation + '}'; } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XConst.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XConst.java index 4d03e6cf94..1430bf8fa2 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XConst.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/V2XConst.java @@ -145,6 +145,10 @@ public class V2XConst { * */ public static final String V2X_FRONT_WARNING_MARKER = "V2X_FRONT_WARNING_MARKER"; + /* + *V2X 车路云前方预警 + * */ + public static final String V2X_FRONT_STOP_LINE = "V2X_FRONT_STOP_LINE"; /** * V2X预警日志tag */ diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XFrontWarningScenario.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XFrontWarningScenario.java index 4b58b04e90..2355cc0096 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XFrontWarningScenario.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XFrontWarningScenario.java @@ -2,6 +2,7 @@ package com.mogo.module.v2x.scenario.scene.warning; import android.content.Context; import android.content.Intent; +import android.location.Location; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -9,7 +10,9 @@ import android.view.ViewGroup; import androidx.annotation.Nullable; import com.alibaba.android.arouter.facade.annotation.Route; +import com.mogo.map.MogoLatLng; import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.navi.IMogoCarLocationChangedListener2; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.entity.V2XMessageEntity; import com.mogo.module.common.entity.V2XPoiTypeEnum; @@ -39,7 +42,7 @@ import java.util.List; * @description 车路云—场景预警-V1.0 前车/行人/摩托车/盲区碰撞预警 * @since: 2021/3/24 */ -public class V2XFrontWarningScenario extends AbsV2XScenario implements IMogoTopViewStatusListener { +public class V2XFrontWarningScenario extends AbsV2XScenario implements IMogoTopViewStatusListener , IMogoCarLocationChangedListener2 { private int direction; private V2XWarningEntity mMarkerEntity; @@ -130,4 +133,15 @@ public class V2XFrontWarningScenario extends AbsV2XScenario implements IMogoTopV public void beforeViewRemoveAnim(View view) { } + + @Override + public void onCarLocationChanged2(Location latLng) { + + } + + @Override + public void onCarLocationChanged(MogoLatLng latLng) { + mMarkerEntity.setCarLocation(latLng); + drawPOI(); + } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java index 18326771bc..90eb63254b 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java @@ -24,14 +24,14 @@ import java.util.List; /** * @author liujing - * @description 描述 + * @description 前方预警marker打点 绘制安全线和预警线 * @since: 2021/3/30 */ public class V2XWarningMarker implements IV2XMarker { private V2XWarningEntity mMarkerEntity; private MarkerShowEntity markerShowEntity = new MarkerShowEntity(); private Context mContext = V2XServiceManager.getContext(); - List fillPoints = new ArrayList();//停止线经纬度合集 + private List fillPoints = new ArrayList();//停止线经纬度合集 @Override public void drawPOI(Object entity) { @@ -42,14 +42,17 @@ public class V2XWarningMarker implements IV2XMarker { location.setLon(mMarkerEntity.getLon()); markerShowEntity.setMarkerLocation(location); -// drawLineAndSmooth(); - pointsBetween(); - //绘制停止线 - drawStopLines(fillPoints); - WorkThreadHandler.getInstance().postDelayed(() -> { - clearPOI(); - }, 6_000); - //绘制安全距离 + + if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) { + pointsBetween(); + //绘制停止线 + drawStopLines(fillPoints); + drawSafeLine(); + WorkThreadHandler.getInstance().postDelayed(() -> { + V2XServiceManager.getMarkerManager().removeMarkers(V2XConst.V2X_FRONT_STOP_LINE); + V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); + }, 6_000); + } } catch (Exception e) { @@ -57,21 +60,27 @@ public class V2XWarningMarker implements IV2XMarker { } - private void drawLineAndSmooth() { - if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) { - clearPOI(); - WorkThreadHandler.getInstance().postDelayed(() -> { - IMogoMarker marker = drawMarkerAndReturn(markerShowEntity); - //如果有预警碰撞点,识别物与预警碰撞点之间连线,并执行平移动画 - if (mMarkerEntity.getCollisionLat() > 0 && mMarkerEntity.getCollisionLon() != 0) { - drawLine(); - smooth(marker); + //绘制安全距离 + private void drawSafeLine() { + clearPOI(); + WorkThreadHandler.getInstance().postDelayed(() -> { + //自车位置 + MogoLatLng car = mMarkerEntity.getCarLocation(); + if (car == null) { + double lon = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLon(); + double lat = MogoApisHandler.getInstance().getApis().getAdasControllerApi().getLastLat(); + car = new MogoLatLng(lat, lon); + car = new MogoLatLng(39.977709,116.417703); + } + if (car != null) { + //根据到停止线的距离和方向角获取经纬度 + MogoLatLng + stopLineLo = LocationUtils.getNewLocation(car, mMarkerEntity.getStopLineDistance(), mMarkerEntity.getAngle()); + if (mMarkerEntity.getCollisionLat() > 0 && mMarkerEntity.getCollisionLon() > 0) { + drawLine(car, stopLineLo); } - }, 0); - - } else { - - } + } + }, 0); } //补点后的停止线经纬度合集 @@ -101,15 +110,17 @@ public class V2XWarningMarker implements IV2XMarker { } + //绘制停止线-通过打点的方式实现 private void drawStopLines(List points) { clearPOI(); + V2XServiceManager.getMarkerManager().removeMarkers(V2XConst.V2X_FRONT_STOP_LINE); for (int i = 0; i < points.size(); i++) { MogoLatLng latLng = (MogoLatLng) points.get(i); - drawMarkerWithLocation(latLng); + drawMarkerWithLocation(latLng, V2XConst.V2X_FRONT_STOP_LINE); } } - private void drawMarkerWithLocation(MogoLatLng latLng) { + private void drawMarkerWithLocation(MogoLatLng latLng, String tag) { MogoMarkerOptions options = new MogoMarkerOptions() .object(markerShowEntity) .latitude(latLng.lat) @@ -118,7 +129,7 @@ public class V2XWarningMarker implements IV2XMarker { options.icon3DRes(com.mogo.module.service.R.raw.people); options.anchor(0.5f, 0.5f); options.anchorColor("#FF4040"); - IMogoMarker marker = V2XServiceManager.getMarkerManager().addMarker(V2XConst.V2X_FRONT_WARNING_MARKER, options); + IMogoMarker marker = V2XServiceManager.getMarkerManager().addMarker(tag, options); iMarkerView.setMarker(marker); marker.setToTop(); } @@ -139,12 +150,10 @@ public class V2XWarningMarker implements IV2XMarker { } //绘制线 - public void drawLine() { + public void drawLine(MogoLatLng s, MogoLatLng e) { DrawLineInfo drawLineInfo = new DrawLineInfo(); - MogoLatLng slatLng = new MogoLatLng(mMarkerEntity.getLat(), mMarkerEntity.getLon()); - MogoLatLng endLatLng = new MogoLatLng(mMarkerEntity.getCollisionLat(), mMarkerEntity.getCollisionLon()); - drawLineInfo.setStartLocation(slatLng); - drawLineInfo.setEndLocation(endLatLng); + drawLineInfo.setStartLocation(s); + drawLineInfo.setEndLocation(e); V2XServiceManager.getMoGoWarnPolylineManager().drawWarnPolyline(mContext, drawLineInfo); } @@ -170,4 +179,5 @@ public class V2XWarningMarker implements IV2XMarker { public void clearLine() { V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); } + } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningWindow.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningWindow.java index 3983091eaf..14e2ee8528 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningWindow.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningWindow.java @@ -1,6 +1,7 @@ package com.mogo.module.v2x.scenario.scene.warning; import android.content.Context; +import android.location.Location; import android.os.Handler; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -10,6 +11,10 @@ import android.widget.TextView; import com.mogo.commons.voice.AIAssist; import com.mogo.commons.voice.VoicePreemptType; +import com.mogo.map.MogoLatLng; +import com.mogo.map.navi.IMogoCarLocationChangedListener; +import com.mogo.map.navi.IMogoCarLocationChangedListener2; +import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.entity.V2XWarningEntity; import com.mogo.module.v2x.R; import com.mogo.module.v2x.V2XServiceManager; @@ -120,6 +125,5 @@ public class V2XWarningWindow extends V2XBasWindow implements IV2XWindow { V2XServiceManager .getMogoTopViewManager() .removeView(this); - } } diff --git a/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json b/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json index ded0e8a92c..91f29e6187 100644 --- a/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json +++ b/modules/mogo-module-v2x/src/main/res/raw/scenario_warning_event_data.json @@ -5,7 +5,7 @@ "distance": 2, "collisionLat": 39.977094, "collisionLon": 116.417634, - "stopLines":[ + "stopLines": [ { "lat": 39.976858, "lon": 116.417651 @@ -16,11 +16,11 @@ } ], "from": 1, - "angle": 120, + "angle": 0, "direction": 10014, "speed": 11.108121, "targetColor": "#FF4040", - "stopLineDistance": 20, + "stopLineDistance": 30, "stopLineLat": 39.977094, "stopLineLon": 116.417634, "warningContent": "小心行人",