From c53ea3f750769e18b6d966d43fbe5c307138c540 Mon Sep 17 00:00:00 2001 From: xuzhiheng <2543137953@qq.com> Date: Mon, 9 Jun 2025 18:34:10 +0800 Subject: [PATCH] update --- .../LoopbackCommunicationAdapter.java | 9 +- .../http/service/ExecuteMove.java | 9 +- .../org/opentcs/manage/AdapterManage.java | 156 ++++++------------ .../manage/entity/AgvActionStatus.java | 13 ++ .../org/opentcs/manage/entity/AgvStatus.java | 6 +- .../org/opentcs/util/KernelCommunication.java | 3 +- .../servicewebapi/v1/VehicleHandler.java | 11 +- 7 files changed, 87 insertions(+), 120 deletions(-) create mode 100644 opentcs-common/src/main/java/org/opentcs/manage/entity/AgvActionStatus.java diff --git a/opentcs-commadapter-loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java b/opentcs-commadapter-loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java index 69d6fc6..972b51a 100644 --- a/opentcs-commadapter-loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java +++ b/opentcs-commadapter-loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java @@ -30,6 +30,7 @@ import org.opentcs.drivers.vehicle.SimVehicleCommAdapter; import org.opentcs.drivers.vehicle.VehicleCommAdapter; import org.opentcs.drivers.vehicle.VehicleProcessModel; import org.opentcs.drivers.vehicle.management.VehicleProcessModelTO; +import org.opentcs.manage.entity.AgvActionStatus; import org.opentcs.manage.entity.AgvInfo; import org.opentcs.manage.entity.AgvInfoParams; import org.opentcs.manage.entity.AgvStatus; @@ -284,9 +285,9 @@ public class LoopbackCommunicationAdapter if (message instanceof AgvInfo agvInfo) { //通讯适配器车辆模型更新 handleCallbacks(agvInfo.getParams()); - } else if (message instanceof AgvStatus agvStatus) { + } else if (message instanceof AgvActionStatus agvActionStatus) { //自动管理通讯适配器状态和适配器动作执行状态 - handleActionStatus(agvStatus); + handleActionStatus(agvActionStatus); } } @@ -804,8 +805,8 @@ public class LoopbackCommunicationAdapter return serialNum; } - private void handleActionStatus(AgvStatus agvStatus) { - if (agvStatus.getActionStatus()) { + private void handleActionStatus(AgvActionStatus agvActionStatus) { + if (agvActionStatus.getStatus()) { ACTION_STATUS = false; } } diff --git a/opentcs-common/src/main/java/org/opentcs/communication/http/service/ExecuteMove.java b/opentcs-common/src/main/java/org/opentcs/communication/http/service/ExecuteMove.java index c489189..940432c 100644 --- a/opentcs-common/src/main/java/org/opentcs/communication/http/service/ExecuteMove.java +++ b/opentcs-common/src/main/java/org/opentcs/communication/http/service/ExecuteMove.java @@ -71,12 +71,13 @@ public class ExecuteMove extends BaseService { } org.opentcs.data.model.Path pathInfo = cmd.getStep().getPath(); - int maxVelocity = 1; //获取最大速度 - int maxReverseVelocity = 1; //获取最大反向速度 + int maxVelocity = 5; //获取最大速度 + int maxReverseVelocity = 5; //获取最大反向速度 if (pathInfo != null) { maxVelocity = pathInfo.getMaxVelocity(); //获取设置速度 maxReverseVelocity = pathInfo.getMaxReverseVelocity(); } + maxVelocity = 5; RequestAe ae = new RequestAe(); ae.setWms_order_id(1); //todo 测试填写 @@ -111,7 +112,7 @@ public class ExecuteMove extends BaseService { path.setPath_id(pathID); path.setPath_serial(orderInfo.getPathSerialNum()); path.setPath_angle(0); - path.setDriver_pose(1); + path.setDriver_pose(0); path.setMax_speed(maxVelocity); path.setMax_angle_speed(maxVelocity); @@ -153,7 +154,7 @@ public class ExecuteMove extends BaseService { } else { //车辆不在集合中 OrderInfo orderInfo = new OrderInfo(); - orderInfo.setId(1); + orderInfo.setId(1); //todo 测试修改,正式上线应该为1 orderInfo.setName(orderName); orderInfo.setState(1); orderInfo.setTaskKey(1); diff --git a/opentcs-common/src/main/java/org/opentcs/manage/AdapterManage.java b/opentcs-common/src/main/java/org/opentcs/manage/AdapterManage.java index 86344f4..ffb250f 100644 --- a/opentcs-common/src/main/java/org/opentcs/manage/AdapterManage.java +++ b/opentcs-common/src/main/java/org/opentcs/manage/AdapterManage.java @@ -3,7 +3,6 @@ package org.opentcs.manage; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import java.util.Date; -import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -50,7 +49,7 @@ public class AdapterManage { * 记录通讯适配器数据,实现异步不阻塞更新车辆模型 * 基于线程安全HASHMAP */ - private static final ConcurrentHashMap adapterDataMap = new ConcurrentHashMap<>(); +// private static final ConcurrentHashMap adapterDataMap = new ConcurrentHashMap<>(); /** * 内核状态 */ @@ -74,69 +73,21 @@ public class AdapterManage { Runnable task = () -> { -// if (!kernelStatus) { -// return; -// } -// -// System.out.println("test-----start"); -// -// KernelServicePortal servicePortal = new KernelServicePortalBuilder(USER, PASSWORD).build(); -// servicePortal.login(IP, PORT); -// -// VehicleService vehicleService = servicePortal.getVehicleService(); -// Vehicle vehicle = vehicleService.fetchObject(Vehicle.class, "v2"); -// -// vehicleService.enableCommAdapter(vehicle.getReference()); -// -// servicePortal.logout(); -// -// System.out.println("test-----end"); - kernel = new KernelCommunication(USER, PASSWORD, IP, PORT); autoManageAdapterStatus(); - updateAdapterVehicleModel(); kernel.logout(); - }; /** * 自动管理通讯适配器 */ -// private static boolean autoManageAdapterStatus(String name) { -// Date date = new Date(); -// long currentTime = date.getTime(); -// -// System.out.println("autoManageAdapterStatus: " + adapterStatusMap); -// -// AgvStatus oldData = adapterStatusMap.get(name); -// -// if (oldData == null) { -// return false; -// } -// -// AgvStatus agvStatus = new AgvStatus(); -// agvStatus.setTime(oldData.getTime()); -// -// if (currentTime - oldData.getTime() > AUTO_CLOSE_TIME) { -// System.out.println("adapterStatusMap first DISABLE"); -// agvStatus.setStatus(AdapterStatus.DISABLE); -// } else { -// System.out.println("adapterStatusMap first ENABLE"); -// agvStatus.setStatus(AdapterStatus.ENABLE); -// } -// -// //更新记录数据 -// adapterStatusMap.put(name, agvStatus); -// -// return agvStatus.getStatus(); -// } private void autoManageAdapterStatus() { Date date = new Date(); long currentTime = date.getTime(); - System.out.println("autoManageAdapterStatus: " + adapterStatusMap); + System.out.println("autoManageAdapterStatus sout: " + adapterStatusMap); adapterStatusMap.forEach((key, value) -> { LOG.info("adapterStatusMap starts name: {}", key); @@ -144,52 +95,33 @@ public class AdapterManage { agvStatus.setTime(value.getTime()); if (currentTime - value.getTime() > AUTO_CLOSE_TIME) { - agvStatus.setStatus(AdapterStatus.DISABLE); + //当前时间减去记录时间大于阈值,自动关闭通讯适配器 kernel.disableAdapter(key); + agvStatus.setStatus(AdapterStatus.DISABLE); } else { - agvStatus.setStatus(AdapterStatus.ENABLE); + //通讯适配器当前状态为关闭,设置状态为开启时才会进入 kernel.enableAdapter(key); + agvStatus.setStatus(AdapterStatus.ENABLE); } - LOG.info("update the adapter: {} status:{}", key, value); - - if (value.getActionStatus()) { - kernel.sendToAdapter(key, agvStatus); - } - - //更新数据状态 - agvStatus.setActionStatus(false); + LOG.info("update the adapter: {} status: {}", key, value); //更新记录数据 adapterStatusMap.put(key, agvStatus); - System.out.println("adapterStatusMap end name: " + key); LOG.info("adapterStatusMap end name: {}", key); }); } - /** - * 更新适配器车辆模型 - */ - private void updateAdapterVehicleModel() { - adapterDataMap.forEach((key, value) -> { - System.out.println("updateAdapterVehicleModel name: " + key); - kernel.sendToAdapter(key, value); - adapterDataMap.remove(key); - }); - } - /** * 更新通讯适配器状态 * @param name 车辆名称 */ public static void setAdapterStatus(String name) { - Date date = new Date(); - long time = date.getTime(); - AgvStatus newAgvStatus = new AgvStatus(); - newAgvStatus.setTime(time); - newAgvStatus.setActionStatus(false); + + Date date = new Date(); + newAgvStatus.setTime(date.getTime()); if (!adapterStatusMap.isEmpty() && adapterStatusMap.containsKey(name)) { //已记录,只更新时间 @@ -202,38 +134,15 @@ public class AdapterManage { adapterStatusMap.put(name, newAgvStatus); } - public static boolean getAdapterStatus(String name) { - - AgvStatus agvStatus = adapterStatusMap.get(name); - if (agvStatus != null) { - return agvStatus.getStatus(); - } - - return false; - } - - /** - * 设置动作完成状态 - * @param name 车辆名称 - */ - public static void setActionStatus(String name) { - AgvStatus agvStatus = adapterStatusMap.get(name); - agvStatus.setActionStatus(true); - adapterStatusMap.put(name, agvStatus); - } - /** * 记录对应通讯适配器最后一次上报数据 * @param name 车辆名称 * @param data 数据 */ - public static void setAdapterVehicleModel(String name, String data) { + public static AgvInfo setAdapterVehicleModel(String name, String data) { JSONObject jsonObject = JSON.parseObject(data); - //校验通讯序列号 - - AgvInfo agvInfo = new AgvInfo(); agvInfo.setSender(jsonObject.getString("sender")); agvInfo.setReceiver(jsonObject.getString("receiver")); @@ -242,7 +151,8 @@ public class AdapterManage { agvInfo.setTime(jsonObject.getString("time")); agvInfo.setParams(getAgvInfoParams(jsonObject.getString("params"))); - adapterDataMap.put(name, agvInfo); +// adapterDataMap.put(name, agvInfo); + return agvInfo; } private static AgvInfoParams getAgvInfoParams(String paramsStr) { @@ -271,4 +181,44 @@ public class AdapterManage { Boolean ENABLE = true; Boolean DISABLE = false; } + +// private void testSendMessage() { +// System.out.println("test"); +// AgvInfoParams agvInfoParams = new AgvInfoParams(); +// agvInfoParams.setX(0.5f); +// agvInfoParams.setY(0.5f); +// agvInfoParams.setAngle(0.5f); +// agvInfoParams.setPoint(12); +// agvInfoParams.setPower(0.52f); +// agvInfoParams.setAgv_status(0); +// agvInfoParams.setCargo_status(0); +// agvInfoParams.setAgv_model(0); +// agvInfoParams.setCharge_status(0); +// agvInfoParams.setAction_status(1); +// +// AgvInfo agvInfo = new AgvInfo(); +// agvInfo.setReceiver("OPENTCS"); +// agvInfo.setSender("KC-CTRL"); +// agvInfo.setSerial_num(1); +// agvInfo.setType(1); +// agvInfo.setTime("2020-07-07 09:09:09"); +// agvInfo.setVehicle_name("v2"); +// agvInfo.setParams(agvInfoParams); +// +// System.out.println("testSendMessage agvInfo: " + agvInfo); +// +// KernelServicePortal servicePortal = new KernelServicePortalBuilder(USER, PASSWORD).build(); +// servicePortal.login(IP, PORT); +// VehicleService vehicleService = servicePortal.getVehicleService(); +// Vehicle vehicle = vehicleService.fetchObject(Vehicle.class, "v2"); +// +// if (vehicle != null) { +// System.out.println("send success"); +// vehicleService.sendCommAdapterMessage(vehicle.getReference(), agvInfo); +// } else { +// System.out.println("send not fund"); +// } +// +//// kernel.sendToAdapter("v2", agvInfo); +// } } diff --git a/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvActionStatus.java b/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvActionStatus.java new file mode 100644 index 0000000..59deb17 --- /dev/null +++ b/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvActionStatus.java @@ -0,0 +1,13 @@ +package org.opentcs.manage.entity; + +import lombok.Data; + +@Data +public class AgvActionStatus { + + /** + * 状态: true = 动作执行完成,false = 未知,不做处理 + */ + private Boolean status; + +} diff --git a/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvStatus.java b/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvStatus.java index 04f1e5f..607858e 100644 --- a/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvStatus.java +++ b/opentcs-common/src/main/java/org/opentcs/manage/entity/AgvStatus.java @@ -10,11 +10,7 @@ public class AgvStatus { */ private Long time; /** - * 通讯适配器状态:trye=开启,false=关闭 + * 通讯适配器修改状态:trye=开启,false=关闭 */ private Boolean status; - /** - * 动作执行状态:trye=执行完成,false=未知 - */ - private Boolean actionStatus; } diff --git a/opentcs-common/src/main/java/org/opentcs/util/KernelCommunication.java b/opentcs-common/src/main/java/org/opentcs/util/KernelCommunication.java index fea982b..2cc6526 100644 --- a/opentcs-common/src/main/java/org/opentcs/util/KernelCommunication.java +++ b/opentcs-common/src/main/java/org/opentcs/util/KernelCommunication.java @@ -23,7 +23,7 @@ public class KernelCommunication { } /** - * 通讯适配器通讯 + * 通讯适配器通讯------todo 测试发送数据失败,待修改。勿用!!!!! * @param name 车辆名称 * @param message 数据 */ @@ -35,6 +35,7 @@ public class KernelCommunication { } System.out.println("sendToAdapter: " + message); +// vehicleService.sendCommAdapterMessage(vehicle.getReference(), message); vehicleService.sendCommAdapterMessage(vehicle.getReference(), message); } diff --git a/opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/v1/VehicleHandler.java b/opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/v1/VehicleHandler.java index b66d37d..37a5953 100644 --- a/opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/v1/VehicleHandler.java +++ b/opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/v1/VehicleHandler.java @@ -37,6 +37,8 @@ import org.opentcs.kernel.extensions.servicewebapi.v1.binding.PostVehicleRoutesR import org.opentcs.kernel.extensions.servicewebapi.v1.binding.PutVehicleAllowedOrderTypesTO; import org.opentcs.kernel.extensions.servicewebapi.v1.binding.PutVehicleEnergyLevelThresholdSetTO; import org.opentcs.manage.AdapterManage; +import org.opentcs.manage.entity.AgvActionStatus; +import org.opentcs.manage.entity.AgvInfo; /** * Handles requests related to vehicles. @@ -69,7 +71,7 @@ public class VehicleHandler { * 接收平台异步回调处理 */ public void postReceiveCallback(Object data) { -// System.out.println("jsonObject-----ssss: " + data.toString()); + System.out.println("jsonObject-----ssss: " + data.toString()); //截取平台响应的字符串 String jsonStr = data.toString().split("=", 2)[1]; @@ -86,10 +88,13 @@ public class VehicleHandler { //将数据更新到线程安全的集合中,防止线程阻塞 AdapterManage.setAdapterStatus(name); if (type == 1) { //上报agv详细信息 - AdapterManage.setAdapterVehicleModel(name, jsonStr); + AgvInfo agvInfo = AdapterManage.setAdapterVehicleModel(name, jsonStr); + vehicleService.sendCommAdapterMessage(vehicle.getReference(), agvInfo); } else if (type == 5) { //上报动作完成 //动作完成上报 - AdapterManage.setActionStatus(name); + AgvActionStatus agvActionStatus = new AgvActionStatus(); + agvActionStatus.setStatus(true); + vehicleService.sendCommAdapterMessage(vehicle.getReference(), agvActionStatus); } }