feat: 重构视觉取料流程及生产故障恢复

- 删除订单启动、暂停、复位相关 PLC 握手及无效反馈配置
- 清除报警改为仅写 clearAlarmCommand,不等待反馈
- 将拍照位移动、视觉处理和 RackPick 拆分为三个独立动作
- 增加 M850/M851 拍照位动作及 R60/M852 视觉结果流程
- 暂停改为等待当前机器人动作完成,视觉结果不确定时转人工确认
- 删除复位按钮,合并为恢复/重试按钮
- 普通 PAUSED 订单通过启动按钮继续
- 恢复前检查 PLC、安全状态、订单及动作命令反馈
- 支持在途动作接管、已完成动作收尾、安全重试和人工确认
- 故障状态保持订单 RUNNING,并持久化实际恢复阶段
- 恢复成功后仅清除本次软件故障对应的报警
- 更新小轴 PLC 地址、Modbus 配置和视觉集成文档
This commit is contained in:
lidg
2026-10-29 17:20:14 +08:00
parent 31454722a0
commit 407af2892d
17 changed files with 839 additions and 929 deletions
+99 -218
View File
@@ -8,10 +8,9 @@
namespace {
const int FeedbackPollIntervalMs = 50;
bool actionAddresses(DeviceService::ProductionAction action,
const ModbusAddressMap &addresses,
const VisionConfig &vision,
int *commandAddress, int *feedbackAddress)
{
if (!commandAddress || !feedbackAddress) {
@@ -19,6 +18,10 @@ bool actionAddresses(DeviceService::ProductionAction action,
}
switch (action) {
case DeviceService::PhotoMoveAction:
*commandAddress = vision.photoMoveCoil;
*feedbackAddress = vision.photoMoveCoilFeedback;
return true;
case DeviceService::RackPick:
*commandAddress = addresses.rackPickCommand;
*feedbackAddress = addresses.rackPickFeedback;
@@ -70,8 +73,6 @@ DeviceService::DeviceService(QObject *parent)
, m_productionFeedbackAddress(-1)
, m_terminationActive(false)
, m_terminationSignalIndex(0)
, m_controlCommandAddress(-1)
, m_controlFeedbackAddress(-1)
{
connect(m_pollTimer, &QTimer::timeout,
this, &DeviceService::pollStatus);
@@ -349,84 +350,6 @@ DeviceStatus DeviceService::simulatedStatus() const
return status;
}
void DeviceService::start(const OperationCallback &callback)
{
if (m_terminationActive) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
if (ConfigManager::instance().simulationMode()) {
if (callback) {
callback(true, QString());
}
return;
}
if (!ConfigManager::instance().productionEnabled()) {
if (callback) {
callback(false, "Production control is disabled by configuration");
}
return;
}
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
executeCommand(addresses.startCommand, addresses.startFeedback, callback);
}
void DeviceService::pause(const OperationCallback &callback)
{
if (m_terminationActive) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
if (ConfigManager::instance().simulationMode()) {
if (callback) {
callback(true, QString());
}
return;
}
if (!ConfigManager::instance().productionEnabled()) {
if (callback) {
callback(false, "Production control is disabled by configuration");
}
return;
}
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
executeCommand(addresses.pauseCommand, addresses.pauseFeedback, callback);
}
void DeviceService::reset(const OperationCallback &callback)
{
if (m_terminationActive) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
if (ConfigManager::instance().simulationMode()) {
if (callback) {
callback(true, QString());
}
return;
}
if (!ConfigManager::instance().productionEnabled()) {
if (callback) {
callback(false, "Production control is disabled by configuration");
}
return;
}
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
executeCommand(addresses.resetCommand, addresses.resetFeedback, callback);
}
void DeviceService::clearAlarm(const OperationCallback &callback)
{
if (m_terminationActive) {
@@ -449,9 +372,22 @@ void DeviceService::clearAlarm(const OperationCallback &callback)
return;
}
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
executeCommand(addresses.clearAlarmCommand,
addresses.clearAlarmFeedback, callback);
if (m_controlRequestPending || m_productionActionBusy) {
if (callback) {
callback(false, "Another PLC operation is already active");
}
return;
}
m_controlRequestPending = true;
m_modbus->writeCoil(
m_modbus->config().addressMap.clearAlarmCommand, true,
[this, callback](bool success, const QString &error) {
m_controlRequestPending = false;
if (callback) {
callback(success, error);
}
});
}
void DeviceService::setInspectionMode(const QString &mode,
@@ -517,7 +453,6 @@ void DeviceService::terminate(const OperationCallback &callback)
m_pollTimer->stop();
const QList<QPair<int, int>> currentSignals = QList<QPair<int, int>>()
<< qMakePair(m_controlCommandAddress, m_controlFeedbackAddress)
<< qMakePair(m_productionCommandAddress,
m_productionFeedbackAddress);
for (const QPair<int, int> &signalPair : currentSignals) {
@@ -546,16 +481,7 @@ void DeviceService::clearNextTerminationSignal()
return;
}
if (m_terminationSignalIndex >= m_terminationSignals.size()) {
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
executeCommand(
addresses.pauseCommand, addresses.pauseFeedback,
[this](bool success, const QString &error) {
if (!success) {
finishTermination(false, error);
return;
}
finishTermination(true, QString());
}, true);
finishTermination(true, QString());
return;
}
@@ -587,8 +513,6 @@ void DeviceService::finishTermination(bool success, const QString &error)
m_productionActionActive = false;
m_productionActionBusy = false;
if (success) {
m_controlCommandAddress = -1;
m_controlFeedbackAddress = -1;
m_productionCommandAddress = -1;
m_productionFeedbackAddress = -1;
}
@@ -597,113 +521,6 @@ void DeviceService::finishTermination(bool success, const QString &error)
}
}
void DeviceService::executeCommand(int commandAddress, int feedbackAddress,
const OperationCallback &callback,
bool allowDuringTermination)
{
if (m_terminationActive && !allowDuringTermination) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
if (m_controlRequestPending || m_productionActionBusy) {
if (callback) {
callback(false, "Another PLC operation is already active");
}
return;
}
m_controlRequestPending = true;
m_controlCommandAddress = commandAddress;
m_controlFeedbackAddress = feedbackAddress;
writeCommandAndWaitFeedback(commandAddress, feedbackAddress,
[this, commandAddress, feedbackAddress,
callback](bool success,
const QString &error) {
m_controlRequestPending = false;
if (success
&& m_controlCommandAddress
== commandAddress
&& m_controlFeedbackAddress
== feedbackAddress) {
m_controlCommandAddress = -1;
m_controlFeedbackAddress = -1;
}
if (callback) {
callback(success, error);
}
}, allowDuringTermination);
}
void DeviceService::writeCommandAndWaitFeedback(
int commandAddress, int feedbackAddress,
const OperationCallback &callback, bool allowDuringTermination)
{
if (m_terminationActive && !allowDuringTermination) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
m_modbus->writeCoil(
commandAddress, true,
[this, commandAddress, feedbackAddress, callback,
allowDuringTermination](bool success,
const QString &error) {
if (!success) {
if (callback) {
callback(false, error);
}
return;
}
pollFeedback(commandAddress, feedbackAddress, callback,
allowDuringTermination);
});
}
void DeviceService::pollFeedback(int commandAddress, int feedbackAddress,
const OperationCallback &callback,
bool allowDuringTermination)
{
if (m_terminationActive && !allowDuringTermination) {
if (callback) {
callback(false, "PLC termination is in progress");
}
return;
}
m_modbus->readCoil(
feedbackAddress,
[this, commandAddress, feedbackAddress, callback,
allowDuringTermination](
bool success, bool feedback,
const QString &error) {
if (!success) {
if (callback) {
callback(false, error);
}
return;
}
if (!feedback) {
QTimer::singleShot(
FeedbackPollIntervalMs, this,
[this, commandAddress, feedbackAddress, callback,
allowDuringTermination]() {
pollFeedback(commandAddress, feedbackAddress, callback,
allowDuringTermination);
});
return;
}
clearSignals(commandAddress, feedbackAddress,
[callback](bool cleared, const QString &clearError) {
if (callback) {
callback(cleared, clearError);
}
});
});
}
void DeviceService::beginProductionAction(
ProductionAction action, int trayNo, int slotNo,
const OperationCallback &callback, const std::function<bool()> &beforeSend)
@@ -740,7 +557,8 @@ void DeviceService::beginProductionAction(
}
const ModbusAddressMap &addresses = m_modbus->config().addressMap;
if (!actionAddresses(action, addresses,
const VisionConfig vision = ConfigManager::instance().visionConfig();
if (!actionAddresses(action, addresses, vision,
&m_productionCommandAddress,
&m_productionFeedbackAddress)) {
if (callback) {
@@ -750,10 +568,11 @@ void DeviceService::beginProductionAction(
}
m_productionActionBusy = true;
m_modbus->readCoil(
m_productionFeedbackAddress,
inspectProductionAction(
action,
[this, action, trayNo, slotNo, addresses, callback, beforeSend](
bool success, bool feedback, const QString &error) {
bool success, const ProductionActionStatus &status,
const QString &error) {
if (!success) {
m_productionActionBusy = false;
if (callback) {
@@ -761,11 +580,11 @@ void DeviceService::beginProductionAction(
}
return;
}
if (feedback) {
if (status.command || status.feedback) {
m_productionActionBusy = false;
if (callback) {
callback(false,
"PLC feedback is still active before a new action");
"PLC command or feedback is still active before a new action");
}
return;
}
@@ -803,7 +622,8 @@ void DeviceService::beginProductionAction(
}
};
if (action == RackPick || action == RackPlace) {
if (action == PhotoMoveAction || action == RackPick
|| action == RackPlace) {
m_modbus->writeHoldingRegister(
addresses.trayNumber,
static_cast<quint16>(trayNo),
@@ -825,6 +645,67 @@ void DeviceService::beginProductionAction(
});
}
void DeviceService::inspectProductionAction(
ProductionAction action, const ActionStatusCallback &callback)
{
ProductionActionStatus emptyStatus;
if (m_terminationActive) {
if (callback) callback(false, emptyStatus,
"PLC termination is in progress");
return;
}
if (ConfigManager::instance().simulationMode()) {
if (callback) callback(true, emptyStatus, QString());
return;
}
int commandAddress = -1;
int feedbackAddress = -1;
if (!actionAddresses(action, m_modbus->config().addressMap,
ConfigManager::instance().visionConfig(),
&commandAddress, &feedbackAddress)) {
if (callback) callback(false, emptyStatus,
"Unknown PLC production action");
return;
}
m_modbus->readCoil(
commandAddress,
[this, feedbackAddress, callback](bool commandRead, bool command,
const QString &commandError) {
if (!commandRead) {
if (callback) callback(false, ProductionActionStatus(),
commandError);
return;
}
m_modbus->readCoil(
feedbackAddress,
[callback, command](bool feedbackRead, bool feedback,
const QString &feedbackError) {
ProductionActionStatus status;
status.command = command;
status.feedback = feedback;
if (callback) callback(feedbackRead, status,
feedbackError);
});
});
}
void DeviceService::adoptProductionAction(ProductionAction action)
{
int commandAddress = -1;
int feedbackAddress = -1;
if (m_productionActionBusy
|| !actionAddresses(action, m_modbus->config().addressMap,
ConfigManager::instance().visionConfig(),
&commandAddress, &feedbackAddress)) {
return;
}
m_productionCommandAddress = commandAddress;
m_productionFeedbackAddress = feedbackAddress;
m_productionActionActive = true;
}
void DeviceService::pollProductionAction(const ActionCallback &callback)
{
if (m_terminationActive) {
@@ -1069,7 +950,7 @@ void DeviceService::readVisionHandshake(const HandshakeCallback &callback)
return;
}
const VisionConfig config = ConfigManager::instance().visionConfig();
if (config.photoArrivedCoil == config.photoMoveCoil + 1
if (config.photoMoveCoilFeedback == config.photoMoveCoil + 1
&& config.comparisonPickCoil == config.photoMoveCoil + 2) {
const quint64 generation = m_visionGeneration;
m_modbus->readCoils(config.photoMoveCoil, 3,
@@ -1077,7 +958,7 @@ void DeviceService::readVisionHandshake(const HandshakeCallback &callback)
VisionHandshake state;
if (success && values.size() == 3 && generation == m_visionGeneration) {
state.photoMove = values.at(0);
state.photoArrived = values.at(1);
state.photoMoveFeedback = values.at(1);
state.comparisonPick = values.at(2);
if (callback) callback(true, state, QString());
} else if (callback) {
@@ -1101,7 +982,7 @@ void DeviceService::readVisionHandshakeStep(int index, const VisionHandshake &st
return;
}
const VisionConfig config = ConfigManager::instance().visionConfig();
const int addresses[] = {config.photoMoveCoil, config.photoArrivedCoil, config.comparisonPickCoil};
const int addresses[] = {config.photoMoveCoil, config.photoMoveCoilFeedback, config.comparisonPickCoil};
m_modbus->readVisionCoil(addresses[index],
[this, index, state, generation, callback](bool success, bool value, const QString &error) {
if (!success) {
@@ -1111,7 +992,7 @@ void DeviceService::readVisionHandshakeStep(int index, const VisionHandshake &st
VisionHandshake next = state;
switch (index) {
case 0: next.photoMove = value; break;
case 1: next.photoArrived = value; break;
case 1: next.photoMoveFeedback = value; break;
case 2: next.comparisonPick = value; break;
}
readVisionHandshakeStep(index + 1, next, generation, callback);
@@ -1131,8 +1012,8 @@ void DeviceService::writeVisionSignal(VisionSignal signal, bool value,
int address = -1;
switch (signal) {
case PhotoMove: address = config.photoMoveCoil; break;
case PhotoArrived:
if (!value) address = config.photoArrivedCoil; // Only PLC may publish arrival.
case PhotoMoveFeedback:
if (!value) address = config.photoMoveCoilFeedback; // Only PLC may publish arrival.
break;
case ComparisonPick: address = config.comparisonPickCoil; break;
default: break;