This commit is contained in:
2022-12-22 10:11:08 +08:00
parent 94e1aa281f
commit 363d6b7f0d
9 changed files with 1036 additions and 2 deletions

View File

@@ -147,6 +147,11 @@ public interface AgvService {
*/
public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception;
public HttpResponse pauseVehicleToXZ(JSONObject jsonObject) throws Exception;
public HttpResponse resumeVehicleToXZ(JSONObject jsonObject) throws Exception;
public HttpResponse addOrderSequences(Instruction inst) throws Exception;
/**
@@ -161,6 +166,7 @@ public interface AgvService {
public JSONObject createOrederData(Instruction inst, String type);
public JSONArray createBlocksData(Instruction inst);
/**
* magic 全部暂停车辆
*/

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
@@ -1521,6 +1522,48 @@ public class AgvServiceImpl implements AgvService {
}
}
@Override
public HttpResponse pauseVehicleToXZ(JSONObject jsonObject) throws Exception {
if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) {
String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL);
String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT);
agvurl = agvurl + ":" + agvport + "/gotoSitePause";
System.out.println("请求地址为:" + agvurl);
HttpResponse result = HttpRequest.post(agvurl)
.body(JSON.toJSONString(jsonObject))//表单内容
.timeout(20000)//超时,毫秒
.execute();
System.out.println("返回结果为:" + result);
log.info(agvurl);
logServer.log("pauseVehicle", "pauseVehicleToXZ", "info", String.valueOf(jsonObject), result.body(), String.valueOf(result.getStatus()), agvurl, String.valueOf(jsonObject));
return result;
} else {
return null;
}
}
@Override
public HttpResponse resumeVehicleToXZ(JSONObject jsonObject) throws Exception {
if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) {
String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL);
String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT);
agvurl = agvurl + ":" + agvport + "/gotoSiteResume";
System.out.println("请求地址为:" + agvurl);
HttpResponse result = HttpRequest.post(agvurl)
.body(JSON.toJSONString(jsonObject))//表单内容
.timeout(20000)//超时,毫秒
.execute();
System.out.println("返回结果为:" + result);
log.info(agvurl);
logServer.log("resumeVehicle", "resumeVehicleToXZ", "info", String.valueOf(jsonObject), result.body(), String.valueOf(result.getStatus()), agvurl, String.valueOf(jsonObject));
return result;
} else {
return null;
}
}
@Override
public HttpResponse addOrderSequences(Instruction inst) throws Exception {
JSONObject orderjo = createOrederData(inst, "1");

View File

@@ -0,0 +1,44 @@
package org.nl.acs.common.deviceInfo;
import net.sf.json.JSONObject;
import org.nl.acs.common.AbstractDriverService;
import org.nl.acs.device_driver.tianneng.PauseOrResumeDeviceDriver;
import org.nl.acs.opc.Device;
import org.nl.acs.task.service.dto.TaskDto;
import org.springframework.stereotype.Component;
/**
* @author geng by
* 输送线
*/
@Component("pauseOrResume")
public class PauseOrResumeDevice extends AbstractDriverService {
PauseOrResumeDeviceDriver pauseOrResumeDeviceDriver;
@Override
public JSONObject getDeviceInfo(Device device) {
pauseOrResumeDeviceDriver = (PauseOrResumeDeviceDriver) device.getDeviceDriver();
JSONObject jo = this.getCommonDeviceInfo(pauseOrResumeDeviceDriver);
return jo;
}
@Override
public Boolean createInstCheckStartPoint(Device device, TaskDto taskDto) throws Exception {
//standardConveyorLineDeviceDriver = (StandardConveyorLineDeviceDriver) device.getDeviceDriver();
//return this.checkStartPoint(standardConveyorLineDeviceDriver, taskDto, InstEnum.standard_conveyor_line_start.getMode(), InstEnum.standard_conveyor_line_start.getMove());
return true;
}
@Override
public Boolean createInstCheckNextPoint(Device device, TaskDto taskDto) throws Exception {
//standardConveyorLineDeviceDriver = (StandardConveyorLineDeviceDriver) device.getDeviceDriver();
// return this.checkNextPoint(standardConveyorLineDeviceDriver, taskDto,InstEnum.standard_conveyor_line_next.getMode(), InstEnum.standard_conveyor_line_next.getMove());
return true;
}
@Override
public void changeDeviceStatus(Device device, JSONObject form) {
pauseOrResumeDeviceDriver = (PauseOrResumeDeviceDriver) device.getDeviceDriver();
this.changeDeviceStatus(pauseOrResumeDeviceDriver, form, false);
}
}

View File

@@ -82,7 +82,8 @@ public enum DriverTypeEnum {
//
// ssj_cache_site(37, "ssj_cache_site", "三时纪-缓存站点", "conveyor"),
STANDARDCONVEYORLINE(38, "standard_conveyor_line", "缓存架", "conveyor");
STANDARDCONVEYORLINE(38, "standard_conveyor_line", "缓存架", "conveyor"),
PAUSEorresume(39, "pauseOrResume", "agv暂停或继续", "conveyor");
//驱动索引

View File

@@ -0,0 +1,59 @@
package org.nl.acs.device_driver.tianneng;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class ItemProtocol {
public static String item_agv_action = "agv_action";
private PauseOrResumeDeviceDriver driver;
public ItemProtocol(PauseOrResumeDeviceDriver driver) {
this.driver = driver;
}
public int getAgv_action() {
return this.getOpcIntegerValue(item_agv_action);
}
//是否有货
public int hasGoods(int move) {
return move;
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegerValue(protocol);
if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_agv_action, "agv工作状态", "DB600.B502"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_agv_action, "agv工作状态", "DB600.B502"));
return list;
}
}

View File

@@ -0,0 +1,63 @@
package org.nl.acs.device_driver.tianneng;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceType;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* agv-暂停或恢复
*/
@Service
public class PauseOrResumeDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "pauseOrResume";
}
@Override
public String getDriverName() {
return "agv-暂停或恢复";
}
@Override
public String getDriverDescription() {
return "agv-暂停或恢复";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new PauseOrResumeDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return PauseOrResumeDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.conveyor);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,279 @@
package org.nl.acs.device_driver.tianneng;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.nl.acs.agv.server.AgvService;
import org.nl.acs.agv.server.impl.AgvServiceImpl;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.utils.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* agv暂停或恢复驱动
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class PauseOrResumeDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
@Autowired
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class);
@Autowired
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class);
@Autowired
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
@Autowired
AgvService agvService = SpringContextHolder.getBean(AgvServiceImpl.class);
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private Date instruction_apply_time = new Date();
private int instruction_require_time_out = 3000;
//请求暂停成功标记
Boolean requirePauseSuccess = false;
//请求继续成功标记
Boolean requireResumeSuccess = false;
int agv_action = 0;
int last_agv_action = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
String Container = null;
String device_code = null;
int branchProtocol = 0;
//备注
String remark;
//数量
String qty;
//物料
String material;
//当前指令
Instruction inst = null;
//上次指令
Instruction last_inst = null;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
String message = null;
try {
device_code = this.getDeviceCode();
agv_action = this.itemProtocol.getAgv_action();
if (agv_action != last_agv_action) {
if (agv_action == 1) {
this.setRequirePauseSuccess(false);
}
if (agv_action == 2) {
this.setRequireResumeSuccess(false);
}
this.execute_log.setResource(this.device_code, this.device.getDevice_name());
this.execute_log.log("设备:" + device_code + ",last_agv_action -> agv_action:" + last_agv_action + "->" + agv_action);
}
} catch (Exception var17) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
switch (agv_action) {
case 1:
if (!requirePauseSuccess) {
JSONObject map = new JSONObject();
JSONArray vehicles = new JSONArray();
map.put("vehicles", vehicles);
agvService.pauseVehicleToXZ(map);
this.setRequirePauseSuccess(true);
}
break;
case 2:
if (!requireResumeSuccess) {
JSONObject map = new JSONObject();
JSONArray vehicles = new JSONArray();
map.put("vehicles", vehicles);
agvService.resumeVehicleToXZ(map);
this.setRequireResumeSuccess(true);
}
break;
}
// switch (flag) {
// //取货完成
// case 1:
// writing(2);
// return;
// //放货完成
// case 2:
// writing(3);
// return;
//
// }
last_agv_action = agv_action;
}
}
public boolean exe_error() {
// if (this.error == 0) {
// return true;
// } else {
// log.debug("设备报警");
// return false;
// }
return true;
}
protected void thingToNothing() {
log.debug("从有货到无货 清理数据");
}
public void set_last_container(String barcode, String type_desc) {
this.set_last_container(barcode);
this.set_last_container_type_desc(type_desc);
}
public void set_last_container(String barcode) {
}
public void set_last_container_type_desc(String type) {
}
public boolean exe_business() {
return true;
}
protected void executing(Instruction instruction) {
this.executing(1, instruction, "");
}
public void executing(int command, Instruction instruction, String appendMessage) {
// String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_command;
// String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_target;
// String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_task;
// if (appendMessage == null) {
// appendMessage = "";
// }
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
// String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_command;
//
// String opcservcerid = this.getDevice().getOpc_server_id();
// Server server = ReadUtil.getServer(opcservcerid);
// Map<String, Object> itemMap = new HashMap<String, Object>();
// itemMap.put(to_command, command);
// ReadUtil.write(itemMap, server);
}
public void writing(int type, int command) {
// String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_command;
// String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_target;
// String to_onset = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_onset;
// String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_task;
// String opcservcerid = this.getDevice().getOpc_server_id();
// Server server = ReadUtil.getServer(opcservcerid);
// Map<String, Object> itemMap = new HashMap<String, Object>();
// if (type == 1) {
// itemMap.put(to_command, command);
// } else if (type == 2) {
// itemMap.put(to_target, command);
//
// } else if (type == 3) {
// itemMap.put(to_task, command);
// }
// ReadUtil.write(itemMap, server);
}
public void writing(Instruction inst) {
// String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_command;
// String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_target;
// String to_onset = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_onset;
// String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_task;
// String opcservcerid = this.getDevice().getOpc_server_id();
// Server server = ReadUtil.getServer(opcservcerid);
// Map<String, Object> itemMap = new HashMap<String, Object>();
// itemMap.put(to_command, 1);
// itemMap.put(to_onset, appService.findDeviceByCode(inst.getStart_device_code()).getAddress());
// itemMap.put(to_target, appService.findDeviceByCode(inst.getNext_device_code()).getAddress());
// itemMap.put(to_task, inst.getInstruction_code());
// ReadUtil.write(itemMap, server);
// this.execute_log.setResource(this.device_code, device_code);
// this.execute_log.log("设备:{},下发作业命令:{},起始站{},目标站:{},任务号:{}", device_code, to_command, to_onset, to_target, to_task);
// }
}
}