This commit is contained in:
xuzhiheng
2025-06-09 10:34:24 +08:00
parent 503771fe7c
commit 2cc6f2906b
49 changed files with 1471 additions and 514 deletions

View File

@@ -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.ActionStatus;
import org.opentcs.manage.entity.AgvInfo;
import org.opentcs.manage.entity.AgvInfoParams;
import org.opentcs.manage.entity.AgvStatus;
@@ -106,6 +107,10 @@ public class LoopbackCommunicationAdapter
* 记录当前车辆位置
*/
private static String CURRENT_POS;
/**
* 订单任务key
*/
private int TASK_KEY = 1;
/**
* Creates a new instance.
@@ -212,6 +217,7 @@ public class LoopbackCommunicationAdapter
if (isEnabled()) {
return;
}
LOG.info("Loopback comm adapter is being enabled: {}", getName());
super.enable();
}
@@ -220,6 +226,7 @@ public class LoopbackCommunicationAdapter
if (!isEnabled()) {
return;
}
LOG.info("Loopback comm adapter is being disable: {}", getName());
super.disable();
}
@@ -232,12 +239,13 @@ public class LoopbackCommunicationAdapter
public synchronized void sendCommand(MovementCommand cmd) {
requireNonNull(cmd, "cmd");
//下发起点
String sourcePoint = null;
if (cmd.getStep().getSourcePoint() != null) {
//下发起点不为空
sourcePoint = cmd.getStep().getSourcePoint().getName();
//下发AGV移动指令
ExecuteMove.sendCmd(cmd, getSerialNum());
ExecuteMove.sendCmd(getProcessModel().getName(), cmd, getSerialNum());
}
// Start the simulation task if we're not in single step mode and not simulating already.
@@ -249,6 +257,8 @@ public class LoopbackCommunicationAdapter
ORDER_NAME = cmd.getTransportOrder().getName();
//下发起点
CURRENT_POS = sourcePoint;
//当前执行taskKey
TASK_KEY = 1;
// The command is added to the sent queue after this method returns. Therefore
// we have to explicitly start the simulation like this.
@@ -275,9 +285,9 @@ public class LoopbackCommunicationAdapter
if (message instanceof AgvInfo agvInfo) {
//通讯适配器车辆模型更新
handleCallbacks(agvInfo.getParams());
} else if (message instanceof AgvStatus agvStatus) {
} else if (message instanceof ActionStatus actionStatus) {
//自动管理通讯适配器状态和适配器动作执行状态
handleAdapterAuthEnable(agvStatus);
handleActionStatus(actionStatus);
}
}
@@ -385,12 +395,14 @@ public class LoopbackCommunicationAdapter
*/
private void startVehicleExec(MovementCommand command) {
LOG.debug("VEHICLE: {} BEGINS TO EXECUTE THE COMMAND: {}", getProcessModel().getName(),command);
Step step = command.getStep();
getProcessModel().setState(Vehicle.State.EXECUTING);
Step step = command.getStep();
if (step.getPath() == null) {
actionExec(command);
} else {
ExecuteMove.setExecTaskKey(getProcessModel().getName(), TASK_KEY);
TASK_KEY++;
//todo 移动
movementExec(command);
}
@@ -418,7 +430,7 @@ public class LoopbackCommunicationAdapter
ACTION_STATUS = true;
//下发动作
ExecuteAction.sendCmd(command.getOperation(), getSerialNum());
ExecuteAction.sendCmd(getProcessModel().getName(), command.getOperation(), getSerialNum());
// 结束动作
finishCmd(command);
@@ -769,7 +781,7 @@ public class LoopbackCommunicationAdapter
if (!Objects.equals(getProcessModel().getPosition(), params.getPoint().toString())) {
getProcessModel().setPosition(params.getPoint().toString()); //更新最终经过点
}
getProcessModel().setPose(new Pose(new Triple(Math.round(params.getX()), Math.round(params.getY()), 0), params.getAngle()));
getProcessModel().setPose(new Pose(new Triple(Math.round(params.getX() * 1000), Math.round(params.getY() * 1000), 0), params.getAngle()));
} else {
//最后经过点为0应该是车辆重启过。车辆关机时应该正常对点位进行交管防止车辆碰撞。
//todo 可能需要实现原点自动定位,暂时不做处理
@@ -793,15 +805,9 @@ public class LoopbackCommunicationAdapter
return serialNum;
}
private void handleAdapterAuthEnable(AgvStatus agvStatus) {
if (agvStatus.getActionStatus()) {
private void handleActionStatus(ActionStatus actionStatus) {
if (actionStatus.getStatus()) {
ACTION_STATUS = false;
}
if (agvStatus.getStatus()) {
enable();
} else {
disable();
}
}
}