update
This commit is contained in:
parent
f2241efc68
commit
c07ca22d29
@ -27,6 +27,7 @@ import org.opentcs.communication.http.service.ExecuteAction;
|
||||
import org.opentcs.communication.http.service.ExecuteMove;
|
||||
import org.opentcs.communication.http.service.ExecuteOperation;
|
||||
import org.opentcs.components.kernel.Router;
|
||||
import org.opentcs.components.kernel.services.DispatcherService;
|
||||
import org.opentcs.components.kernel.services.TCSObjectService;
|
||||
import org.opentcs.components.kernel.services.TransportOrderService;
|
||||
import org.opentcs.components.kernel.services.VehicleService;
|
||||
@ -41,6 +42,7 @@ import org.opentcs.data.model.TCSResourceReference;
|
||||
import org.opentcs.data.model.Triple;
|
||||
import org.opentcs.data.model.Vehicle;
|
||||
import org.opentcs.data.order.DriveOrder;
|
||||
import org.opentcs.data.order.ReroutingType;
|
||||
import org.opentcs.data.order.Route;
|
||||
import org.opentcs.data.order.Route.Step;
|
||||
import org.opentcs.data.order.TransportOrder;
|
||||
@ -162,11 +164,14 @@ public class LoopbackCommunicationAdapter
|
||||
|
||||
private final Router router;
|
||||
|
||||
private final DispatcherService dispatcherService;
|
||||
|
||||
//标记是否开启自动回休息点:true=开启,false=关闭
|
||||
private final Boolean IS_AUTOMATIC_BREAKS = true;
|
||||
|
||||
//连接状态
|
||||
private final Boolean CONNECT_STATUS = false;
|
||||
private final Boolean CONNECT_STATUS = true;
|
||||
//AGV模式:待机 = 0,手动 = 1,半自动 = 2,自动 = 3,示教 = 4,服务 = 5(升级程序中的工作,状态),维修 = 6
|
||||
private Integer AGV_MODEL;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
@ -185,7 +190,8 @@ public class LoopbackCommunicationAdapter
|
||||
TCSObjectService objectService, // 注入对象服务
|
||||
VehicleService vehicleService,
|
||||
TransportOrderService transportOrderService,
|
||||
Router router
|
||||
Router router,
|
||||
DispatcherService dispatcherService
|
||||
) {
|
||||
super(
|
||||
new LoopbackVehicleModel(vehicle),
|
||||
@ -199,6 +205,7 @@ public class LoopbackCommunicationAdapter
|
||||
this.vehicleService = requireNonNull(vehicleService, "vehicleService");
|
||||
this.transportOrderService = requireNonNull(transportOrderService, "transportOrderService");
|
||||
this.router = requireNonNull(router, "router");
|
||||
this.dispatcherService = requireNonNull(dispatcherService, "dispatcherService");
|
||||
|
||||
// 初始化充电策略管理器
|
||||
this.chargingStrategyManager = new ChargingStrategyManager();
|
||||
@ -571,7 +578,7 @@ public class LoopbackCommunicationAdapter
|
||||
|
||||
String currentPosition = getProcessModel().getPosition();
|
||||
if (currentPosition != null && currentPosition.equals(CURRENT_POS)) {
|
||||
LOG.info("车辆: {} ,实际位置: {} ,记录位置: {}", vehicle.getName(), currentPosition, CURRENT_POS);
|
||||
// LOG.info("车辆: {} ,实际位置: {} ,记录位置: {}", vehicle.getName(), currentPosition, CURRENT_POS);
|
||||
getExecutor().schedule(
|
||||
() -> movementExec(command),
|
||||
500,
|
||||
@ -591,7 +598,7 @@ public class LoopbackCommunicationAdapter
|
||||
|
||||
private void finishCmd(MovementCommand command) {
|
||||
if (Objects.equals(getSentCommands().peek(), command)) {
|
||||
LOG.info("车辆: {} ,订单: {} ,命令: {} 结束", vehicle.getName(), command.getTransportOrder().getName(), command);
|
||||
// LOG.info("车辆: {} ,订单: {} ,命令: {} 结束", vehicle.getName(), command.getTransportOrder().getName(), command);
|
||||
//清理任务队列
|
||||
getProcessModel().commandExecuted(requireNonNull(getSentCommands().poll()));
|
||||
} else {
|
||||
@ -601,8 +608,9 @@ public class LoopbackCommunicationAdapter
|
||||
|
||||
private void nextCmd() {
|
||||
if (getSentCommands().isEmpty() && getUnsentCommands().isEmpty() || getProcessModel().isSingleStepModeEnabled()) {
|
||||
LOG.info("Vehicle: {} ,order: {} is done", vehicle.getName(), ORDER_NAME);
|
||||
// LOG.info("Vehicle: {} ,order: {} is done", vehicle.getName(), ORDER_NAME);
|
||||
isSimulationRunning = false;
|
||||
getProcessModel().setState(Vehicle.State.IDLE);
|
||||
} else {
|
||||
LOG.info("Vehicle: {} ,order: {} exec next command: {}", vehicle.getName(), ORDER_NAME, getSentCommands().peek());
|
||||
((ExecutorService) getExecutor()).submit(
|
||||
@ -864,12 +872,23 @@ public class LoopbackCommunicationAdapter
|
||||
//记录车辆最终状态
|
||||
Vehicle.State vehicleState;
|
||||
|
||||
Integer oldModel = AGV_MODEL;
|
||||
AGV_MODEL = params.getAgv_model();
|
||||
switch (params.getAgv_model()) {
|
||||
case 3 -> integrationLevel = Vehicle.IntegrationLevel.TO_BE_UTILIZED;
|
||||
case 6 -> integrationLevel = Vehicle.IntegrationLevel.TO_BE_IGNORED;
|
||||
default -> integrationLevel = Vehicle.IntegrationLevel.TO_BE_RESPECTED;
|
||||
}
|
||||
|
||||
if (AGV_MODEL == 1) { //AGV状态切为手动,执行控制器任务撤销
|
||||
ExecuteOperation.cancelOrder(vehicle.getName());
|
||||
}
|
||||
|
||||
if (oldModel != null && oldModel != 3 && AGV_MODEL == 3) {
|
||||
//车辆原本模式不为自动,切换为自动时需要重新路由。
|
||||
dispatcherService.reroute(vehicle.getReference(), ReroutingType.FORCED);
|
||||
}
|
||||
|
||||
//更新车辆状态
|
||||
if (params.getCharge_status() == 1) {
|
||||
vehicleState = Vehicle.State.CHARGING;
|
||||
@ -946,10 +965,12 @@ public class LoopbackCommunicationAdapter
|
||||
* @param agvActionStatus 车辆动作执行状态对象
|
||||
*/
|
||||
private void handleActionStatus(AgvActionStatus agvActionStatus) {
|
||||
LOG.info("handleActionStatus: {}", agvActionStatus.getStatus());
|
||||
if (agvActionStatus.getStatus()) {
|
||||
// System.out.println("handleActionStatus: ======");
|
||||
ACTION_STATUS = false;
|
||||
}
|
||||
LOG.info("handleActionStatus ACTION_STATUS: {}", ACTION_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ public class ExecuteOperation extends BaseService{
|
||||
String time = now.format(formatter);
|
||||
|
||||
// RequestB2 b2 = buildCommand(operation, orderId, taskKey);
|
||||
BaseRequestTo baseRequestTo = new BaseRequestTo(2, "OPENTCS", "KC-CTRL", serialNum, time, data);
|
||||
BaseRequestTo baseRequestTo = new BaseRequestTo(3, "OPENTCS", "KC-CTRL", serialNum, time, data);
|
||||
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.sendCommand(url, baseRequestTo);
|
||||
|
@ -296,6 +296,19 @@ public class V1RequestHandler
|
||||
// return jsonBinder.toJson("");
|
||||
}
|
||||
|
||||
// private Object handlePostAgvTaskWithdrawal(Request request, Response response)
|
||||
// throws KernelRuntimeException {
|
||||
//
|
||||
// response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8);
|
||||
//
|
||||
// //可能会有动作阻塞,所以需要初始化动作状态
|
||||
// vehicleHandler.initActionStatus(request.params(":NAME"));
|
||||
// //重新路由,需要清理车辆映射订单ID
|
||||
// ExecuteMove.resetOrder(request.params(":NAME"));
|
||||
//
|
||||
// return jsonBinder.toJson("");
|
||||
// }
|
||||
|
||||
private Object handlePostDispatcherTrigger(Request request, Response response)
|
||||
throws KernelRuntimeException {
|
||||
response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8);
|
||||
@ -452,8 +465,7 @@ public class V1RequestHandler
|
||||
|
||||
private Object handlePostWithdrawalByVehicle(Request request, Response response)
|
||||
throws ObjectUnknownException {
|
||||
|
||||
//初始化动作状态
|
||||
//初始化动作执行状态
|
||||
vehicleHandler.initActionStatus(request.params(":NAME"));
|
||||
|
||||
//根据车辆撤销任务
|
||||
@ -463,7 +475,7 @@ public class V1RequestHandler
|
||||
disableVehicle(request)
|
||||
);
|
||||
response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8);
|
||||
return "";
|
||||
return jsonBinder.toJson("");
|
||||
}
|
||||
|
||||
private Object handlePostPeripheralJobWithdrawal(Request request, Response response)
|
||||
@ -475,19 +487,13 @@ public class V1RequestHandler
|
||||
|
||||
private Object handlePostVehicleRerouteRequest(Request request, Response response)
|
||||
throws ObjectUnknownException {
|
||||
//清理车辆映射订单ID
|
||||
ExecuteMove.resetOrder(request.params(":NAME"));
|
||||
|
||||
//可能会有动作阻塞,所以需要初始化动作状态
|
||||
//初始化动作执行状态
|
||||
vehicleHandler.initActionStatus(request.params(":NAME"));
|
||||
|
||||
//撤销订单 todo 订单撤销后可能会有延时继续运动,所以应该考虑是否需要等待订单撤销成功
|
||||
// ExecuteOperation.cancelOrder(request.params(":NAME"));
|
||||
|
||||
//立即重新路由
|
||||
orderDispatcherHandler.reroute(request.params(":NAME"), forced(request));
|
||||
response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8);
|
||||
return "";
|
||||
return jsonBinder.toJson("");
|
||||
}
|
||||
|
||||
private Object handleGetTransportOrders(Request request, Response response) {
|
||||
|
@ -15,6 +15,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.opentcs.communication.http.service.ExecuteOperation;
|
||||
import org.opentcs.components.kernel.services.RouterService;
|
||||
import org.opentcs.components.kernel.services.VehicleService;
|
||||
import org.opentcs.data.ObjectUnknownException;
|
||||
@ -109,14 +110,37 @@ public class VehicleHandler {
|
||||
AgvInfo agvInfo = AdapterManage.setAdapterVehicleModel(name, jsonStr);
|
||||
vehicleService.sendCommAdapterMessage(vehicle.getReference(), agvInfo);
|
||||
} else if (type == 5) { //上报动作完成
|
||||
//动作完成上报
|
||||
//动作完成,初始化动作状态
|
||||
initActionStatus(name);
|
||||
// AgvActionStatus agvActionStatus = new AgvActionStatus();
|
||||
// agvActionStatus.setStatus(true);
|
||||
// vehicleService.sendCommAdapterMessage(vehicle.getReference(), agvActionStatus);
|
||||
} else if (type == 6) { //撤销任务
|
||||
//可能会卡动作,先初始化动作
|
||||
initActionStatus(name);
|
||||
//撤销agv控制器中的运动订单
|
||||
ExecuteOperation.cancelOrder(name);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 撤销已下发的AGV任务
|
||||
// */
|
||||
// public void postAgvTaskWithdrawal(Object data) {
|
||||
// String jsonStr;
|
||||
// try {
|
||||
// jsonStr = data.toString().split("=", 2)[1];
|
||||
// } catch (Exception e) {
|
||||
// jsonStr = data.toString();
|
||||
// }
|
||||
// JSONObject jsonObject = JSON.parseObject(jsonStr);
|
||||
// String name = jsonObject.getString("vehicle_name");
|
||||
// Integer type = jsonObject.getInteger("type");
|
||||
//
|
||||
// //可能会卡动作,先初始化动作
|
||||
// initActionStatus(name);
|
||||
//
|
||||
// //撤销agv控制器中的运动订单
|
||||
// ExecuteOperation.cancelOrder(name);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 初始化动作完成状态
|
||||
* @param name 车辆名称
|
||||
|
@ -358,6 +358,7 @@ public class TransportOrderUtil
|
||||
|
||||
//撤销订单,获取订单状态
|
||||
TransportOrder.State state = order.getState();
|
||||
LOG.info("车辆: {}: 正在中止订单: {} 订单状态: {}...", vehicle.getName(), order.getName(), order.getState());
|
||||
if (state == TransportOrder.State.BEING_PROCESSED) {
|
||||
//订单执行中,需要撤销下发给控制器的任务
|
||||
ExecuteOperation.cancelOrder(vehicle.getName());
|
||||
|
Loading…
Reference in New Issue
Block a user