feat(vision): 新增拍照到位前置流程并支持视觉失败降级取料
- 在普通 RackPick 前写托盘号、格位并置 M850,收到 M851 后清除两位 - 使用 vision/enabled 控制识别,关闭时仍执行拍照到位流程 - 识别成功且 R60 写入确认后写 M852=1,视觉关闭或失败时写 M852=0 - 确认 M852 写入后启动 RackPick,动作结束保留 M852 - 移除旧 850–854 五信号握手,更新配置和协议文档 - 允许未就绪的视觉服务接收测量,扩展超时以覆盖初始化重试 - 保留 PLC 写入失败阻断、暂停发送门控及迟到结果拒绝 - 持久化未完成事务,支持 PLC 暂停后的视觉维护与人工恢复 验证:MinGW 32/64 位编译通过;生产流程47、IPC14、PLC11项测试通过
This commit is contained in:
+58
-31
@@ -706,7 +706,7 @@ void DeviceService::pollFeedback(int commandAddress, int feedbackAddress,
|
||||
|
||||
void DeviceService::beginProductionAction(
|
||||
ProductionAction action, int trayNo, int slotNo,
|
||||
const OperationCallback &callback)
|
||||
const OperationCallback &callback, const std::function<bool()> &beforeSend)
|
||||
{
|
||||
if (m_terminationActive) {
|
||||
if (callback) {
|
||||
@@ -752,7 +752,7 @@ void DeviceService::beginProductionAction(
|
||||
m_productionActionBusy = true;
|
||||
m_modbus->readCoil(
|
||||
m_productionFeedbackAddress,
|
||||
[this, action, trayNo, slotNo, addresses, callback](
|
||||
[this, action, trayNo, slotNo, addresses, callback, beforeSend](
|
||||
bool success, bool feedback, const QString &error) {
|
||||
if (!success) {
|
||||
m_productionActionBusy = false;
|
||||
@@ -787,14 +787,20 @@ void DeviceService::beginProductionAction(
|
||||
}
|
||||
};
|
||||
|
||||
auto writeCommand = [this, sendCommand](bool success,
|
||||
auto writeCommand = [this, sendCommand, beforeSend](bool success,
|
||||
const QString &error) {
|
||||
if (!success) {
|
||||
sendCommand(false, error);
|
||||
return;
|
||||
}
|
||||
m_modbus->writeCoil(
|
||||
m_productionCommandAddress, true, sendCommand);
|
||||
if (beforeSend) {
|
||||
m_modbus->writeVisionCoil(m_productionCommandAddress, true,
|
||||
[sendCommand](VisionWriteOutcome outcome, const QString &error) {
|
||||
sendCommand(outcome == VisionWriteOutcome::Confirmed, error);
|
||||
}, beforeSend);
|
||||
} else {
|
||||
m_modbus->writeCoil(m_productionCommandAddress, true, sendCommand);
|
||||
}
|
||||
};
|
||||
|
||||
if (action == RackPick || action == RackPlace) {
|
||||
@@ -980,6 +986,34 @@ bool DeviceService::checkVisionAccess(QString *error) const
|
||||
return ConfigManager::instance().visionConfig().isValid(error);
|
||||
}
|
||||
|
||||
void DeviceService::moveToPhotoPosition(int trayNo, int slotNo,
|
||||
const VisionWriteCallback &callback,
|
||||
const std::function<bool()> &beforeSend)
|
||||
{
|
||||
QString error;
|
||||
if (!checkVisionAccess(&error) || trayNo < 1 || trayNo > 65535 || slotNo < 1 || slotNo > 49) {
|
||||
if (callback) callback(VisionWriteOutcome::NotSent,
|
||||
error.isEmpty() ? "Invalid photo-position tray/slot" : error);
|
||||
return;
|
||||
}
|
||||
const ModbusAddressMap addresses = m_modbus->config().addressMap;
|
||||
m_modbus->writeVisionHoldingRegister(addresses.trayNumber, quint16(trayNo),
|
||||
[this, addresses, slotNo, callback, beforeSend](VisionWriteOutcome outcome, const QString &error) {
|
||||
if (outcome != VisionWriteOutcome::Confirmed) {
|
||||
if (callback) callback(outcome, error);
|
||||
return;
|
||||
}
|
||||
m_modbus->writeVisionHoldingRegister(addresses.slotNumber, quint16(slotNo),
|
||||
[this, callback, beforeSend](VisionWriteOutcome outcome, const QString &error) {
|
||||
if (outcome != VisionWriteOutcome::Confirmed) {
|
||||
if (callback) callback(outcome, error);
|
||||
return;
|
||||
}
|
||||
writeVisionSignal(PhotoMove, true, callback, beforeSend);
|
||||
}, beforeSend);
|
||||
}, beforeSend);
|
||||
}
|
||||
|
||||
void DeviceService::readRobotPhotoPose(const PoseCallback &callback)
|
||||
{
|
||||
QString error;
|
||||
@@ -1035,20 +1069,16 @@ void DeviceService::readVisionHandshake(const HandshakeCallback &callback)
|
||||
return;
|
||||
}
|
||||
const VisionConfig config = ConfigManager::instance().visionConfig();
|
||||
if (config.photoRequestCoil == config.robotReceivedCoil + 1
|
||||
&& config.comparingCoil == config.robotReceivedCoil + 2
|
||||
&& config.comparisonErrorCoil == config.robotReceivedCoil + 3
|
||||
&& config.comparisonPassedCoil == config.robotReceivedCoil + 4) {
|
||||
if (config.photoArrivedCoil == config.photoMoveCoil + 1
|
||||
&& config.comparisonPickCoil == config.photoMoveCoil + 2) {
|
||||
const quint64 generation = m_visionGeneration;
|
||||
m_modbus->readCoils(config.robotReceivedCoil, 5,
|
||||
m_modbus->readCoils(config.photoMoveCoil, 3,
|
||||
[this, callback, generation](bool success, const QVector<bool> &values, const QString &text) {
|
||||
VisionHandshake state;
|
||||
if (success && values.size() == 5 && generation == m_visionGeneration) {
|
||||
state.robotReceived = values.at(0);
|
||||
state.photoRequest = values.at(1);
|
||||
state.comparing = values.at(2);
|
||||
state.comparisonError = values.at(3);
|
||||
state.comparisonPassed = values.at(4);
|
||||
if (success && values.size() == 3 && generation == m_visionGeneration) {
|
||||
state.photoMove = values.at(0);
|
||||
state.photoArrived = values.at(1);
|
||||
state.comparisonPick = values.at(2);
|
||||
if (callback) callback(true, state, QString());
|
||||
} else if (callback) {
|
||||
callback(false, state, text.isEmpty() ? "Vision handshake read canceled or incomplete" : text);
|
||||
@@ -1066,14 +1096,12 @@ void DeviceService::readVisionHandshakeStep(int index, const VisionHandshake &st
|
||||
if (callback) callback(false, VisionHandshake(), "Vision handshake read canceled");
|
||||
return;
|
||||
}
|
||||
if (index == 5) {
|
||||
if (index == 3) {
|
||||
if (callback) callback(true, state, QString());
|
||||
return;
|
||||
}
|
||||
const VisionConfig config = ConfigManager::instance().visionConfig();
|
||||
const int addresses[] = {config.robotReceivedCoil, config.photoRequestCoil,
|
||||
config.comparingCoil, config.comparisonErrorCoil,
|
||||
config.comparisonPassedCoil};
|
||||
const int addresses[] = {config.photoMoveCoil, config.photoArrivedCoil, config.comparisonPickCoil};
|
||||
m_modbus->readVisionCoil(addresses[index],
|
||||
[this, index, state, generation, callback](bool success, bool value, const QString &error) {
|
||||
if (!success) {
|
||||
@@ -1082,11 +1110,9 @@ void DeviceService::readVisionHandshakeStep(int index, const VisionHandshake &st
|
||||
}
|
||||
VisionHandshake next = state;
|
||||
switch (index) {
|
||||
case 0: next.robotReceived = value; break;
|
||||
case 1: next.photoRequest = value; break;
|
||||
case 2: next.comparing = value; break;
|
||||
case 3: next.comparisonError = value; break;
|
||||
case 4: next.comparisonPassed = value; break;
|
||||
case 0: next.photoMove = value; break;
|
||||
case 1: next.photoArrived = value; break;
|
||||
case 2: next.comparisonPick = value; break;
|
||||
}
|
||||
readVisionHandshakeStep(index + 1, next, generation, callback);
|
||||
});
|
||||
@@ -1103,15 +1129,16 @@ void DeviceService::writeVisionSignal(VisionSignal signal, bool value,
|
||||
}
|
||||
const VisionConfig config = ConfigManager::instance().visionConfig();
|
||||
int address = -1;
|
||||
QString name;
|
||||
switch (signal) {
|
||||
case Comparing: address = config.comparingCoil; name = "comparing"; break;
|
||||
case ComparisonError: address = config.comparisonErrorCoil; name = "comparisonError"; break;
|
||||
case ComparisonPassed: address = config.comparisonPassedCoil; name = "comparisonPassed"; break;
|
||||
case PhotoMove: address = config.photoMoveCoil; break;
|
||||
case PhotoArrived:
|
||||
if (!value) address = config.photoArrivedCoil; // Only PLC may publish arrival.
|
||||
break;
|
||||
case ComparisonPick: address = config.comparisonPickCoil; break;
|
||||
default: break;
|
||||
}
|
||||
if (address < 0 || !config.writableSignals.contains(name)) {
|
||||
if (callback) callback(VisionWriteOutcome::NotSent, "Vision coil is not owned by ssp");
|
||||
if (address < 0) {
|
||||
if (callback) callback(VisionWriteOutcome::NotSent, "Unsupported photo-position output");
|
||||
return;
|
||||
}
|
||||
m_modbus->writeVisionCoil(address, value, callback, beforeSend);
|
||||
|
||||
Reference in New Issue
Block a user