| | |
| | | import com.zy.core.thread.RgvThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private BasCircularShuttleService basCircularShuttleService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | |
| | | @Value("${constant-parameters.perimeter}") |
| | | private Long perimeter; |
| | | @Value("${constant-parameters.proportion}") |
| | | private Long proportion; |
| | | @Value("${constant-parameters.acceleration}") |
| | | private Long acceleration; |
| | | @Value("${constant-parameters.rgvCount}") |
| | | private Long rgvCount; |
| | | @Value("${constant-parameters.rgvDate}") |
| | | private Double rgvDate; |
| | | /** |
| | | * 站点任务检测 更新小车位置信息 |
| | | */ |
| | | public synchronized void updateStePositionNearby1() { |
| | | for (RgvSlave rgvSlave:slaveProperties.getRgv()) { |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | try{ |
| | | double finalVelocity = 0.0; // 最终速度 (m/s) |
| | | double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed/60, 2)) / (2 * acceleration); |
| | | BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", 111)); |
| | | if (distance*proportion > ((SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(),rgvProtocol.getRgvPos(),perimeter) + (rgvProtocol.instantaneousSpeed/60)*proportion*0.1))){ |
| | | // continue ; |
| | | } |
| | | } catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public synchronized void updateStePositionNearby() { |
| | | try{ |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L)); |
| | | if (wrkMasts.isEmpty()){ |
| | | return; |
| | | } |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position",false)); |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position",true)); |
| | | if (basDevpPositions.isEmpty()){ |
| | | log.error("获取所有站点信息异常"); |
| | | return; |
| | |
| | | rgvPosition.add(rgvProtocol.getRgvPos()); |
| | | rgvPositionList.add(rgvPosition); |
| | | } |
| | | Integer rgvNo = SortTheExecutionOfTheCarUtil.LatelyAndGreaterThan(rgvPositionList, sitePosition); |
| | | |
| | | Integer rgvNo = SortTheExecutionOfTheCarUtil.LatelyAndGreaterThan(rgvPositionList, sitePosition,perimeter); |
| | | if (rgvNo == -1){ |
| | | log.info("更新小车排序信息异常={}",rgvNo); |
| | | return; |
| | | } |
| | | List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<BasCircularShuttle>().orderBy("rgv_id", true)); |
| | | if (basCircularShuttleList.get(0).getRgvNo().equals(rgvNo)){ |
| | | return; |
| | |
| | | if (wrkMasts.isEmpty()){ |
| | | return; |
| | | } |
| | | long differenceInSeconds = TimeCalculatorUtils.differenceInSeconds(wrkMasts.get(0).getModiTime(), new Date()); |
| | | if (differenceInSeconds<=5){ |
| | | long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(wrkMasts.get(0).getModiTime(), new Date()); |
| | | if (differenceInSeconds<=100){ |
| | | return; |
| | | } |
| | | |
| | |
| | | if (rgvProtocol == null) { |
| | | return; |
| | | } |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position",false)); |
| | | Integer devNo = SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPositions, rgvProtocol.getRgvPos()); |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position",true)); |
| | | Integer devNo = SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPositions, rgvProtocol.getRgvPos(),perimeter); |
| | | BasDevpPosition[] basDevpPositionsList = SortTheExecutionOfTheCarUtil.devpNoSort(basDevpPositions, devNo); |
| | | BasDevpPosition[] basDevpPositionsListUN = SortTheExecutionOfTheCarUtil.devpNoSortUN(basDevpPositionsList); |
| | | List<List<WrkMast>> wrkMastLists = getWrkMastLists(basDevpPositionsListUN); |
| | |
| | | runRgv: |
| | | for (List<WrkMast> wrkMastList : wrkMastLists){ |
| | | for (WrkMast wrkMast: wrkMastList){ |
| | | log.error("存在任务,RGV号={},任务数据={}", rgvId, JSON.toJSON(wrkMast)); |
| | | while (rgvId <= rgvCount){ |
| | | rgvId++; |
| | | log.info("存在任务,RGV号={},任务数据={}", rgvId, JSON.toJSON(wrkMast)); |
| | | |
| | | rgvId++; |
| | | BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", 1L)); |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol != null |
| | | && rgvProtocol.modeType == RgvModeType.AUTO |
| | | && (rgvProtocol.getStatusType() == RgvStatusType.IDLE || rgvProtocol.getStatusType() == RgvStatusType.ROAM) |
| | | && rgvProtocol.getTaskNo1()==0 |
| | | && rgvProtocol.getAlarm() == 0){ |
| | | RgvCommand rgvCommand = new RgvCommand(); |
| | | rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); |
| | | rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位 |
| | | rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); |
| | | rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货 |
| | | rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //工位1起点 |
| | | rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //工位1目标站点 |
| | | rgvCommand.setCommand((short) 1); //工位1任务确认 |
| | | if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { |
| | | // |
| | | log.error("RGV命令下发失败,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | if (rgvId > rgvCount){ |
| | | break runRgv; |
| | | } |
| | | log.error("RGV命令下发成功,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | |
| | | wrkMast.setWrkSts(2L); |
| | | wrkMast.setRgvNo(rgvProtocol.getRgvNo()); |
| | | wrkMast.setAppeTime(new Date()); |
| | | try{ |
| | | wrkMastService.updateById(wrkMast); |
| | | BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", rgvId)); |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null){ |
| | | continue ; |
| | | }catch (Exception e){ |
| | | log.error("更新小车任务失败,任务号:"+wrkMast.getWrkNo()); |
| | | } |
| | | break runRgv; |
| | | } else { |
| | | break runRgv; |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("rgv_no", rgvProtocol.getRgvNo()).eq("wrk_sts", 2L)); |
| | | if (!wrkMasts.isEmpty()){ |
| | | continue ; |
| | | } |
| | | if (rgvProtocol != null |
| | | && rgvProtocol.modeType == RgvModeType.AUTO |
| | | && (rgvProtocol.getStatusType() == RgvStatusType.IDLE || rgvProtocol.getStatusType() == RgvStatusType.ROAM) |
| | | && rgvProtocol.getTaskNo1()==0 |
| | | && rgvProtocol.getAlarm() == 0){ |
| | | if (rgvProtocol.getStatusType() == RgvStatusType.ROAM) { |
| | | double finalVelocity = 0.0; // 最终速度 (m/s) |
| | | double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed/60, 2)) / (2 * acceleration); |
| | | BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); |
| | | if (distance*proportion > ((SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(),rgvProtocol.getRgvPos(),perimeter) + (rgvProtocol.instantaneousSpeed/60)*proportion*rgvDate))){ |
| | | continue ; |
| | | } |
| | | } |
| | | RgvCommand rgvCommand = new RgvCommand(); |
| | | rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); |
| | | rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位 |
| | | rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); |
| | | rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货 |
| | | rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //工位1起点 |
| | | rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //工位1目标站点 |
| | | rgvCommand.setCommand((short) 1); //工位1任务确认 |
| | | if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { |
| | | // |
| | | log.error("RGV命令下发失败,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | break runRgv; |
| | | } |
| | | log.info("RGV命令下发成功,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | |
| | | wrkMast.setWrkSts(2L); |
| | | wrkMast.setRgvNo(rgvProtocol.getRgvNo()); |
| | | wrkMast.setAppeTime(new Date()); |
| | | try{ |
| | | wrkMastService.updateById(wrkMast); |
| | | break; |
| | | }catch (Exception e){ |
| | | log.error("更新小车任务失败,任务号:"+wrkMast.getWrkNo()); |
| | | } |
| | | break runRgv; |
| | | } else { |
| | | break runRgv; |
| | | } |
| | | } |
| | | } |
| | | } |