| | |
| | | package com.dji.sample.wayline.service.impl; |
| | | |
| | | import com.alibaba.druid.stat.TableStat; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dji.sample.common.error.CommonErrorEnum; |
| | |
| | | import com.dji.sample.control.model.param.TakeoffToPointParam; |
| | | import com.dji.sample.control.service.IControlService; |
| | | import com.dji.sample.control.service.IDrcService; |
| | | import com.dji.sample.geo.entity.GeoJson; |
| | | import com.dji.sample.manage.model.dto.DeviceDTO; |
| | | import com.dji.sample.manage.model.enums.DeviceModeCodeEnum; |
| | | import com.dji.sample.manage.model.enums.DockModeCodeEnum; |
| | |
| | | import com.dji.sample.media.model.MediaFileCountDTO; |
| | | import com.dji.sample.media.model.MediaMethodEnum; |
| | | import com.dji.sample.media.service.IFileService; |
| | | import com.dji.sample.utils.GeoUtils; |
| | | import com.dji.sample.geo.utils.GeoUtils; |
| | | import com.dji.sample.wayline.dao.IWaylineJobMapper; |
| | | import com.dji.sample.wayline.model.dto.*; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.File; |
| | | import java.net.URL; |
| | | import java.sql.SQLException; |
| | | import java.time.*; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult flyByArea(String sn, FlyAreaParam flyAreaParam) { |
| | | public ResponseResult flyByArea(String sn, FlyAreaParam flyAreaParam, String deviceSn) { |
| | | |
| | | List<List<PointPOJO>> areaList = flyAreaParam.getAreaList(); |
| | | //获取所有中心点 |
| | | // List<PointPOJO> targetList = GeoUtils.caculatePointList(flyAreaParam); |
| | | PointPOJO dockPoint = flyAreaParam.getDockPoint(); |
| | | Double radius = flyAreaParam.getRadius(); |
| | | GeoJson geoJson = GeoUtils.readJsonFile(flyAreaParam.getJsonPath()); |
| | | List<PointPOJO> targetList = GeoUtils.caculatePointList(geoJson, dockPoint, flyAreaParam.getRadius()); |
| | | |
| | | List<PointPOJO> centerPointList = new ArrayList<>(); |
| | | //一键起飞 |
| | | TakeoffToPointParam takeoffToPointParam = buildTakeoffToPointParam(dockPoint); |
| | | |
| | | //根据区域获取中心点 |
| | | areaList.forEach(area -> { |
| | | PointPOJO centerPoint = GeoUtils.getCenterPoint(area); |
| | | centerPointList.add(centerPoint); |
| | | }); |
| | | ResponseResult takeoffToPointRes = controlService.takeoffToPoint(sn, takeoffToPointParam); |
| | | |
| | | //巡逻目标集合 |
| | | List<PointPOJO> targetList = new ArrayList<>(); |
| | | //获取所有中心点之后, |
| | | centerPointList.forEach(centerPoint -> { |
| | | //判断各个中心点和机场点的距离 |
| | | double distance = GeoUtils.distance(dockPoint.getLon(), dockPoint.getLat(), centerPoint.getLon(), centerPoint.getLat()); |
| | | //设置飞向第一个点 |
| | | while (takeoffToPointRes.getCode() == ResponseResult.CODE_SUCCESS) { |
| | | //获取无人机状态 |
| | | DeviceModeCodeEnum deviceMode = deviceService.getDeviceMode(deviceSn); |
| | | |
| | | //当距离小于半径时,添加到目标集合中 |
| | | if (distance <= radius) { |
| | | centerPoint.setDistance(distance); |
| | | targetList.add(centerPoint); |
| | | //当无人机状态为手动飞行 |
| | | if (deviceMode == DeviceModeCodeEnum.MANUAL) { |
| | | //飞向目标点 |
| | | FlyToPointParam flyToPointParam = new FlyToPointParam(); |
| | | flyToPointParam.setMaxSpeed(14); |
| | | List<PointDTO> pointDTOS = new ArrayList<>(); |
| | | |
| | | PointDTO pointDTO = new PointDTO(); |
| | | pointDTO.setHeight(150.0); |
| | | pointDTO.setLongitude(targetList.get(0).getLon()); |
| | | pointDTO.setLatitude(targetList.get(0).getLat()); |
| | | pointDTOS.add(pointDTO); |
| | | flyToPointParam.setPoints(pointDTOS); |
| | | |
| | | |
| | | ResponseResult flyToRes = controlService.flyToPoint(sn, flyToPointParam); |
| | | |
| | | if (flyToRes.getCode() == ResponseResult.CODE_SUCCESS) { |
| | | //第一个点指令飞行成功后,把数组存到redis中 |
| | | /** |
| | | * { |
| | | * targetList:[], |
| | | * curIndex: |
| | | * } |
| | | */ |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("targetList",targetList); |
| | | jsonObject.put("curIndex",0); |
| | | |
| | | |
| | | RedisOpsUtils.set("tuban:"+sn,jsonObject); |
| | | } |
| | | }); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //按距离从近到远排序 |
| | | targetList.sort(Comparator.comparing(PointPOJO::getDistance)); |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | //后续为无人机操作逻辑 |
| | | //先飞到空中 |
| | | public TakeoffToPointParam buildTakeoffToPointParam(PointPOJO dockPoint) { |
| | | TakeoffToPointParam takeoffToPointParam = new TakeoffToPointParam(); |
| | | |
| | | takeoffToPointParam.setTargetLatitude(dockPoint.getLat()); |
| | |
| | | takeoffToPointParam.setMaxSpeed(10.0); |
| | | takeoffToPointParam.setExitWaylineWhenRcLost(WaylineRcLostActionEnum.EXECUTE_RC_LOST_ACTION); |
| | | |
| | | return ResponseResult.success(); |
| | | // //起飞 |
| | | // ResponseResult responseResult = controlService.takeoffToPoint(sn, takeoffToPointParam); |
| | | // |
| | | // if (responseResult.getCode() != ResponseResult.CODE_SUCCESS) { |
| | | // return responseResult; |
| | | // } |
| | | // //向目标点飞行 |
| | | // |
| | | // FlyToPointParam flyToPointParam = new FlyToPointParam(); |
| | | // flyToPointParam.setMaxSpeed(14); |
| | | // List<PointDTO> pointDTOS = new ArrayList<>(); |
| | | // targetList.forEach(pointPOJO -> { |
| | | // PointDTO pointDTO = new PointDTO(); |
| | | // pointDTO.setHeight(150.0); |
| | | // pointDTO.setLongitude(pointPOJO.getLon()); |
| | | // pointDTO.setLatitude(pointPOJO.getLat()); |
| | | // |
| | | // pointDTOS.add(pointDTO); |
| | | // }); |
| | | // flyToPointParam.setPoints(pointDTOS); |
| | | // ResponseResult responseResult1 = controlService.flyToPoint(sn, flyToPointParam); |
| | | // |
| | | // if (responseResult1.getCode() != ResponseResult.CODE_SUCCESS) { |
| | | // return responseResult1; |
| | | // } |
| | | // |
| | | // //返航 |
| | | // //return_home |
| | | // |
| | | // |
| | | // return ResponseResult.success(); |
| | | return takeoffToPointParam; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |