Explorar el Código

Merge remote-tracking branch 'origin/master'

root hace 2 años
padre
commit
9e376ecff2

+ 45 - 0
api-common/src/main/java/api/common/pojo/po/scene/VehicleTypePO.java

@@ -0,0 +1,45 @@
+package api.common.pojo.po.scene;
+
+import lombok.*;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 三维自车指标替换
+ */
+@EqualsAndHashCode()
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class VehicleTypePO implements Serializable {
+    private String vehicleCategory;//车辆类型
+    private String model3d;//车辆颜色渲染地址
+    private BigDecimal centerX;
+    private double centerY=0;
+    private BigDecimal centerZ;
+    private BigDecimal dimensionsWidth;
+    private BigDecimal dimensionsLength;
+    private BigDecimal dimensionsHeight;
+
+    private BigDecimal performanceMaxSpeed;
+    private BigDecimal performanceMaxDeceleration;
+    private String performanceMaxAcceleration="2.5";
+
+    private BigDecimal FrontAxleMaxSteering;
+    private BigDecimal FrontAxleWheelDiameter;
+    private BigDecimal FrontAxleTrackWidth;
+    private BigDecimal FrontAxlePositionX;
+    private BigDecimal FrontAxlePositionZ;
+
+    private String RearAxleMaxSteering="0";
+    private BigDecimal RearAxleWheelDiameter;
+    private BigDecimal RearAxleTrackWidth;
+    private BigDecimal RearAxlePositionX;
+    private BigDecimal RearAxlePositionZ;
+
+
+
+
+}

+ 23 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/ConfigMapper.java

@@ -0,0 +1,23 @@
+package com.css.simulation.resource.scheduler.mapper;
+
+
+import api.common.pojo.param.model.ConfigPageParam;
+import api.common.pojo.po.model.ConfigPO;
+import api.common.pojo.po.model.ConfigSensorPO;
+import api.common.pojo.vo.model.ConfigSensorVO;
+import api.common.pojo.vo.model.ConfigVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface ConfigMapper {
+    @Select("select vehicle_id vehicleId\n" +
+            "from model_config\n" +
+            "where id = #{id}")
+    String getVehicleId(String id);
+}

+ 19 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/SimulationAutomaticProjectMapper.java

@@ -0,0 +1,19 @@
+package com.css.simulation.resource.scheduler.mapper;
+
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+@Mapper
+@Repository
+public interface SimulationAutomaticProjectMapper {
+     @Select("select vehicle\n" +
+             "from simulation_manual_project\n" +
+             "where id = #{id}")
+     String vehicleBySdId(String id);
+     @Select("select vehicle\n" +
+             "from simulation_automatic_project\n" +
+             "where id = #{id}")
+     String vehicleByZdId(String id);
+}

+ 31 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/VehicleMapper.java

@@ -1,5 +1,6 @@
 package com.css.simulation.resource.scheduler.mapper;
 
+import api.common.pojo.vo.model.VehicleVO;
 import com.css.simulation.resource.scheduler.pojo.po.VehiclePO;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
@@ -53,4 +54,34 @@ public interface VehicleMapper {
             "    where mc.id = #{vehicleConfigId}\n" +
             ")")
     VehiclePO selectByVehicleConfigId(@Param("vehicleConfigId") String vehicleConfigId);
+
+    @Select("select id,\n" +
+            "       vehicle_code,\n" +
+            "       vehicle_name,\n" +
+            "       description,\n" +
+            "       vehicle_type,\n" +
+            "       model_label,\n" +
+            "       vehicle_front_view,\n" +
+            "       vehicle_top_view,\n" +
+            "       max_speed,\n" +
+            "       engine_power,\n" +
+            "       max_deceleration,\n" +
+            "       max_steering_angle,\n" +
+            "       mass,\n" +
+            "       front_surface_effective,\n" +
+            "       air_drag_coefficient,\n" +
+            "       rolling_resistance_coefficient,\n" +
+            "       wheel_diameter,\n" +
+            "       wheel_drive\n" +
+            "       overall_efficiency\n" +
+            "       front_distance\n" +
+            "       rear_distance\n" +
+            "       left_distance\n" +
+            "       right_distance\n" +
+            "       height_distance\n" +
+            "       wheelbase\n" +
+            "       share\n" +
+            "from model_vehicle\n" +
+            "where  id = #{vehicleId}\n")
+    VehicleVO getVehicleInfo(@Param("vehicleId") String vehicleId);
 }

+ 277 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/GenerateVideoService.java

@@ -0,0 +1,277 @@
+package com.css.simulation.resource.scheduler.service;
+
+import api.common.pojo.param.model.VehicleParam;
+import api.common.pojo.po.scene.VehicleTypePO;
+import api.common.pojo.vo.model.VehicleVO;
+import api.common.util.LinuxUtil;
+import com.css.simulation.resource.scheduler.mapper.ConfigMapper;
+import com.css.simulation.resource.scheduler.mapper.SimulationAutomaticProjectMapper;
+import com.css.simulation.resource.scheduler.mapper.VehicleMapper;
+import lombok.SneakyThrows;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+
+public class GenerateVideoService {
+    @Autowired
+    VehicleMapper vehicleMapper;
+    @Autowired
+    ConfigMapper configMapper;
+    @Resource
+    SimulationAutomaticProjectMapper simulationAutomaticProjectMapper;
+    @SneakyThrows
+    //map必传 xoscPath 文件夹路径  ;osgbPath,xodrPath 全路径;projectType 项目类型 1.手动;2.自动 ;id项目id;
+    public void GenerateVideo( Map<String ,String> map) throws IOException {
+        String xoscPath=map.get("xoscPath");
+        LinuxUtil.execute("D:\\Users\\anaconda3\\envs\\flaskProject\\python.exe C:/Users/CSS/Desktop/simulation/gqSw/simulation_my.py "+xoscPath);
+        //xosc全路径
+        xoscPath= xoscPath+"\\xosc\\simulation_my0.xosc";
+        map.put("xoscPath",xoscPath);
+         //调用修改xosc
+      String xoscNewPath=  changeXos(map);//返回最新的xosc文件全路径
+
+    }
+
+    //获取三维自车对象
+    @SneakyThrows
+    public VehicleTypePO vehicleById(Map<String,String> map) {
+        VehicleTypePO po=new VehicleTypePO();
+        String projectType=map.get("projectType");
+        String id=map.get("id");
+        //项目类型 1.手动;2.自动
+        String vehicle="";
+        if(projectType.equals("1"))
+        {
+            vehicle = simulationAutomaticProjectMapper.vehicleBySdId(id);
+        }else if (projectType.equals("2")){
+            vehicle = simulationAutomaticProjectMapper.vehicleByZdId(id);
+        }
+        String vehicleId=configMapper.getVehicleId(vehicle);
+
+        VehicleVO vehicleInfo = vehicleMapper.getVehicleInfo(vehicleId);
+
+        //自车模型
+        String car= vehicleInfo.getVehicleTypeStr().substring(0,vehicleInfo.getVehicleTypeStr().indexOf(","));
+        car=car.substring(0,1).toLowerCase()+car.substring(1);
+        if(car.indexOf("truck")>-1){
+            po.setVehicleCategory("truck");
+        }else if(car.indexOf("trailer")>-1){
+            po.setVehicleCategory("trailer");
+        }else if(car.indexOf("van")>-1){
+            po.setVehicleCategory("van");
+        }else if(car.indexOf("semitrailer")>-1){
+            po.setVehicleCategory("semitrailer");
+        }else if(car.indexOf("bus")>-1){
+            po.setVehicleCategory("bus");
+        }else if(car.indexOf("motorbike")>-1){
+            po.setVehicleCategory("motorbike");
+        }else if(car.indexOf("bicycle")>-1){
+            po.setVehicleCategory("bicycle");
+        }else if(car.indexOf("bicycle")>-1){
+            po.setVehicleCategory("bicycle");
+        }else if(car.indexOf("train")>-1){
+            po.setVehicleCategory("train");
+        }else if(car.indexOf("tram")>-1){
+            po.setVehicleCategory("tram");
+        }else{
+            po.setVehicleCategory("car");
+        }
+
+        //车前距
+        BigDecimal frontDistance=vehicleInfo.getFrontDistance();
+        //车后距
+        BigDecimal mo2=new BigDecimal("2");
+        BigDecimal rearDistance=vehicleInfo.getRearDistance();
+        if(frontDistance.compareTo(rearDistance)>0){
+            BigDecimal  CenterX= (frontDistance.add(rearDistance)).divide(mo2).subtract(rearDistance);
+            po.setCenterX(CenterX);
+        }else{
+            BigDecimal  CenterX= (frontDistance.add(rearDistance)).divide(mo2).subtract(frontDistance);
+            po.setCenterX(CenterX);
+        }
+        //车高
+        BigDecimal mo3=new BigDecimal("3");
+        po.setCenterZ(vehicleInfo.getHeightDistance().divide(mo3));
+        //车左距  车右距
+        BigDecimal LeftDistance=vehicleInfo.getLeftDistance();
+        BigDecimal RightDistance= vehicleInfo.getRightDistance();
+        po.setDimensionsWidth(LeftDistance.add(RightDistance));
+        po.setDimensionsHeight(vehicleInfo.getHeightDistance());
+        po.setDimensionsLength(frontDistance.add(rearDistance));
+
+        po.setPerformanceMaxSpeed(vehicleInfo.getMaxSpeed());
+        po.setPerformanceMaxDeceleration(vehicleInfo.getMaxDeceleration());
+        BigDecimal moπ=new BigDecimal("3.141516");
+        BigDecimal mo180=new BigDecimal("180");
+        po.setFrontAxleMaxSteering(vehicleInfo.getMaxSteeringAngle().multiply(moπ).divide(mo180));
+        po.setFrontAxleWheelDiameter(vehicleInfo.getWheelDiameter());
+        BigDecimal mo4=new BigDecimal("4");
+        BigDecimal mo5=new BigDecimal("5");
+        po.setFrontAxleTrackWidth(LeftDistance.add(RightDistance).multiply(mo4).divide(mo5));
+        po.setFrontAxlePositionX(po.getCenterX());
+        po.setFrontAxlePositionZ(po.getCenterZ());
+
+        po.setRearAxleWheelDiameter(vehicleInfo.getWheelDiameter());
+        po.setRearAxleTrackWidth(po.getFrontAxleTrackWidth());
+        po.setRearAxlePositionX(po.getFrontAxlePositionX());
+        po.setRearAxlePositionZ(po.getFrontAxlePositionZ());
+        return po;
+
+    }
+
+
+    //转换xosc自车形态
+    @SneakyThrows
+    public String changeXos(Map<String, String> map){
+
+        String xoscPath=map.get("xoscPath");
+        String osgbPath=map.get("osgbPath");
+        String xodrPath=map.get("xodrPath");
+        String xoscNewPath= xoscPath.substring(0,xoscPath.length()-5)+"5.xosc";//
+        //获取三维自车对象
+        VehicleTypePO po =vehicleById(map);
+
+        //1 创建Reader对象
+        SAXReader reader = new SAXReader();
+        //2 加载xml
+        // Document document = reader.read(new File("D:\\simulation_my0.xosc"));
+        Document document = reader.read(new File(xoscPath));
+        //3 获取根节点
+        Element root = document.getRootElement();
+        Iterator iterator0 = root.elementIterator();
+        while (iterator0.hasNext()) {   // 第一层遍历
+            Element node1 = (Element) iterator0.next();
+            if ("Entities".equals(node1.getName())) { // 找到第一层节点后进入第二层遍历
+                Iterator iterator1 = node1.elementIterator();
+                while (iterator1.hasNext()) {
+                    Element node2 = (Element) iterator1.next();
+                    // 添加节点
+                    if ("ScenarioObject".equals(node2.getName())) {
+                        String scenarioObjectName = node2.attribute("name").getValue();
+                        if (scenarioObjectName.equals("Ego")) {
+                            Iterator<Element> iterator2 = node2.elementIterator();
+                            while (iterator2.hasNext()) {
+                                Element node3 = iterator2.next();
+                                if ("Vehicle".equals(node3.getName())) {
+                                    Attribute name = node3.attribute("name");
+                                    name.setText("Audi_A3_2009_red");
+                                    Attribute vehicleCategory = node3.attribute("vehicleCategory");
+                                    vehicleCategory.setText(po.getVehicleCategory());
+                                    Iterator<Element> iterator4 = node3.elementIterator();
+                                    while (iterator4.hasNext()) {
+                                        Element node4 = iterator4.next();
+                                        if ("Performance".equals(node4.getName())) {
+                                            Attribute maxSpeed = node4.attribute("maxSpeed");
+                                            maxSpeed.setText(po.getPerformanceMaxSpeed()+"");
+                                            Attribute maxDeceleration = node4.attribute("maxDeceleration");
+                                            maxDeceleration.setText(po.getPerformanceMaxDeceleration()+"");
+                                            Attribute maxAcceleration = node4.attribute("maxAcceleration");
+                                            maxAcceleration.setText(po.getPerformanceMaxAcceleration());
+                                        }else if("BoundingBox".equals(node4.getName())){
+                                            Iterator<Element> iterator5 = node4.elementIterator();
+                                            while (iterator5.hasNext()) {
+                                                Element node5 = iterator5.next();
+                                                if ("Center".equals(node5.getName())) {
+                                                    Attribute x = node5.attribute("x");
+                                                    x.setText(po.getCenterX() + "");
+                                                    Attribute y = node5.attribute("y");
+                                                    y.setText(po.getCenterY() + "");
+                                                    Attribute z = node5.attribute("z");
+                                                    z.setText(po.getCenterZ() + "");
+                                                }
+                                                if ("Dimensions".equals(node5.getName())) {
+                                                    Attribute width = node5.attribute("width");
+                                                    width.setText(po.getDimensionsWidth() + "");
+                                                    Attribute length = node5.attribute("length");
+                                                    length.setText(po.getDimensionsHeight() + "");
+                                                    Attribute height = node5.attribute("height");
+                                                    height.setText(po.getDimensionsHeight() + "");
+                                                }
+                                            }
+                                        }else if("Axles".equals(node4.getName())){
+                                            Iterator<Element> iterator5 = node4.elementIterator();
+                                            while (iterator5.hasNext()) {
+                                                Element node5 = iterator5.next();
+                                                if ("FrontAxle".equals(node5.getName())) {
+                                                    Attribute maxSteering = node5.attribute("maxSteering");
+                                                    maxSteering.setText(po.getFrontAxleMaxSteering() + "");
+                                                    Attribute wheelDiameter = node5.attribute("wheelDiameter");
+                                                    wheelDiameter.setText(po.getFrontAxleWheelDiameter() + "");
+                                                    Attribute trackWidth = node5.attribute("trackWidth");
+                                                    trackWidth.setText(po.getFrontAxleTrackWidth() + "");
+                                                    Attribute positionX = node5.attribute("positionX");
+                                                    positionX.setText(po.getFrontAxlePositionX() + "");
+                                                    Attribute positionZ = node5.attribute("positionZ");
+                                                    positionZ.setText(po.getFrontAxlePositionZ() + "");
+                                                }
+                                                if ("RearAxle".equals(node5.getName())) {
+                                                    Attribute maxSteering = node5.attribute("maxSteering");
+                                                    maxSteering.setText(po.getRearAxleMaxSteering());
+                                                    Attribute wheelDiameter = node5.attribute("wheelDiameter");
+                                                    wheelDiameter.setText(po.getRearAxleWheelDiameter() + "");
+                                                    Attribute trackWidth = node5.attribute("trackWidth");
+                                                    trackWidth.setText(po.getRearAxleTrackWidth() + "");
+                                                    Attribute positionX = node5.attribute("positionX");
+                                                    positionX.setText(po.getRearAxlePositionX() + "");
+                                                    Attribute positionZ = node5.attribute("positionZ");
+                                                    positionZ.setText(po.getRearAxlePositionZ() + "");
+                                                }
+                                            }
+                                        }
+
+                                    }
+                                }
+
+                            }
+
+                            // 保存文件
+                            // Writer osWrite = new OutputStreamWriter(Files.newOutputStream(Paths.get("D:\\simulation_my0000.xosc")));// 创建输出流
+
+                        }
+                    }
+                }
+            }
+
+            if ("RoadNetwork".equals(node1.getName())) { // 找到第一层节点后进入第二层遍历
+                Iterator iterator1 = node1.elementIterator();
+                while (iterator1.hasNext()) {
+                    Element node2 = (Element) iterator1.next();
+                    // 添加节点
+                    if ("LogicFile".equals(node2.getName())) {
+                        Attribute name = node2.attribute("filepath");
+                        name.setText(xodrPath);
+                    }
+                    if ("SceneGraphFile".equals(node2.getName())) {
+                        Attribute name = node2.attribute("filepath");
+                        name.setText(osgbPath);
+                    }
+                }
+            }
+
+            Writer osWrite = new OutputStreamWriter(Files.newOutputStream(Paths.get(xoscNewPath)));
+            OutputFormat format = OutputFormat.createPrettyPrint(); // 获取输出的指定格式
+            format.setEncoding("UTF-8");// 设置编码 ,确保解析的xml为UTF-8格式
+            XMLWriter writer = new XMLWriter(osWrite, format);// XMLWriter
+            writer.write(document);// 把document写入xmlFile指定的文件(可以为被解析的文件或者新创建的文件)
+            writer.flush();
+            writer.close();
+        }
+        return xoscNewPath;
+    }
+}