|
|
@ -683,6 +683,7 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
|
|
|
|
//todo 新增代码 目标位置信息
|
|
|
|
/** |
|
|
|
* case4 : 点击的目标数据 (只有点击雷达图上的目标时才发送) |
|
|
|
* address : 172.20.0.77 (ZMQ发布地址) |
|
|
|
* port : 5151 |
|
|
|
* topic : NyGuideCamPos |
|
|
@ -812,8 +813,7 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
List<MsCameraSetting> cameraSettings = null;//todo : 查询所有的球机 暂时查询本项目数据库 实际可能查询别的项目数据库
|
|
|
|
LambdaQueryWrapper<MsCameraSetting> cameraSettingLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType, 2);//只查询球机的信息 type:2 球机 type:1 枪击 type:10 故障
|
|
|
|
//todo : 用于调整球机初始角
|
|
|
|
//cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType,5);//只查询球机的信息
|
|
|
|
//cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType,5);//只查询球机的信息 用于调整球机初始角
|
|
|
|
|
|
|
|
cameraSettings = msCameraSettingService.list(cameraSettingLambdaQueryWrapper); |
|
|
|
if (cameraSettings == null || cameraSettings.isEmpty()) { |
|
|
@ -822,30 +822,6 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
log.info("case4 : 遍历相机列表 寻找最近的点的球机去跟踪"); |
|
|
|
log.info("case4 : " + JSON.toJSONString(cameraSettings)); |
|
|
|
|
|
|
|
//todo : 未优化算法(减少相机数量)
|
|
|
|
/* double minDis=GEOUtils.GetDistance(cameraSettings.get(0).getLongitude().doubleValue(),cameraSettings.get(0).getLatitude().doubleValue(), targetLonLat.getLon(), targetLonLat.getLat()); |
|
|
|
int index=0; |
|
|
|
for (int i = 1; i < cameraSettings.size(); i++) { |
|
|
|
MsCameraSetting cameraSetting = cameraSettings.get(i); |
|
|
|
//todo : 1.计算距离 选最近球机 进行跟踪
|
|
|
|
BigDecimal cameraHeight = cameraSetting.getHeight(); |
|
|
|
BigDecimal labelHeight = new BigDecimal(h); |
|
|
|
double heightDiff = cameraHeight.subtract(labelHeight).doubleValue(); |
|
|
|
if (heightDiff < 0) { |
|
|
|
log.info("IP:"+cameraSetting.getIp()+"与目标的高度差:"+heightDiff+"小于0"); |
|
|
|
} else{ |
|
|
|
BigDecimal longitude = cameraSetting.getLongitude();//经度
|
|
|
|
BigDecimal latitude = cameraSetting.getLatitude();//纬度
|
|
|
|
double zDis = GEOUtils.GetDistance(longitude.doubleValue(), latitude.doubleValue(), targetLonLat.getLon(), targetLonLat.getLat()); |
|
|
|
log.info("下标i:"+i+ " 相机IP:"+ cameraSetting.getIp() +" 距离当前相机:"+zDis); |
|
|
|
//todo : 更新距离最小的数据 如果数据是按顺序的 可以判断当数据比前一个数据变大的时候就终止 取前一个数据
|
|
|
|
if (zDis<minDis){ |
|
|
|
minDis=zDis; |
|
|
|
index=i; |
|
|
|
} |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
// todo : 优化1.0
|
|
|
|
// 计算距离最近的球机
|
|
|
|
MsCameraSetting msCameraSetting = null;//最近球机信息
|
|
|
@ -889,22 +865,9 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
log.info("case4 :" + " 相机IP:" + msCameraSetting.getIp() + " 最短距离nearestDistance:" + nearestDistance); |
|
|
|
log.info("case4 :" + "距离最近的相机:" + JSON.toJSONString(msCameraSetting)); |
|
|
|
|
|
|
|
/* //todo : 计算PTZ
|
|
|
|
//球机高度
|
|
|
|
BigDecimal cameraHeight = msCameraSetting.getHeight(); |
|
|
|
//目标高度
|
|
|
|
BigDecimal labelHeight = new BigDecimal(h); |
|
|
|
//球机与目标的高度差
|
|
|
|
double heightDiff = cameraHeight.subtract(labelHeight).doubleValue(); |
|
|
|
//高度差小于0 则说明目标在球机上方 超过球机照射范围
|
|
|
|
if (heightDiff < 0) { |
|
|
|
log.info("heightDiff < 0 超过球机照射范围"); |
|
|
|
return; |
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
//todo : 球机也跟踪光电过去(此处可保留 也可删除 因为轨迹数据也会让球机过去)
|
|
|
|
//1.先控制球机照射目标
|
|
|
|
log.info("【尝试使用ptzControllerByLatLonAndDistance】"); |
|
|
|
log.info("case4【尝试使用ptzControllerByLatLonAndDistance】将球机转到目标位置"); |
|
|
|
msCameraSettingService.ptzControllerByLatLon(msCameraSetting.getIp(), |
|
|
|
msCameraSetting.getUser(), |
|
|
|
msCameraSetting.getPassword(), |
|
|
@ -930,7 +893,8 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
log.info("targetLonLat.getLat()" + targetLonLat.getLat()); |
|
|
|
|
|
|
|
//todo : 2.水平跟踪目标 目标详细信息再redis中 当雷达开启目标跟踪后 将发case3数据 订阅case3数据后 将目标详细数据缓存到redis中
|
|
|
|
log.info("------case4将球机转到目标位置-------"); |
|
|
|
//由于只能接收到方位角和距离 并且轨迹不断更新 所以只能将方位角和距离进行
|
|
|
|
//由于经纬度不断变化 暂时不使用经纬度进行定位
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.00");//保留两位小数
|
|
|
|
String longitude = decimalFormat.format(targetLonLat.getLon()); |
|
|
|
String latitude = decimalFormat.format(targetLonLat.getLat()); |
|
|
@ -938,43 +902,20 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
//获取轨迹信息
|
|
|
|
//String redisKey = "tracks"+"_"+longitude+"_"+latitude;
|
|
|
|
int redisAzimuth = (int) azimuth; |
|
|
|
String redisKey = "tracks:"+redisAzimuth; |
|
|
|
log.info("case4 :"+"longitude:"+longitude+" "+"latitude"+latitude+"azimuth"+redisAzimuth); |
|
|
|
|
|
|
|
|
|
|
|
// todo : 1.通过船速和航向控制球机转动(不采用)
|
|
|
|
/* float targetSpeed = Float.parseFloat(redisUtil.hget(redisKey, "targetSpeed").toString());//航速
|
|
|
|
float targetCourse =Float.parseFloat(redisUtil.hget(redisKey, "targetCourse").toString());//航向
|
|
|
|
|
|
|
|
log.info("targetCourse 航向:"+String.valueOf(targetSpeed)); |
|
|
|
log.info("targetSpeed 航速:"+String.valueOf(targetCourse)); |
|
|
|
|
|
|
|
double ySpend = Math.cos(Math.toRadians(targetCourse))*targetSpeed; //正数 上 负数 下
|
|
|
|
log.info("ySpend 方向:"+String.valueOf(ySpend)); |
|
|
|
|
|
|
|
String instruct="stop"; |
|
|
|
//todo : 待优化
|
|
|
|
if (ySpend>=0){ //160 下 330 上
|
|
|
|
instruct="right";//(-1, 0, 0)
|
|
|
|
}else { |
|
|
|
instruct="left";//(1, 0, 0)
|
|
|
|
} |
|
|
|
|
|
|
|
//todo : 速度的计算 根据航速和航向
|
|
|
|
float speed= (float) (targetSpeed * msCameraSetting.getLeftAngle()); |
|
|
|
log.info("相机水平转动速度:"+String.valueOf(speed)+"方向:"+instruct); |
|
|
|
int redisDis = (((int) distance + 999) / 1000) * 1000; |
|
|
|
String redisKey = "tracks:" + redisAzimuth + "_" + redisDis; |
|
|
|
log.info("case4 :" + "longitude:" + longitude + " " + "latitude" + latitude + "azimuth" + redisAzimuth + redisDis); |
|
|
|
log.info("case4 :" + "redisKey = " + redisKey); |
|
|
|
|
|
|
|
msCameraSettingService.ptzControl(msCameraSetting.getIp(), msCameraSetting.getUser(), msCameraSetting.getPassword(),instruct,speed); |
|
|
|
*/ |
|
|
|
|
|
|
|
//todo : 2.通过不断更新的船经纬度信息控制球机转动
|
|
|
|
/* redisUtil.hget(redisKey,"targetLon"); |
|
|
|
redisUtil.hget(redisKey,"targetLat");*/ |
|
|
|
int trackId = (int) redisUtil.hget(redisKey, "trackId");//根据方位角 找到 轨迹Id
|
|
|
|
int trackId = Integer.valueOf(redisUtil.hget(redisKey, "trackId").toString());//根据方位角 找到 轨迹Id
|
|
|
|
redisUtil.hset("trackingTargetId", String.valueOf(trackId), msCameraSetting.getIp());//将该轨迹 和 定位该轨迹的球机 保存到跟踪队列中
|
|
|
|
log.info("正在跟踪的trackId:" + trackId); |
|
|
|
|
|
|
|
//todo : 根据trackId更新的数据转动球机
|
|
|
|
//todo : case4 当前轨迹数据是正在跟踪点时 调动球机跟踪
|
|
|
|
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
@ -986,8 +927,10 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
}; |
|
|
|
new Thread(nyGuideCamPosThread).start(); |
|
|
|
|
|
|
|
|
|
|
|
//todo : 新增代码 球机联动
|
|
|
|
/** |
|
|
|
* case3 : 船轨迹数据 (开启目标跟踪使能后 持续发送) |
|
|
|
* address : 172.20.0.77 (ZMQ发布地址) |
|
|
|
* port : 5151 |
|
|
|
* topic : RadarTrack(todo : 暂时写死 后续通过配置文件配置) |
|
|
@ -1016,8 +959,9 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
//将每个目标轨迹信息进行缓存
|
|
|
|
//String redisKey = "tracks"+"_"+longitude+"_"+latitude;//经纬度来进行缓存
|
|
|
|
float redisAzimuth = Float.parseFloat(azimuth); |
|
|
|
int redisDis = ((radarTrackModel.getDis() + 999) / 1000) * 1000; |
|
|
|
|
|
|
|
String redisKey = "tracks:"+(int)redisAzimuth;//方位角进行缓存
|
|
|
|
String redisKey = "tracks:" + (int) redisAzimuth + "_" + redisDis;//方位角进行缓存
|
|
|
|
//String redisKey = "tracks";//方位角进行缓存
|
|
|
|
|
|
|
|
//todo : 将雷达轨迹数据持续进行缓存 后续根据当用户点击雷达图的目标时 持续跟踪最新的该目标信息(存在的问题 : 雷达数据不更新)
|
|
|
@ -1048,13 +992,11 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
log.info("查询当前轨迹是否处于跟踪状态" + ip); |
|
|
|
if (ip != null) {// 该轨迹处于跟踪状态
|
|
|
|
|
|
|
|
// todo : 2.0
|
|
|
|
//计算最近球机
|
|
|
|
List<MsCameraSetting> cameraSettings = null;//todo : 查询所有的球机 暂时查询本项目数据库 实际可能查询别的项目数据库
|
|
|
|
LambdaQueryWrapper<MsCameraSetting> cameraSettingLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType, 2);//只查询球机的信息 type:2 球机 type:1 枪击 type:10 故障
|
|
|
|
//todo : 用于调整球机初始角
|
|
|
|
//cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType,5);//只查询球机的信息
|
|
|
|
//cameraSettingLambdaQueryWrapper.eq(MsCameraSetting::getType,5);//只查询球机的信息 用于调整球机初始角
|
|
|
|
|
|
|
|
cameraSettings = msCameraSettingService.list(cameraSettingLambdaQueryWrapper); |
|
|
|
if (cameraSettings == null || cameraSettings.isEmpty()) { |
|
|
@ -1067,7 +1009,6 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
double nearestDistance = 0;//最近距离
|
|
|
|
double heightDiff = 0;//最近球机的高度差
|
|
|
|
double targetHeight = Double.parseDouble(redisUtil.hget("alarm_settings", "targetHeight").toString()); |
|
|
|
//Map cameraList=new HashMap();//保存距离目标球机的顺序
|
|
|
|
for (MsCameraSetting cameraSetting : cameraSettings) { |
|
|
|
// todo : 判断该球机是否满足照射范围 不满足的话还可以找第二近的球机 如果放到后面才判断高度差 就无法找第二近的去跟踪了
|
|
|
|
BigDecimal cameraHeight = cameraSetting.getHeight();//球机高度
|
|
|
@ -1135,8 +1076,7 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
log.info("cameraSetting.getLatitude():" + msCameraSetting.getLatitude().doubleValue()); |
|
|
|
log.info("targetLonLat.getLon()" + targetLon); |
|
|
|
log.info("targetLonLat.getLat()" + targetLat); |
|
|
|
|
|
|
|
log.info("case3 :"+"已控制球机照过去 等待下一次轨迹信息 在进行下次定位"); |
|
|
|
log.info("case3 :" + "已控制球机照过去 等待下一次更新的轨迹信息 在进行下次定位"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -1146,133 +1086,6 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws SOAPException, ConnectException { |
|
|
|
float speed=10.45f; |
|
|
|
System.out.println(speed*1000L); |
|
|
|
long result= (long) (speed*1000L); |
|
|
|
System.out.println(result); |
|
|
|
|
|
|
|
|
|
|
|
RadarTrackModel radarTrackModel =new RadarTrackModel(); |
|
|
|
radarTrackModel.setDis(1); |
|
|
|
log.info(JSON.toJSONString(radarTrackModel)); |
|
|
|
|
|
|
|
String a="314.8044"; |
|
|
|
float b= Float.parseFloat(a); |
|
|
|
System.out.println(b); |
|
|
|
|
|
|
|
float azimuth=314.80445f; |
|
|
|
int redisAzimuth=(int)azimuth; |
|
|
|
System.out.println(redisAzimuth); |
|
|
|
|
|
|
|
double targetSpeed=1.0831853; |
|
|
|
double targetCourse=330; |
|
|
|
double degree=Math.toRadians(targetCourse); |
|
|
|
|
|
|
|
double cos=Math.cos(degree); |
|
|
|
double ySpend = Math.cos(targetCourse)*targetSpeed; |
|
|
|
System.out.println(degree); |
|
|
|
System.out.println(cos); |
|
|
|
System.out.println(ySpend); |
|
|
|
System.out.println("--------------------"); |
|
|
|
/* System.out.println(System.getProperty("user.dir") + "\\lib\\hk\\win64\\HCNetSDK.dll"); |
|
|
|
de.onvif.soap.OnvifDevice onvifDevice = new OnvifDevice("192.168.1.71","admin","hk123456"); |
|
|
|
PtzDevices ptzDevices = onvifDevice.getPtz(); |
|
|
|
String token = onvifDevice.getDevices().getProfiles().get(0).getToken();*/ |
|
|
|
// boolean absoluteMoveSupported = ptzDevices.isAbsoluteMoveSupported(token);
|
|
|
|
/* System.out.println(absoluteMoveSupported); |
|
|
|
ptzDevices.absoluteMove(token,0.5f,0.5f,0.5f); |
|
|
|
ptzDevices.relativeMove(token,0,0,0.5f);*/ |
|
|
|
|
|
|
|
/* ptzDevices.absoluteMove(token,0.5f,0f,0f); |
|
|
|
ptzDevices.relativeMove(token,0,0,0.5f); |
|
|
|
ptzDevices.continuousMove(token,0.5f , 0f, 0f); |
|
|
|
//ptzDevices.stopMove(token);
|
|
|
|
PTZStatus status = ptzDevices.getStatus(token);*/ |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("flag",1); |
|
|
|
jsonObject.put("sourceId","AgilTrack_cat010bsz"); |
|
|
|
jsonObject.put("utc",System.currentTimeMillis()); |
|
|
|
|
|
|
|
List<RadarTrackModel> radarTracks=new ArrayList<>(); |
|
|
|
RadarTrackModel radarTrack = new RadarTrackModel(); |
|
|
|
radarTrack.setDis(100); |
|
|
|
radarTrack.setAzimuth(315); |
|
|
|
radarTrack.setRadarId(10); |
|
|
|
radarTrack.setSpeed(10); |
|
|
|
radarTrack.setLatitude(22.180616f); |
|
|
|
radarTrack.setLongitude(113.40126f); |
|
|
|
radarTracks.add(radarTrack); |
|
|
|
jsonObject.put("radarTracks",JSON.toJSONString(radarTracks)); |
|
|
|
String jsonString = JSON.toJSONString(jsonObject); |
|
|
|
|
|
|
|
byte[] data=jsonString.getBytes(); |
|
|
|
|
|
|
|
JSONObject jsonObject2 = JSON.parseObject(new String(data)); |
|
|
|
log.info("1.RadarTrack数据:" + jsonObject2.toString()); |
|
|
|
|
|
|
|
String radarTarcksJsonString = (String) jsonObject2.get("radarTracks"); |
|
|
|
List<RadarTrackModel> radarTrackModels = JSONObject.parseArray(radarTarcksJsonString, RadarTrackModel.class); |
|
|
|
float latitude = radarTrackModels.get(0).getLatitude(); |
|
|
|
float longitude = radarTrackModels.get(0).getLongitude(); |
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.00"); |
|
|
|
String l = decimalFormat.format(latitude); |
|
|
|
String r = decimalFormat.format(longitude); |
|
|
|
System.out.println(latitude); |
|
|
|
System.out.println(longitude); |
|
|
|
System.out.println(l); |
|
|
|
System.out.println(r); |
|
|
|
System.out.println(radarTrackModels); |
|
|
|
|
|
|
|
float ab=1.0831853f; |
|
|
|
log.info(String.valueOf(ab)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取最近球机 |
|
|
|
* @param cameraSettings 所有球机 |
|
|
|
* @param targetHeight 目标高度 |
|
|
|
* @param targetLon 目标经度 |
|
|
|
* @param targetLat 目标纬度 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public MsCameraSetting getNearestDistanceCamera(List<MsCameraSetting> cameraSettings,double targetHeight,double targetLon,double targetLat){ |
|
|
|
// todo : 优化1.0
|
|
|
|
// 计算距离最近的球机
|
|
|
|
MsCameraSetting msCameraSetting=null;//最近球机信息
|
|
|
|
double nearestDistance=0;//最近距离
|
|
|
|
double heightDiff=0;//最近球机的高度差
|
|
|
|
//Map cameraList=new HashMap();//保存距离目标球机的顺序
|
|
|
|
for (MsCameraSetting cameraSetting : cameraSettings) { |
|
|
|
// todo : 判断该球机是否满足照射范围 不满足的话还可以找第二近的球机 如果放到后面才判断高度差 就无法找第二近的去跟踪了
|
|
|
|
BigDecimal cameraHeight = cameraSetting.getHeight();//球机高度
|
|
|
|
BigDecimal labelHeight = new BigDecimal(targetHeight);//目标高度
|
|
|
|
double tempHeightDiff = cameraHeight.subtract(labelHeight).doubleValue();//球机与目标高度差
|
|
|
|
if (tempHeightDiff<0){ |
|
|
|
log.info("ip="+cameraSetting.getIp() + " tempHeightDiff < 0 超过球机照射范围"); |
|
|
|
}else { |
|
|
|
double temp = GEOUtils.GetDistance(cameraSetting.getLongitude().doubleValue(),cameraSetting.getLatitude().doubleValue(),targetLon,targetLat); |
|
|
|
// 第一次 先将第一个球机的距离作为最近距离 和 最近球机信息
|
|
|
|
if (msCameraSetting==null){ |
|
|
|
msCameraSetting=cameraSetting; |
|
|
|
nearestDistance=temp; |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 第二次以后 如果距离更近则更新最近距离 以及 最近球机信息
|
|
|
|
if (nearestDistance>temp){ |
|
|
|
msCameraSetting=cameraSetting; |
|
|
|
nearestDistance=temp; |
|
|
|
heightDiff=tempHeightDiff; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//判断两点的距离是否超过有效距离,超过则丢掉
|
|
|
|
if (nearestDistance > Integer.parseInt(redisUtil.hget("alarm_settings", "inOutEffectDistance").toString())) { |
|
|
|
log.info("超过跟踪的最大距离"+redisUtil.hget("alarm_settings", "inOutEffectDistance").toString()); |
|
|
|
} |
|
|
|
return msCameraSetting; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 计算围网报警有效区域(围网外5米 + 雷达测角误差±1°造成的距离偏差) |
|
|
@ -1416,4 +1229,176 @@ public class MilitaryZMQApplication implements ApplicationRunner { |
|
|
|
return new MsAreaPoint[]{pointMap.get(min1), pointMap.get(min2)}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//测试数据
|
|
|
|
public static void main(String[] args) throws SOAPException, ConnectException { |
|
|
|
float d = 3142f; |
|
|
|
int redisDis = (((int) d + 999) / 1000) * 1000; |
|
|
|
System.out.println(redisDis); |
|
|
|
int dis = 845; |
|
|
|
int count = (int) Math.log10(dis) + 1; |
|
|
|
System.out.println();//判断一个数是几位数
|
|
|
|
|
|
|
|
int num = 5000; |
|
|
|
System.out.println(((num + 999) / 1000) * 1000); |
|
|
|
|
|
|
|
|
|
|
|
float speed = 10.45f; |
|
|
|
System.out.println(speed * 1000L); |
|
|
|
long result = (long) (speed * 1000L); |
|
|
|
System.out.println(result); |
|
|
|
|
|
|
|
|
|
|
|
RadarTrackModel radarTrackModel = new RadarTrackModel(); |
|
|
|
radarTrackModel.setDis(1); |
|
|
|
log.info(JSON.toJSONString(radarTrackModel)); |
|
|
|
|
|
|
|
String a = "314.8044"; |
|
|
|
float b = Float.parseFloat(a); |
|
|
|
System.out.println(b); |
|
|
|
|
|
|
|
float azimuth = 314.80445f; |
|
|
|
int redisAzimuth = (int) azimuth; |
|
|
|
System.out.println(redisAzimuth); |
|
|
|
|
|
|
|
double targetSpeed = 1.0831853; |
|
|
|
double targetCourse = 330; |
|
|
|
double degree = Math.toRadians(targetCourse); |
|
|
|
|
|
|
|
double cos = Math.cos(degree); |
|
|
|
double ySpend = Math.cos(targetCourse) * targetSpeed; |
|
|
|
System.out.println(degree); |
|
|
|
System.out.println(cos); |
|
|
|
System.out.println(ySpend); |
|
|
|
System.out.println("--------------------"); |
|
|
|
/* System.out.println(System.getProperty("user.dir") + "\\lib\\hk\\win64\\HCNetSDK.dll"); |
|
|
|
de.onvif.soap.OnvifDevice onvifDevice = new OnvifDevice("192.168.1.71","admin","hk123456"); |
|
|
|
PtzDevices ptzDevices = onvifDevice.getPtz(); |
|
|
|
String token = onvifDevice.getDevices().getProfiles().get(0).getToken();*/ |
|
|
|
// boolean absoluteMoveSupported = ptzDevices.isAbsoluteMoveSupported(token);
|
|
|
|
/* System.out.println(absoluteMoveSupported); |
|
|
|
ptzDevices.absoluteMove(token,0.5f,0.5f,0.5f); |
|
|
|
ptzDevices.relativeMove(token,0,0,0.5f);*/ |
|
|
|
|
|
|
|
/* ptzDevices.absoluteMove(token,0.5f,0f,0f); |
|
|
|
ptzDevices.relativeMove(token,0,0,0.5f); |
|
|
|
ptzDevices.continuousMove(token,0.5f , 0f, 0f); |
|
|
|
//ptzDevices.stopMove(token);
|
|
|
|
PTZStatus status = ptzDevices.getStatus(token);*/ |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("flag", 1); |
|
|
|
jsonObject.put("sourceId", "AgilTrack_cat010bsz"); |
|
|
|
jsonObject.put("utc", System.currentTimeMillis()); |
|
|
|
|
|
|
|
List<RadarTrackModel> radarTracks = new ArrayList<>(); |
|
|
|
RadarTrackModel radarTrack = new RadarTrackModel(); |
|
|
|
radarTrack.setDis(100); |
|
|
|
radarTrack.setAzimuth(315); |
|
|
|
radarTrack.setRadarId(10); |
|
|
|
radarTrack.setSpeed(10); |
|
|
|
radarTrack.setLatitude(22.180616f); |
|
|
|
radarTrack.setLongitude(113.40126f); |
|
|
|
radarTracks.add(radarTrack); |
|
|
|
jsonObject.put("radarTracks", JSON.toJSONString(radarTracks)); |
|
|
|
String jsonString = JSON.toJSONString(jsonObject); |
|
|
|
|
|
|
|
byte[] data = jsonString.getBytes(); |
|
|
|
|
|
|
|
JSONObject jsonObject2 = JSON.parseObject(new String(data)); |
|
|
|
log.info("1.RadarTrack数据:" + jsonObject2.toString()); |
|
|
|
|
|
|
|
String radarTarcksJsonString = (String) jsonObject2.get("radarTracks"); |
|
|
|
List<RadarTrackModel> radarTrackModels = JSONObject.parseArray(radarTarcksJsonString, RadarTrackModel.class); |
|
|
|
float latitude = radarTrackModels.get(0).getLatitude(); |
|
|
|
float longitude = radarTrackModels.get(0).getLongitude(); |
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.00"); |
|
|
|
String l = decimalFormat.format(latitude); |
|
|
|
String r = decimalFormat.format(longitude); |
|
|
|
System.out.println(latitude); |
|
|
|
System.out.println(longitude); |
|
|
|
System.out.println(l); |
|
|
|
System.out.println(r); |
|
|
|
System.out.println(radarTrackModels); |
|
|
|
|
|
|
|
float ab = 1.0831853f; |
|
|
|
log.info(String.valueOf(ab)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据船速和航向进行跟踪
|
|
|
|
private void trackingTarget() { |
|
|
|
// todo : 通过船速和航向控制球机转动(不采用)
|
|
|
|
MsCameraSetting msCameraSetting=null; |
|
|
|
|
|
|
|
String redisKey = "";//根据雷达图上目标的距离和方位角找到轨迹数据中对应的目标ID
|
|
|
|
|
|
|
|
float targetSpeed = Float.parseFloat(redisUtil.hget(redisKey, "targetSpeed").toString());//获取跟踪目标的航速
|
|
|
|
float targetCourse = Float.parseFloat(redisUtil.hget(redisKey, "targetCourse").toString());//获取跟踪目标的航向
|
|
|
|
|
|
|
|
log.info("targetCourse 航向:" + String.valueOf(targetSpeed)); |
|
|
|
log.info("targetSpeed 航速:" + String.valueOf(targetCourse)); |
|
|
|
|
|
|
|
//计算水平运动速度
|
|
|
|
double ySpend = Math.cos(Math.toRadians(targetCourse)) * targetSpeed; //正数 上 负数 下
|
|
|
|
log.info("ySpend 方向:" + String.valueOf(ySpend)); |
|
|
|
|
|
|
|
String instruct = "stop"; |
|
|
|
//todo : 待优化
|
|
|
|
if (ySpend >= 0) { //160 下 330 上
|
|
|
|
instruct = "right";//(-1, 0, 0)
|
|
|
|
} else { |
|
|
|
instruct = "left";//(1, 0, 0)
|
|
|
|
} |
|
|
|
|
|
|
|
//todo : 速度的计算 根据航速和航向
|
|
|
|
float speed = (float) (targetSpeed * msCameraSetting.getLeftAngle()); |
|
|
|
log.info("相机水平转动速度:" + String.valueOf(speed) + "方向:" + instruct); |
|
|
|
|
|
|
|
msCameraSettingService.ptzControl(msCameraSetting.getIp(), msCameraSetting.getUser(), msCameraSetting.getPassword(), instruct, speed); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取最近球机 |
|
|
|
* |
|
|
|
* @param cameraSettings 所有球机 |
|
|
|
* @param targetHeight 目标高度 |
|
|
|
* @param targetLon 目标经度 |
|
|
|
* @param targetLat 目标纬度 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public MsCameraSetting getNearestDistanceCamera(List<MsCameraSetting> cameraSettings, double targetHeight, double targetLon, double targetLat) { |
|
|
|
// 计算距离最近的球机
|
|
|
|
MsCameraSetting msCameraSetting = null;//最近球机信息
|
|
|
|
double nearestDistance = 0;//最近距离
|
|
|
|
double heightDiff = 0;//最近球机的高度差
|
|
|
|
//Map cameraList=new HashMap();//保存距离目标球机的顺序
|
|
|
|
for (MsCameraSetting cameraSetting : cameraSettings) { |
|
|
|
// todo : 判断该球机是否满足照射范围 不满足的话还可以找第二近的球机 如果放到后面才判断高度差 就无法找第二近的去跟踪了
|
|
|
|
BigDecimal cameraHeight = cameraSetting.getHeight();//球机高度
|
|
|
|
BigDecimal labelHeight = new BigDecimal(targetHeight);//目标高度
|
|
|
|
double tempHeightDiff = cameraHeight.subtract(labelHeight).doubleValue();//球机与目标高度差
|
|
|
|
if (tempHeightDiff < 0) { |
|
|
|
log.info("ip=" + cameraSetting.getIp() + " tempHeightDiff < 0 超过球机照射范围"); |
|
|
|
} else { |
|
|
|
double temp = GEOUtils.GetDistance(cameraSetting.getLongitude().doubleValue(), cameraSetting.getLatitude().doubleValue(), targetLon, targetLat); |
|
|
|
// 第一次 先将第一个球机的距离作为最近距离 和 最近球机信息
|
|
|
|
if (msCameraSetting == null) { |
|
|
|
msCameraSetting = cameraSetting; |
|
|
|
nearestDistance = temp; |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 第二次以后 如果距离更近则更新最近距离 以及 最近球机信息
|
|
|
|
if (nearestDistance > temp) { |
|
|
|
msCameraSetting = cameraSetting; |
|
|
|
nearestDistance = temp; |
|
|
|
heightDiff = tempHeightDiff; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//判断两点的距离是否超过有效距离,超过则丢掉
|
|
|
|
if (nearestDistance > Integer.parseInt(redisUtil.hget("alarm_settings", "inOutEffectDistance").toString())) { |
|
|
|
log.info("超过跟踪的最大距离" + redisUtil.hget("alarm_settings", "inOutEffectDistance").toString()); |
|
|
|
} |
|
|
|
return msCameraSetting; |
|
|
|
} |
|
|
|
} |
|
|
|