diff --git a/CmvrControlStation.pro b/CmvrControlStation.pro index d2633e4..85e1624 100644 --- a/CmvrControlStation.pro +++ b/CmvrControlStation.pro @@ -245,6 +245,8 @@ SOURCES += \ src/quictestserver.cpp \ src/rpcservicewidget.cpp \ src/robotclient.cpp \ + src/tactileheatmapwidget.cpp \ + src/jointfloweditor.cpp \ src/trendwidget.cpp \ src/urdfviewerwidget.cpp \ src/videodecoder.cpp \ @@ -258,6 +260,8 @@ HEADERS += \ src/quictestserver.h \ src/rpcservicewidget.h \ src/robotclient.h \ + src/tactileheatmapwidget.h \ + src/jointfloweditor.h \ src/trendwidget.h \ src/uiicons.h \ src/urdfviewerwidget.h \ diff --git a/protos/cmvr/api/dexhand_command.proto b/protos/cmvr/api/dexhand_command.proto index 9d65a7f..8ff1bb3 100644 --- a/protos/cmvr/api/dexhand_command.proto +++ b/protos/cmvr/api/dexhand_command.proto @@ -58,6 +58,8 @@ message SensorData { message DexHandState { bool is_initialized = 1; // 是否初始化 repeated FreedomState hands = 2; // 包含多个自由度状态 + bool has_tactile_feedback = 3; // 是否具备真实触觉传感器反馈能力 + string model = 4; // 设备型号,仅作为描述信息 } message GetDexHandStateCommand { @@ -146,4 +148,4 @@ message GetSensorDataStreamCommand { CommandHeader.Feedback header = 1; repeated SensorData sensor = 2;//所有传感器的数据 } -} \ No newline at end of file +} diff --git a/protos/cmvr/config/dexhand_config/dexhand_config.proto b/protos/cmvr/config/dexhand_config/dexhand_config.proto index 0cbc267..9d894d0 100644 --- a/protos/cmvr/config/dexhand_config/dexhand_config.proto +++ b/protos/cmvr/config/dexhand_config/dexhand_config.proto @@ -43,14 +43,25 @@ message ZeroSimTouchDexHand { string id = 1; } +message OYMotionAP001Config { + string id = 1; + string can_interface = 2; + uint32 hand_id = 3; + uint32 master_id = 4; + uint32 command_timeout_ms = 5; +} + message DexHandDeviceConfig { string id = 1; - reserved 2; + string model = 2; + optional bool has_tactile_feedback = 3; oneof backend { RH56DFTPDexHandConfig rh56dftp = 10; PX6AXGen3 px_6ax_gen3 = 11; ZeroSimTouchDexHand zero_sim_touch = 12; + // Shared OYMotion backend for AP001, LiteS001 and compatible hands. + OYMotionAP001Config oymotion_ap001 = 13; } } diff --git a/src/jointfloweditor.cpp b/src/jointfloweditor.cpp new file mode 100644 index 0000000..f2849f6 --- /dev/null +++ b/src/jointfloweditor.cpp @@ -0,0 +1,658 @@ +#include "jointfloweditor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +constexpr qreal kNodeWidth = 190.0; +constexpr qreal kNodeHeight = 76.0; + +class FlowGraphicsView final : public QGraphicsView +{ +public: + explicit FlowGraphicsView(QGraphicsScene *scene, QWidget *parent = nullptr) + : QGraphicsView(scene, parent) + { + } + +protected: + void mousePressEvent(QMouseEvent *event) override + { + if (event->button() == Qt::RightButton) { + m_panning = true; + m_lastPosition = event->pos(); + viewport()->setCursor(Qt::ClosedHandCursor); + event->accept(); + return; + } + QGraphicsView::mousePressEvent(event); + } + + void mouseMoveEvent(QMouseEvent *event) override + { + if (m_panning) { + const QPoint delta = event->pos() - m_lastPosition; + m_lastPosition = event->pos(); + horizontalScrollBar()->setValue(horizontalScrollBar()->value() - delta.x()); + verticalScrollBar()->setValue(verticalScrollBar()->value() - delta.y()); + event->accept(); + return; + } + QGraphicsView::mouseMoveEvent(event); + } + + void mouseReleaseEvent(QMouseEvent *event) override + { + if (event->button() == Qt::RightButton && m_panning) { + m_panning = false; + viewport()->unsetCursor(); + event->accept(); + return; + } + QGraphicsView::mouseReleaseEvent(event); + } + +private: + bool m_panning = false; + QPoint m_lastPosition; +}; + +class FlowCardItem final : public QGraphicsItem +{ +public: + FlowCardItem(QString id, QString title, QString subtitle, bool loop, bool active, + bool collapsed, + std::function moved, + std::function edit, + std::function toggleCollapsed) + : m_id(std::move(id)), m_title(std::move(title)), m_subtitle(std::move(subtitle)), + m_loop(loop), m_active(active), m_collapsed(collapsed), + m_moved(std::move(moved)), m_edit(std::move(edit)), + m_toggleCollapsed(std::move(toggleCollapsed)) + { + setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges); + setAcceptHoverEvents(true); + setCursor(Qt::OpenHandCursor); + setZValue(2.0); + } + + QRectF boundingRect() const override { return QRectF(0, 0, kNodeWidth, kNodeHeight); } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override + { + painter->setRenderHint(QPainter::Antialiasing); + const QColor fill = m_loop ? QColor("#262044") : QColor("#163447"); + const QColor border = m_active ? QColor("#56d39b") + : (isSelected() ? QColor("#64b5f6") : QColor("#52606d")); + painter->setPen(QPen(border, m_active ? 3.0 : 1.5)); + painter->setBrush(fill); + painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10); + painter->setPen(QColor("#f2f5f7")); + QFont titleFont = painter->font(); + titleFont.setBold(true); + painter->setFont(titleFont); + painter->drawText(QRectF(14, 10, kNodeWidth - (m_loop ? 58 : 28), 25), + Qt::AlignLeft | Qt::AlignVCenter, + m_title); + if (m_loop) { + const QColor buttonFill = m_collapsePressed ? QColor("#2563a8") + : m_collapseHovered ? QColor("#244d78") : QColor("#17263a"); + const QColor buttonBorder = m_collapseHovered || m_collapsePressed + ? QColor("#64b5f6") : QColor("#71869b"); + painter->setPen(QPen(buttonBorder, 1.4)); + painter->setBrush(buttonFill); + painter->drawRoundedRect(collapseButtonRect(), 5, 5); + painter->setPen(QPen(QColor("#f4f8fc"), 1.8, + Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + const QPointF center = collapseButtonRect().center(); + QPolygonF arrow; + if (m_collapsed) { + arrow << QPointF(center.x() - 3.5, center.y() - 5) + << QPointF(center.x() + 2.0, center.y()) + << QPointF(center.x() - 3.5, center.y() + 5); + } else { + arrow << QPointF(center.x() - 5, center.y() - 3.0) + << QPointF(center.x(), center.y() + 2.5) + << QPointF(center.x() + 5, center.y() - 3.0); + } + painter->drawPolyline(arrow); + } + painter->setFont(QFont()); + painter->setPen(QColor("#aeb8c2")); + painter->drawText(QRectF(14, 38, kNodeWidth - 28, 26), Qt::AlignLeft | Qt::AlignVCenter, + m_subtitle); + } + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event) override + { + if (m_loop && event->button() == Qt::LeftButton + && collapseButtonRect().contains(event->pos())) { + m_collapsePressed = true; + update(collapseButtonRect().adjusted(-2, -2, 2, 2)); + event->accept(); + return; + } + setCursor(Qt::ClosedHandCursor); + QGraphicsItem::mousePressEvent(event); + } + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override + { + if (m_collapsePressed) { + const bool activate = collapseButtonRect().contains(event->pos()); + m_collapsePressed = false; + update(collapseButtonRect().adjusted(-2, -2, 2, 2)); + if (activate && m_toggleCollapsed) + m_toggleCollapsed(m_id); + event->accept(); + return; + } + setCursor(Qt::OpenHandCursor); + QGraphicsItem::mouseReleaseEvent(event); + if (m_moved) + m_moved(m_id, pos()); + } + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override + { + if (m_edit) + m_edit(m_id); + event->accept(); + } + void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override + { + const bool overButton = m_loop && collapseButtonRect().contains(event->pos()); + if (m_collapseHovered != overButton) { + m_collapseHovered = overButton; + update(collapseButtonRect().adjusted(-2, -2, 2, 2)); + } + setCursor(overButton ? Qt::PointingHandCursor : Qt::OpenHandCursor); + QGraphicsItem::hoverMoveEvent(event); + } + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override + { + if (m_collapseHovered) { + m_collapseHovered = false; + update(collapseButtonRect().adjusted(-2, -2, 2, 2)); + } + setCursor(Qt::OpenHandCursor); + QGraphicsItem::hoverLeaveEvent(event); + } + +private: + QRectF collapseButtonRect() const { return QRectF(kNodeWidth - 34, 9, 22, 22); } + + QString m_id; + QString m_title; + QString m_subtitle; + bool m_loop = false; + bool m_active = false; + bool m_collapsed = false; + bool m_collapseHovered = false; + bool m_collapsePressed = false; + std::function m_moved; + std::function m_edit; + std::function m_toggleCollapsed; +}; +} + +JointFlowEditor::JointFlowEditor(QWidget *parent) : QWidget(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + m_scene = new QGraphicsScene(this); + m_scene->setBackgroundBrush(QColor("#10161d")); + m_view = new FlowGraphicsView(m_scene, this); + m_view->setRenderHint(QPainter::Antialiasing); + m_view->setDragMode(QGraphicsView::RubberBandDrag); + m_view->setMinimumHeight(230); + layout->addWidget(m_view); + connect(m_scene, &QGraphicsScene::selectionChanged, this, [this]() { + for (QGraphicsItem *item : m_scene->selectedItems()) { + const QString id = item->data(0).toString(); + if (!id.isEmpty()) { m_selectedNodeId = id; return; } + } + }); +} + +void JointFlowEditor::addSingleNode(const QString &nodeName, const QString &pointName, + double intervalSeconds) +{ + if (nodeName.trimmed().isEmpty() || pointName.isEmpty()) + return; + Node node; + node.id = QUuid::createUuid().toString(QUuid::WithoutBraces); + node.type = SingleNode; + node.nodeName = nodeName.trimmed(); + node.pointName = pointName; + node.intervalSeconds = qMax(0.0, intervalSeconds); + const Node *insertionParent = nodeById(m_insertionParentId); + node.parentId = insertionParent && insertionParent->type == LoopNode + ? insertionParent->id : QString(); + node.order = childrenOf(node.parentId).size(); + node.position = QPointF(40 + node.order * 220, 40 + (node.parentId.isEmpty() ? 0 : 100)); + m_nodes.append(node); + m_selectedNodeId = node.id; + rebuildScene(); + emit changed(); +} + +void JointFlowEditor::addLoopNode(const QString &nodeName, int loopCount, + double intervalSeconds) +{ + if (nodeName.trimmed().isEmpty()) + return; + Node node; + node.id = QUuid::createUuid().toString(QUuid::WithoutBraces); + node.type = LoopNode; + node.nodeName = nodeName.trimmed(); + node.loopCount = qMax(1, loopCount); + node.intervalSeconds = qMax(0.0, intervalSeconds); + const Node *insertionParent = nodeById(m_insertionParentId); + node.parentId = insertionParent && insertionParent->type == LoopNode + ? insertionParent->id : QString(); + node.order = childrenOf(node.parentId).size(); + node.position = QPointF(40 + node.order * 220, 40 + (node.parentId.isEmpty() ? 0 : 100)); + m_nodes.append(node); + m_selectedNodeId = node.id; + rebuildScene(); + emit changed(); +} + +void JointFlowEditor::removeSelectedNode() +{ + const QString id = selectedNodeId(); + if (id.isEmpty()) + return; + QStringList removing{id}; + for (int i = 0; i < removing.size(); ++i) { + for (const Node &node : m_nodes) + if (node.parentId == removing.at(i)) + removing.append(node.id); + } + QString parentId; + if (const Node *node = nodeById(id)) + parentId = node->parentId; + for (int i = m_nodes.size() - 1; i >= 0; --i) + if (removing.contains(m_nodes.at(i).id)) + m_nodes.removeAt(i); + if (removing.contains(m_insertionParentId)) + setInsertionAtRoot(); + m_selectedNodeId.clear(); + normalizeOrders(parentId); + rebuildScene(); + emit changed(); +} + +void JointFlowEditor::removePointReferences(const QStringList &pointNames) +{ + for (int i = m_nodes.size() - 1; i >= 0; --i) + if (m_nodes.at(i).type == SingleNode && pointNames.contains(m_nodes.at(i).pointName)) + m_nodes.removeAt(i); + rebuildScene(); + emit changed(); +} + +bool JointFlowEditor::isEmpty() const { return m_nodes.isEmpty(); } + +QList JointFlowEditor::expandedSteps( + QString *error, int maximumSteps) const +{ + QList result; + for (const Node *node : childrenOf(QString())) { + if (!appendExecution(*node, result, error, maximumSteps)) + return {}; + } + return result; +} + +bool JointFlowEditor::appendExecution(const Node &node, QList &steps, + QString *error, int maximumSteps) const +{ + if (node.type == SingleNode) { + if (steps.size() >= maximumSteps) { + if (error) *error = QStringLiteral("展开后的流程超过 %1 步").arg(maximumSteps); + return false; + } + steps.append({node.pointName, node.intervalSeconds, node.id}); + return true; + } + const QList children = childrenOf(node.id); + if (children.isEmpty()) { + if (error) *error = QStringLiteral("存在没有子节点的循环节点"); + return false; + } + for (int repeat = 0; repeat < node.loopCount; ++repeat) + for (const Node *child : children) + if (!appendExecution(*child, steps, error, maximumSteps)) return false; + if (!steps.isEmpty()) + steps.last().intervalSeconds += node.intervalSeconds; + return true; +} + +QJsonArray JointFlowEditor::toJson() const +{ + QJsonArray array; + for (const Node &node : m_nodes) + appendJsonNode(array, node); + return array; +} + +void JointFlowEditor::appendJsonNode(QJsonArray &target, const Node &node) const +{ + QJsonObject object; + object.insert(QStringLiteral("id"), node.id); + object.insert(QStringLiteral("type"), node.type == LoopNode ? QStringLiteral("loop") + : QStringLiteral("single")); + object.insert(QStringLiteral("nodeName"), node.nodeName); + object.insert(QStringLiteral("pointName"), node.pointName); + object.insert(QStringLiteral("loopCount"), node.loopCount); + object.insert(QStringLiteral("intervalSeconds"), node.intervalSeconds); + object.insert(QStringLiteral("parentId"), node.parentId); + object.insert(QStringLiteral("order"), node.order); + object.insert(QStringLiteral("x"), node.position.x()); + object.insert(QStringLiteral("y"), node.position.y()); + object.insert(QStringLiteral("collapsed"), node.collapsed); + target.append(object); +} + +bool JointFlowEditor::fromJson(const QJsonArray &array) +{ + QList loaded; + for (const QJsonValue &value : array) { + const QJsonObject object = value.toObject(); + Node node; + node.id = object.value(QStringLiteral("id")).toString(); + if (node.id.isEmpty()) return false; + node.type = object.value(QStringLiteral("type")).toString() == QStringLiteral("loop") + ? LoopNode : SingleNode; + node.nodeName = object.value(QStringLiteral("nodeName")).toString().trimmed(); + node.pointName = object.value(QStringLiteral("pointName")).toString(); + if (node.nodeName.isEmpty()) + node.nodeName = node.type == LoopNode ? QStringLiteral("循环节点") : node.pointName; + node.loopCount = qMax(1, object.value(QStringLiteral("loopCount")).toInt(1)); + node.intervalSeconds = qMax(0.0, object.value(QStringLiteral("intervalSeconds")).toDouble()); + node.parentId = object.value(QStringLiteral("parentId")).toString(); + node.order = object.value(QStringLiteral("order")).toInt(); + node.position = QPointF(object.value(QStringLiteral("x")).toDouble(), + object.value(QStringLiteral("y")).toDouble()); + node.collapsed = object.value(QStringLiteral("collapsed")).toBool(false); + loaded.append(node); + } + m_nodes = loaded; + m_selectedNodeId.clear(); + m_insertionParentId.clear(); + rebuildScene(); + emit insertionContextChanged(QStringLiteral("根流程")); + return true; +} + +void JointFlowEditor::clear() +{ + m_nodes.clear(); + m_selectedNodeId.clear(); + m_insertionParentId.clear(); + rebuildScene(); + emit insertionContextChanged(QStringLiteral("根流程")); +} +void JointFlowEditor::setActiveNode(const QString &nodeId) { m_activeNodeId = nodeId; rebuildScene(); } + +void JointFlowEditor::setAvailablePointNames(const QStringList &pointNames) +{ + m_availablePointNames = pointNames; + m_availablePointNames.removeDuplicates(); +} + +void JointFlowEditor::setInsertionAtRoot() +{ + m_insertionParentId.clear(); + emit insertionContextChanged(QStringLiteral("根流程")); +} + +bool JointFlowEditor::useSelectedLoopAsInsertionParent() +{ + const Node *selected = nodeById(selectedNodeId()); + if (!selected || selected->type != LoopNode) + return false; + m_insertionParentId = selected->id; + emit insertionContextChanged(selected->nodeName); + return true; +} + +JointFlowEditor::Node *JointFlowEditor::nodeById(const QString &id) +{ for (Node &node : m_nodes) if (node.id == id) return &node; return nullptr; } +const JointFlowEditor::Node *JointFlowEditor::nodeById(const QString &id) const +{ for (const Node &node : m_nodes) if (node.id == id) return &node; return nullptr; } + +QList JointFlowEditor::childrenOf(const QString &parentId) const +{ + QList result; + for (const Node &node : m_nodes) if (node.parentId == parentId) result.append(&node); + std::sort(result.begin(), result.end(), [](const Node *a, const Node *b) { + return a->order < b->order; + }); + return result; +} + +QString JointFlowEditor::selectedNodeId() const +{ + for (QGraphicsItem *item : m_scene->selectedItems()) + if (!item->data(0).toString().isEmpty()) return item->data(0).toString(); + return m_selectedNodeId; +} + +void JointFlowEditor::editNode(const QString &id) +{ + Node *node = nodeById(id); + if (!node) return; + + QDialog dialog(this); + dialog.setWindowTitle(node->type == SingleNode + ? QStringLiteral("编辑单步节点") : QStringLiteral("编辑循环节点")); + dialog.setMinimumWidth(420); + QVBoxLayout *dialogLayout = new QVBoxLayout(&dialog); + QFormLayout *form = new QFormLayout; + QLineEdit *nameEdit = new QLineEdit(node->nodeName, &dialog); + form->addRow(QStringLiteral("节点名称"), nameEdit); + + QComboBox *pointCombo = nullptr; + QSpinBox *loopCountSpin = nullptr; + if (node->type == SingleNode) { + QStringList pointNames = m_availablePointNames; + if (!pointNames.contains(node->pointName)) + pointNames.prepend(node->pointName); + pointCombo = new QComboBox(&dialog); + pointCombo->addItems(pointNames); + pointCombo->setCurrentText(node->pointName); + form->addRow(QStringLiteral("执行点位"), pointCombo); + } else { + loopCountSpin = new QSpinBox(&dialog); + loopCountSpin->setRange(1, 10000); + loopCountSpin->setValue(node->loopCount); + form->addRow(QStringLiteral("循环次数"), loopCountSpin); + } + QDoubleSpinBox *intervalSpin = new QDoubleSpinBox(&dialog); + intervalSpin->setRange(0.0, 3600.0); + intervalSpin->setDecimals(1); + intervalSpin->setSingleStep(0.1); + intervalSpin->setSuffix(QStringLiteral(" s")); + intervalSpin->setValue(node->intervalSeconds); + form->addRow(node->type == LoopNode ? QStringLiteral("循环结束后等待") + : QStringLiteral("执行结束后等待"), + intervalSpin); + dialogLayout->addLayout(form); + + QDialogButtonBox *buttons = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); + buttons->button(QDialogButtonBox::Ok)->setText(QStringLiteral("保存")); + buttons->button(QDialogButtonBox::Cancel)->setText(QStringLiteral("取消")); + connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + dialogLayout->addWidget(buttons); + + if (dialog.exec() != QDialog::Accepted || nameEdit->text().trimmed().isEmpty()) + return; + node->nodeName = nameEdit->text().trimmed(); + if (pointCombo) + node->pointName = pointCombo->currentText(); + if (loopCountSpin) + node->loopCount = loopCountSpin->value(); + node->intervalSeconds = intervalSpin->value(); + rebuildScene(); + emit changed(); +} + +void JointFlowEditor::toggleLoopCollapsed(const QString &id) +{ + Node *node = nodeById(id); + if (!node || node->type != LoopNode) + return; + node->collapsed = !node->collapsed; + QTimer::singleShot(0, this, [this]() { + rebuildScene(); + emit changed(); + }); +} + +void JointFlowEditor::moveNode(const QString &id, const QPointF &position) +{ + Node *node = nodeById(id); + if (!node) return; + const QString originalParent = node->parentId; + const QPointF center = position + QPointF(kNodeWidth / 2.0, kNodeHeight / 2.0); + if (!originalParent.isEmpty()) { + for (const Node &candidate : m_nodes) { + if (candidate.id == id || candidate.parentId != originalParent) + continue; + if (QRectF(candidate.position, QSizeF(kNodeWidth, kNodeHeight)).contains(center)) { + rebuildScene(); + return; + } + } + } + node->position = position; + QString newParent = originalParent; + // Once a node belongs to a loop, dragging only changes its order inside that loop. + // This prevents an existing child from accidentally becoming a child of a sibling loop. + if (originalParent.isEmpty()) { + for (const Node &candidate : m_nodes) { + if (candidate.id == id || candidate.type != LoopNode) + continue; + if (!QRectF(candidate.position, QSizeF(kNodeWidth, kNodeHeight)).contains(center)) + continue; + bool createsCycle = false; + const Node *ancestor = &candidate; + while (ancestor && !ancestor->parentId.isEmpty()) { + if (ancestor->parentId == id) { createsCycle = true; break; } + ancestor = nodeById(ancestor->parentId); + } + if (!createsCycle) { + newParent = candidate.id; + break; + } + } + } + node = nodeById(id); + if (node) + node->parentId = newParent; + QStringList parents{newParent}; + for (const Node &candidate : m_nodes) + if (!parents.contains(candidate.parentId)) parents.append(candidate.parentId); + for (const QString &parent : parents) { + QList siblings; + for (Node &candidate : m_nodes) + if (candidate.parentId == parent) siblings.append(&candidate); + std::sort(siblings.begin(), siblings.end(), [](const Node *a, const Node *b) { + return a->position.x() == b->position.x() + ? a->position.y() < b->position.y() : a->position.x() < b->position.x(); + }); + for (int order = 0; order < siblings.size(); ++order) + siblings.at(order)->order = order; + } + rebuildScene(); + emit changed(); +} + +void JointFlowEditor::normalizeOrders(const QString &parentId) +{ + int order = 0; + for (const Node *child : childrenOf(parentId)) + if (Node *node = nodeById(child->id)) node->order = order++; +} + +void JointFlowEditor::rebuildScene() +{ + m_scene->clear(); + QHash cards; + for (const Node &node : m_nodes) { + bool hiddenByCollapsedAncestor = false; + const Node *ancestor = node.parentId.isEmpty() ? nullptr : nodeById(node.parentId); + while (ancestor) { + if (ancestor->collapsed) { + hiddenByCollapsedAncestor = true; + break; + } + ancestor = ancestor->parentId.isEmpty() ? nullptr : nodeById(ancestor->parentId); + } + if (hiddenByCollapsedAncestor) + continue; + const QString title = node.nodeName; + const QString executionUnit = node.type == LoopNode + ? QStringLiteral("循环 × %1").arg(node.loopCount) : node.pointName; + const QString subtitle = QStringLiteral("执行:%1 · 等待 %2 s") + .arg(executionUnit).arg(node.intervalSeconds, 0, 'f', 1); + auto *card = new FlowCardItem(node.id, title, subtitle, node.type == LoopNode, + node.id == m_activeNodeId, node.collapsed, + [this](const QString &id, const QPointF &pos) { moveNode(id, pos); }, + [this](const QString &id) { editNode(id); }, + [this](const QString &id) { toggleLoopCollapsed(id); }); + card->setData(0, node.id); + card->setPos(node.position); + m_scene->addItem(card); + if (node.id == m_selectedNodeId) + card->setSelected(true); + cards.insert(node.id, card); + } + for (const Node &node : m_nodes) { + if (node.parentId.isEmpty() || !cards.contains(node.parentId) || !cards.contains(node.id)) + continue; + const QPointF from = cards.value(node.parentId)->sceneBoundingRect().center(); + const QPointF to = cards.value(node.id)->sceneBoundingRect().center(); + m_scene->addLine(QLineF(from, to), QPen(QColor("#667788"), 2.0)); + } + QStringList parentIds{QString()}; + for (const Node &node : m_nodes) + if (!parentIds.contains(node.parentId)) parentIds.append(node.parentId); + for (const QString &parentId : parentIds) { + const QList siblings = childrenOf(parentId); + for (int i = 1; i < siblings.size(); ++i) { + const Node *previous = siblings.at(i - 1); + const Node *current = siblings.at(i); + if (!cards.contains(previous->id) || !cards.contains(current->id)) continue; + const QPointF from = cards.value(previous->id)->sceneBoundingRect().center(); + const QPointF to = cards.value(current->id)->sceneBoundingRect().center(); + m_scene->addLine(QLineF(from, to), QPen(QColor("#3f8db3"), 1.5, Qt::DashLine)); + } + } + m_scene->setSceneRect(m_scene->itemsBoundingRect().adjusted(-60, -60, 60, 60)); +} diff --git a/src/jointfloweditor.h b/src/jointfloweditor.h new file mode 100644 index 0000000..0cd1aeb --- /dev/null +++ b/src/jointfloweditor.h @@ -0,0 +1,78 @@ +#pragma once + +#include +#include +#include +#include + +class QGraphicsScene; +class QGraphicsView; + +class JointFlowEditor : public QWidget +{ + Q_OBJECT +public: + struct ExecutionStep { + QString pointName; + double intervalSeconds = 0.0; + QString nodeId; + }; + + explicit JointFlowEditor(QWidget *parent = nullptr); + + void addSingleNode(const QString &nodeName, const QString &pointName, + double intervalSeconds); + void addLoopNode(const QString &nodeName, int loopCount, double intervalSeconds); + void removeSelectedNode(); + void removePointReferences(const QStringList &pointNames); + bool isEmpty() const; + QList expandedSteps(QString *error = nullptr, + int maximumSteps = 100000) const; + QJsonArray toJson() const; + bool fromJson(const QJsonArray &array); + void clear(); + void setActiveNode(const QString &nodeId); + void setAvailablePointNames(const QStringList &pointNames); + void setInsertionAtRoot(); + bool useSelectedLoopAsInsertionParent(); + +signals: + void changed(); + void insertionContextChanged(const QString &description); + +private: + enum NodeType { SingleNode, LoopNode }; + struct Node { + QString id; + NodeType type = SingleNode; + QString nodeName; + QString pointName; + int loopCount = 1; + double intervalSeconds = 0.0; + QString parentId; + int order = 0; + QPointF position; + bool collapsed = false; + }; + + Node *nodeById(const QString &id); + const Node *nodeById(const QString &id) const; + QList childrenOf(const QString &parentId) const; + QString selectedNodeId() const; + void editNode(const QString &id); + void toggleLoopCollapsed(const QString &id); + void moveNode(const QString &id, const QPointF &position); + void normalizeOrders(const QString &parentId); + void rebuildScene(); + void appendJsonNode(QJsonArray &target, const Node &node) const; + bool appendExecution(const Node &node, QList &steps, + QString *error, int maximumSteps) const; + + QList m_nodes; + QGraphicsScene *m_scene = nullptr; + QGraphicsView *m_view = nullptr; + QString m_activeNodeId; + QString m_selectedNodeId; + QString m_insertionParentId; + QStringList m_availablePointNames; +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 43a7589..e0cabb8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,4 +1,6 @@ #include "mainwindow.h" +#include "tactileheatmapwidget.h" +#include "jointfloweditor.h" #include "videorenderwidget.h" #include "audiostreammanager.h" @@ -26,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -407,7 +410,7 @@ MainWindow::MainWindow(QWidget *parent) m_pages->addWidget(createAgvPage()); m_pages->addWidget(createAudioPage(true)); m_pages->addWidget(createAudioPage(false)); - m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.DexHandService"))); + m_pages->addWidget(createDexHandPage()); m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.BioHeadService"))); m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.HlcService"))); m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.TestService"))); @@ -442,6 +445,17 @@ MainWindow::MainWindow(QWidget *parent) m_cameraDeviceCombo->setCurrentIndex(index); } break; + case 3: + pageIndex = 6; + if (m_dexHandDeviceCombo) { + int index = m_dexHandDeviceCombo->findData(deviceId); + if (index < 0) { + m_dexHandDeviceCombo->addItem(deviceId, deviceId); + index = m_dexHandDeviceCombo->count() - 1; + } + m_dexHandDeviceCombo->setCurrentIndex(index); + } + break; case 0: pageIndex = 3; if (m_agvIdEdit) m_agvIdEdit->setText(deviceId); @@ -454,9 +468,6 @@ MainWindow::MainWindow(QWidget *parent) pageIndex = 5; if (m_microphoneIdEdit) m_microphoneIdEdit->setText(deviceId); break; - case 3: - pageIndex = 6; - break; case 8: pageIndex = 7; break; @@ -534,6 +545,16 @@ MainWindow::MainWindow(QWidget *parent) m_client->setCameraStreamCodec(isH265 ? QStringLiteral("h265") : QStringLiteral("h264")); }); + connect(m_client, &RobotClient::dexHandStatusReceived, + this, &MainWindow::updateDexHandStatus); + connect(m_client, &RobotClient::dexHandTactileReceived, + this, &MainWindow::updateDexHandTactile); + connect(m_client, &RobotClient::dexHandTactileStreamStateChanged, + this, [this](bool running, const QString &detail) { + if (m_dexHandTactileStateLabel) m_dexHandTactileStateLabel->setText(detail); + if (m_dexHandTactileStartButton) m_dexHandTactileStartButton->setEnabled(!running); + if (m_dexHandTactileStopButton) m_dexHandTactileStopButton->setEnabled(running); + }); connect(m_client, &RobotClient::videoFrameReceived, this, &MainWindow::updateVideoFrame); connect(m_client, &RobotClient::cameraStreamStateChanged, this, &MainWindow::updateCameraStreamState); @@ -1476,6 +1497,34 @@ void MainWindow::updateSystemStatus(double cpu, double memory, double disk, && (previousCameraId != cameraId || m_cameraCodecCombo->toolTip().isEmpty())) m_client->requestCameraStatus(cameraId); } + + if (m_dexHandDeviceCombo) { + const QString previousHandId = m_dexHandDeviceCombo->currentData().toString(); + const QSignalBlocker blocker(m_dexHandDeviceCombo); + m_dexHandDeviceCombo->clear(); + for (const QVariant &value : devices) { + const QVariantMap device = value.toMap(); + if (device.value(QStringLiteral("type")).toInt() != 3) + continue; + const QString deviceId = device.value(QStringLiteral("deviceId")).toString(); + if (deviceId.isEmpty()) + continue; + const QString driver = device.value(QStringLiteral("driverType")).toString(); + m_dexHandDeviceCombo->addItem( + driver.isEmpty() ? deviceId : QStringLiteral("%1 · %2").arg(deviceId, driver), + deviceId); + m_dexHandDeviceCombo->setItemData(m_dexHandDeviceCombo->count() - 1, + driver, Qt::UserRole + 1); + } + int index = m_dexHandDeviceCombo->findData(previousHandId); + if (index < 0 && m_dexHandDeviceCombo->count() > 0) + index = 0; + if (index >= 0) + m_dexHandDeviceCombo->setCurrentIndex(index); + const QString selectedHandId = m_dexHandDeviceCombo->currentData().toString(); + if (!selectedHandId.isEmpty()) + m_client->requestDexHandStatus(selectedHandId); + } } void MainWindow::updateSystemInfo(const QVariantMap &info) @@ -1488,6 +1537,94 @@ void MainWindow::updateSystemInfo(const QVariantMap &info) m_systemOsValue->setText(platform); } +void MainWindow::updateDexHandStatus(const QString &deviceId, bool initialized, + bool hasTactileFeedback, + const QString &model, + const QVariantList &freedoms) +{ + if (!m_dexHandDeviceCombo + || m_dexHandDeviceCombo->currentData().toString() != deviceId) + return; + const QString modelText = model.isEmpty() ? QStringLiteral("未知型号") : model; + m_dexHandStateLabel->setText(initialized + ? QStringLiteral("%1 · 已初始化 · %2") + .arg(modelText, + hasTactileFeedback ? QStringLiteral("支持触觉") + : QStringLiteral("无触觉")) + : QStringLiteral("%1 · 未初始化").arg(modelText)); + m_dexHandStateLabel->setProperty("state", initialized ? QStringLiteral("ok") + : QStringLiteral("warn")); + if (m_dexHandHasTactileFeedback && !hasTactileFeedback) + m_client->stopDexHandTactileStream(); + m_dexHandHasTactileFeedback = hasTactileFeedback; + if (m_dexHandTactilePanel) + m_dexHandTactilePanel->setVisible(hasTactileFeedback); + m_dexHandStateTable->setRowCount(6); + const QString driver = m_dexHandDeviceCombo->currentData(Qt::UserRole + 1).toString(); + const bool oymotion = driver.contains(QStringLiteral("OYMotion"), + Qt::CaseInsensitive); + const QStringList names = {QStringLiteral("小拇指"), QStringLiteral("无名指"), + QStringLiteral("中指"), QStringLiteral("食指"), + QStringLiteral("大拇指弯曲"), QStringLiteral("大拇指旋转")}; + for (int row = 0; row < 6; ++row) { + QVariantMap freedom; + for (const QVariant &value : freedoms) { + if (value.toMap().value(QStringLiteral("id")).toInt() == row) { + freedom = value.toMap(); + break; + } + } + const QStringList values = { + names.at(row), oymotion + ? QStringLiteral("%1°").arg( + freedom.value(QStringLiteral("angle")).toInt() / 100.0, 0, 'f', 2) + : QString::number(freedom.value(QStringLiteral("angle")).toInt()), + QString::number(freedom.value(QStringLiteral("position")).toInt()), + QString::number(freedom.value(QStringLiteral("speed")).toInt()), + QString::number(freedom.value(QStringLiteral("force")).toInt()), + QString::number(freedom.value(QStringLiteral("current")).toInt()), + QString::number(freedom.value(QStringLiteral("temperature")).toInt()), + freedom.value(QStringLiteral("error")).toInt() == 0 + ? QStringLiteral("正常") + : freedom.value(QStringLiteral("errors")).toStringList().join(QStringLiteral(";"))}; + for (int column = 0; column < values.size(); ++column) + m_dexHandStateTable->setItem(row, column, new QTableWidgetItem(values.at(column))); + } +} + +void MainWindow::updateDexHandTactile(const QString &deviceId, int rows, int cols, + const QVariantList &values, quint64 frameCount) +{ + if (!m_dexHandDeviceCombo || !m_dexHandTactileHeatmap + || m_dexHandDeviceCombo->currentData().toString() != deviceId + || rows <= 0 || cols <= 0 || values.size() < rows * cols) + return; + + // Preserve the full-rate gRPC reception while limiting expensive table + // painting to about 30 FPS. + const qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (now - m_lastDexHandTactileUiUpdateMs < 33) + return; + m_lastDexHandTactileUiUpdateMs = now; + QVector forceValues; + forceValues.reserve(rows * cols); + int peak = 0; + qint64 totalMilliNewtons = 0; + for (int index = 0; index < rows * cols; ++index) { + const int value = values.at(index).toInt(); + forceValues.append(value); + peak = qMax(peak, value); + totalMilliNewtons += value; + } + m_dexHandTactileHeatmap->setTactileData(rows, cols, forceValues); + if (m_dexHandTactileStateLabel) + m_dexHandTactileStateLabel->setText( + QStringLiteral("帧 %1 · 合力 %2 N · 峰值 %3 mN") + .arg(frameCount) + .arg(totalMilliNewtons / 1000.0, 0, 'f', 3) + .arg(peak)); +} + void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &navigation) { const bool controllerConnected = state.value(QStringLiteral("connected")).toBool(); @@ -1782,6 +1919,11 @@ void MainWindow::refreshRecordedJointPoints() { if (!m_jointPointTable) return; + QStringList pointNames; + for (const RecordedJointPoint &point : m_recordedJointPoints) + pointNames.append(point.name); + if (m_jointFlowEditor) + m_jointFlowEditor->setAvailablePointNames(pointNames); m_jointPointTable->setRowCount(m_recordedJointPoints.size()); for (int row = 0; row < m_recordedJointPoints.size(); ++row) { const RecordedJointPoint &point = m_recordedJointPoints.at(row); @@ -1805,21 +1947,8 @@ void MainWindow::refreshRecordedJointPoints() void MainWindow::refreshJointFlowTable() { - if (!m_jointFlowTable) - return; - m_jointFlowTable->setRowCount(m_jointFlowSteps.size()); - for (int row = 0; row < m_jointFlowSteps.size(); ++row) { - const JointFlowStep &step = m_jointFlowSteps.at(row); - m_jointFlowTable->setItem(row, 0, new QTableWidgetItem(QString::number(row + 1))); - m_jointFlowTable->setItem(row, 1, new QTableWidgetItem(step.pointName)); - m_jointFlowTable->setItem(row, 2, new QTableWidgetItem( - QStringLiteral("%1 s").arg(step.waitSeconds, 0, 'f', 1))); - m_jointFlowTable->setItem(row, 3, new QTableWidgetItem( - step.loopGroup.isEmpty() ? QStringLiteral("—") : step.loopGroup)); - m_jointFlowTable->setItem(row, 4, new QTableWidgetItem( - step.loopGroup.isEmpty() ? QStringLiteral("1") - : QString::number(step.loopCount))); - } + if (m_jointFlowEditor) + m_jointFlowEditor->update(); } void MainWindow::recordCurrentJointPoint() @@ -1914,13 +2043,14 @@ void MainWindow::startJointPointLoop() { if (m_jointPointLoopActive || m_jointPointMovePending) return; - if (m_jointFlowSteps.isEmpty()) { + if (!m_jointFlowEditor || m_jointFlowEditor->isEmpty()) { QMessageBox::information(this, QStringLiteral("执行自定义流程"), QStringLiteral("请先向自定义流程中添加步骤。")); return; } m_jointPointLoopRows.clear(); m_jointPointExecutionWaits.clear(); + m_jointPointExecutionNodeIds.clear(); const auto pointRow = [this](const QString &name) { for (int row = 0; row < m_recordedJointPoints.size(); ++row) { if (m_recordedJointPoints.at(row).name == name) @@ -1928,32 +2058,26 @@ void MainWindow::startJointPointLoop() } return -1; }; - for (int i = 0; i < m_jointFlowSteps.size();) { - const JointFlowStep &step = m_jointFlowSteps.at(i); - if (step.loopGroup.isEmpty()) { - const int row = pointRow(step.pointName); - if (row >= 0) { - m_jointPointLoopRows.append(row); - m_jointPointExecutionWaits.append(step.waitSeconds); - } - ++i; - continue; + QString flowError; + const QList steps = + m_jointFlowEditor->expandedSteps(&flowError); + if (!flowError.isEmpty()) { + QMessageBox::warning(this, QStringLiteral("执行自定义流程"), flowError); + return; + } + for (const JointFlowEditor::ExecutionStep &step : steps) { + const int row = pointRow(step.pointName); + if (row < 0) { + QMessageBox::warning(this, QStringLiteral("执行自定义流程"), + QStringLiteral("流程引用的点位“%1”已不存在。").arg(step.pointName)); + m_jointPointLoopRows.clear(); + m_jointPointExecutionWaits.clear(); + m_jointPointExecutionNodeIds.clear(); + return; } - int end = i + 1; - while (end < m_jointFlowSteps.size() - && m_jointFlowSteps.at(end).loopGroup == step.loopGroup) - ++end; - for (int repeat = 0; repeat < step.loopCount; ++repeat) { - for (int index = i; index < end; ++index) { - const JointFlowStep &groupStep = m_jointFlowSteps.at(index); - const int row = pointRow(groupStep.pointName); - if (row >= 0) { - m_jointPointLoopRows.append(row); - m_jointPointExecutionWaits.append(groupStep.waitSeconds); - } - } - } - i = end; + m_jointPointLoopRows.append(row); + m_jointPointExecutionWaits.append(step.intervalSeconds); + m_jointPointExecutionNodeIds.append(step.nodeId); } if (m_jointPointLoopRows.isEmpty()) { QMessageBox::warning(this, QStringLiteral("执行自定义流程"), @@ -1987,6 +2111,8 @@ void MainWindow::advanceJointPointLoop() return; } const RecordedJointPoint &point = m_recordedJointPoints.at(row); + if (m_jointFlowEditor && executionIndex < m_jointPointExecutionNodeIds.size()) + m_jointFlowEditor->setActiveNode(m_jointPointExecutionNodeIds.at(executionIndex)); QVariantList positions; for (double position : point.positions) positions.append(position); @@ -2004,6 +2130,9 @@ void MainWindow::stopJointPointLoop(const QString &reason) m_jointPointMovePending = false; m_jointPointLoopRows.clear(); m_jointPointExecutionWaits.clear(); + m_jointPointExecutionNodeIds.clear(); + if (m_jointFlowEditor) + m_jointFlowEditor->setActiveNode(QString()); if (m_startJointPointLoopButton) m_startJointPointLoopButton->setEnabled(true); if (m_runJointPointButton) @@ -2223,19 +2352,45 @@ void MainWindow::loadJointPrograms(QSettings &settings) } settings.endArray(); - m_jointFlowSteps.clear(); - const int flowCount = settings.beginReadArray(QStringLiteral("arm/jointFlow")); - for (int i = 0; i < flowCount; ++i) { - settings.setArrayIndex(i); - JointFlowStep step; - step.pointName = settings.value(QStringLiteral("pointName")).toString(); - step.waitSeconds = settings.value(QStringLiteral("waitSeconds"), 1.0).toDouble(); - step.loopGroup = settings.value(QStringLiteral("loopGroup")).toString(); - step.loopCount = settings.value(QStringLiteral("loopCount"), 1).toInt(); - if (!step.pointName.isEmpty()) - m_jointFlowSteps.append(step); + if (m_jointFlowEditor) { + m_jointFlowEditor->clear(); + const QByteArray flowJson = settings.value(QStringLiteral("arm/jointFlowGraph")).toByteArray(); + const QJsonDocument document = QJsonDocument::fromJson(flowJson); + if (document.isArray()) { + m_jointFlowEditor->fromJson(document.array()); + } else { + struct LegacyStep { QString point; double wait = 1.0; QString group; int count = 1; }; + QList legacy; + const int flowCount = settings.beginReadArray(QStringLiteral("arm/jointFlow")); + for (int i = 0; i < flowCount; ++i) { + settings.setArrayIndex(i); + LegacyStep step; + step.point = settings.value(QStringLiteral("pointName")).toString(); + step.wait = settings.value(QStringLiteral("waitSeconds"), 1.0).toDouble(); + step.group = settings.value(QStringLiteral("loopGroup")).toString(); + step.count = qMax(1, settings.value(QStringLiteral("loopCount"), 1).toInt()); + if (!step.point.isEmpty()) legacy.append(step); + } + settings.endArray(); + for (int i = 0; i < legacy.size();) { + if (legacy.at(i).group.isEmpty()) { + m_jointFlowEditor->addSingleNode(legacy.at(i).point, + legacy.at(i).point, + legacy.at(i).wait); + ++i; + continue; + } + int end = i + 1; + while (end < legacy.size() && legacy.at(end).group == legacy.at(i).group) ++end; + for (int repeat = 0; repeat < legacy.at(i).count; ++repeat) + for (int index = i; index < end; ++index) + m_jointFlowEditor->addSingleNode(legacy.at(index).point, + legacy.at(index).point, + legacy.at(index).wait); + i = end; + } + } } - settings.endArray(); refreshRecordedJointPoints(); refreshJointFlowTable(); } @@ -2257,17 +2412,11 @@ void MainWindow::saveJointPrograms(QSettings &settings) const settings.setValue(QStringLiteral("positions"), positions); } settings.endArray(); - settings.remove(QStringLiteral("arm/jointFlow")); - settings.beginWriteArray(QStringLiteral("arm/jointFlow")); - for (int i = 0; i < m_jointFlowSteps.size(); ++i) { - settings.setArrayIndex(i); - const JointFlowStep &step = m_jointFlowSteps.at(i); - settings.setValue(QStringLiteral("pointName"), step.pointName); - settings.setValue(QStringLiteral("waitSeconds"), step.waitSeconds); - settings.setValue(QStringLiteral("loopGroup"), step.loopGroup); - settings.setValue(QStringLiteral("loopCount"), step.loopCount); + if (m_jointFlowEditor) { + settings.setValue(QStringLiteral("arm/jointFlowGraph"), + QJsonDocument(m_jointFlowEditor->toJson()).toJson(QJsonDocument::Compact)); + settings.remove(QStringLiteral("arm/jointFlow")); } - settings.endArray(); } void MainWindow::setControlsEnabled(bool enabled) diff --git a/src/mainwindow.h b/src/mainwindow.h index 392871f..a069d31 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -41,6 +41,8 @@ class QuicTestServer; class UrdfViewerWidget; class AudioStreamManager; class VideoRenderWidget; +class TactileHeatmapWidget; +class JointFlowEditor; class MainWindow : public QMainWindow { @@ -73,6 +75,12 @@ private slots: void updateCameraStreamState(const QString &cameraId, bool running, const QString &detail); void updateCameraRecordingState(bool recording, const QString &detail); + void updateDexHandStatus(const QString &deviceId, bool initialized, + bool hasTactileFeedback, + const QString &model, + const QVariantList &freedoms); + void updateDexHandTactile(const QString &deviceId, int rows, int cols, + const QVariantList &values, quint64 frameCount); void updateAgvState(const QVariantMap &state, const QVariantMap &navigation); void updateAgvInventory(const QStringList &maps, const QVariantList &stations); void handleCommand(const QString &command, bool success, const QString &detail); @@ -95,6 +103,7 @@ private: QWidget *createSystemPage(); QWidget *createArmPage(); QWidget *createCameraPage(); + QWidget *createDexHandPage(); QStringList configuredCameraIds() const; void rebuildCameraPreviewGrid(const QStringList &cameraIds); void refreshCameraStreamControls(); @@ -185,7 +194,6 @@ private: QStringList m_leftArmJointNames; QStringList m_rightArmJointNames; QStringList m_activeArmJointNames; - QTabWidget *m_motionCommandTabs = nullptr; QList m_moveJPoseSpins; QComboBox *m_moveJPoseBaseLinkCombo = nullptr; QPushButton *m_copyCurrentPoseButton = nullptr; @@ -238,23 +246,16 @@ private: QStringList jointNames; QVector positions; }; - struct JointFlowStep { - QString pointName; - double waitSeconds = 1.0; - QString loopGroup; - int loopCount = 1; - }; QList m_recordedJointPoints; - QList m_jointFlowSteps; QHash m_latestArmJointPositions; QLineEdit *m_jointPointNameEdit = nullptr; QTableWidget *m_jointPointTable = nullptr; QLabel *m_jointPointDetailLabel = nullptr; QSpinBox *m_jointPointLoopCount = nullptr; QDoubleSpinBox *m_jointPointInterval = nullptr; - QLineEdit *m_jointFlowGroupEdit = nullptr; QSpinBox *m_jointFlowGroupCount = nullptr; - QTableWidget *m_jointFlowTable = nullptr; + JointFlowEditor *m_jointFlowEditor = nullptr; + QDialog *m_jointFlowDialog = nullptr; QPushButton *m_recordJointPointButton = nullptr; QPushButton *m_runJointPointButton = nullptr; QPushButton *m_deleteJointPointButton = nullptr; @@ -263,6 +264,7 @@ private: QLabel *m_jointPointLoopStatus = nullptr; QVector m_jointPointLoopRows; QVector m_jointPointExecutionWaits; + QStringList m_jointPointExecutionNodeIds; int m_jointPointLoopCursor = 0; int m_jointPointLoopsCompleted = 0; int m_jointPointLoopTarget = 0; @@ -295,6 +297,23 @@ private: bool m_cameraStreaming = false; bool m_cameraRecording = false; + QComboBox *m_dexHandDeviceCombo = nullptr; + QLabel *m_dexHandStateLabel = nullptr; + QTableWidget *m_dexHandStateTable = nullptr; + QTabWidget *m_dexHandCommandTabs = nullptr; + QList m_dexHandAngleSpins; + QList m_dexHandPositionSpins; + QList m_dexHandSpeedSpins; + QList m_dexHandForceSpins; + QTimer *m_dexHandRefreshTimer = nullptr; + QWidget *m_dexHandTactilePanel = nullptr; + TactileHeatmapWidget *m_dexHandTactileHeatmap = nullptr; + QLabel *m_dexHandTactileStateLabel = nullptr; + QPushButton *m_dexHandTactileStartButton = nullptr; + QPushButton *m_dexHandTactileStopButton = nullptr; + bool m_dexHandHasTactileFeedback = false; + qint64 m_lastDexHandTactileUiUpdateMs = 0; + QLineEdit *m_agvIdEdit = nullptr; QDialog *m_agvStatusDialog = nullptr; QCheckBox *m_agvStatusSwitch = nullptr; diff --git a/src/mainwindow_ui.cpp b/src/mainwindow_ui.cpp index f662840..dc1a520 100644 --- a/src/mainwindow_ui.cpp +++ b/src/mainwindow_ui.cpp @@ -2,6 +2,8 @@ #include "audiostreammanager.h" #include "robotclient.h" +#include "tactileheatmapwidget.h" +#include "jointfloweditor.h" #include "rpcservicewidget.h" #include "uiicons.h" #include "urdfviewerwidget.h" @@ -31,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -373,19 +376,11 @@ QWidget *MainWindow::createArmPage() ui.poseValue->hide(); ui.updatedValue->hide(); - m_motionCommandTabs = new QTabWidget(ui.targetsPanel); - m_motionCommandTabs->setObjectName(QStringLiteral("armMotionCommandTabs")); - m_motionCommandTabs->setDocumentMode(true); - QWidget *moveJPage = new QWidget(m_motionCommandTabs); - QGridLayout *moveJLayout = new QGridLayout(moveJPage); - moveJLayout->setContentsMargins(0, 0, 0, 0); - moveJLayout->setHorizontalSpacing(12); - moveJLayout->setVerticalSpacing(10); - moveJLayout->setColumnStretch(0, 4); - moveJLayout->setColumnStretch(1, 6); - moveJLayout->setRowStretch(0, 1); - moveJLayout->setRowStretch(1, 1); - QSplitter *armTargetTables = new QSplitter(Qt::Vertical, moveJPage); + QWidget *directMovePage = new QWidget; + QVBoxLayout *directMoveLayout = new QVBoxLayout(directMovePage); + directMoveLayout->setContentsMargins(0, 8, 0, 0); + directMoveLayout->setSpacing(8); + QSplitter *armTargetTables = new QSplitter(Qt::Vertical, directMovePage); armTargetTables->setObjectName(QStringLiteral("armTargetTables")); armTargetTables->setChildrenCollapsible(false); QWidget *leftTargets = new QWidget(armTargetTables); @@ -410,7 +405,20 @@ QWidget *MainWindow::createArmPage() armTargetTables->addWidget(leftTargets); armTargetTables->addWidget(rightTargets); armTargetTables->setSizes({340, 340}); - moveJLayout->addWidget(armTargetTables, 0, 0, 2, 1); + directMoveLayout->addWidget(armTargetTables, 1); + QHBoxLayout *directMoveActions = new QHBoxLayout; + ui.zeroButton->setParent(directMovePage); + ui.safetyHint->setParent(directMovePage); + m_sendMoveButton->setParent(directMovePage); + directMoveActions->addWidget(ui.zeroButton); + directMoveActions->addWidget(ui.safetyHint, 1); + directMoveActions->addWidget(m_sendMoveButton); + directMoveLayout->addLayout(directMoveActions); + + QWidget *moveJPage = new QWidget; + QVBoxLayout *moveJLayout = new QVBoxLayout(moveJPage); + moveJLayout->setContentsMargins(0, 0, 0, 0); + moveJLayout->setSpacing(10); QFrame *pointPanel = new QFrame(moveJPage); pointPanel->setObjectName(QStringLiteral("panelCard")); @@ -469,7 +477,7 @@ QWidget *MainWindow::createArmPage() pointActions->addStretch(1); pointActions->addWidget(m_jointPointLoopStatus); pointLayout->addLayout(pointActions); - moveJLayout->addWidget(pointPanel, 0, 1); + moveJLayout->addWidget(pointPanel, 2); connect(m_recordJointPointButton, &QPushButton::clicked, this, &MainWindow::recordCurrentJointPoint); @@ -495,10 +503,8 @@ QWidget *MainWindow::createArmPage() m_recordedJointPoints.removeAt(row); } } - for (int i = m_jointFlowSteps.size() - 1; i >= 0; --i) { - if (removedNames.contains(m_jointFlowSteps.at(i).pointName)) - m_jointFlowSteps.removeAt(i); - } + if (m_jointFlowEditor) + m_jointFlowEditor->removePointReferences(removedNames); refreshRecordedJointPoints(); refreshJointFlowTable(); QSettings settings; @@ -537,38 +543,37 @@ QWidget *MainWindow::createArmPage() m_jointPointInterval->setDecimals(1); m_jointPointInterval->setValue(1.0); m_jointPointInterval->setSuffix(QStringLiteral(" s")); - m_jointFlowGroupEdit = new QLineEdit(flowPanel); - m_jointFlowGroupEdit->setPlaceholderText(QStringLiteral("循环组名(留空=执行一次)")); - m_jointFlowGroupEdit->setMaximumWidth(190); m_jointFlowGroupCount = new QSpinBox(flowPanel); m_jointFlowGroupCount->setRange(1, 10000); - m_jointFlowGroupCount->setValue(1); - QPushButton *addFlowStepButton = new QPushButton(QStringLiteral("添加选中点位到流程"), flowPanel); + m_jointFlowGroupCount->setValue(2); + QLabel *insertionContextLabel = new QLabel(QStringLiteral("添加到:根流程"), flowPanel); + insertionContextLabel->setObjectName(QStringLiteral("mutedLabel")); + QPushButton *insertAtRootButton = new QPushButton(QStringLiteral("返回根流程"), flowPanel); + QPushButton *enterSelectedLoopButton = new QPushButton(QStringLiteral("进入选中循环"), flowPanel); + QPushButton *addFlowStepButton = new QPushButton(QStringLiteral("+ 单步节点"), flowPanel); + QPushButton *addFlowLoopButton = new QPushButton(QStringLiteral("+ 循环节点"), flowPanel); flowBuilder->addWidget(flowTitle); + flowBuilder->addWidget(insertionContextLabel); + flowBuilder->addWidget(insertAtRootButton); + flowBuilder->addWidget(enterSelectedLoopButton); flowBuilder->addStretch(1); flowBuilder->addWidget(intervalLabel); flowBuilder->addWidget(m_jointPointInterval); - flowBuilder->addWidget(m_jointFlowGroupEdit); - flowBuilder->addWidget(new QLabel(QStringLiteral("组循环次数"), flowPanel)); - flowBuilder->addWidget(m_jointFlowGroupCount); flowBuilder->addWidget(addFlowStepButton); + flowBuilder->addWidget(new QLabel(QStringLiteral("循环次数"), flowPanel)); + flowBuilder->addWidget(m_jointFlowGroupCount); + flowBuilder->addWidget(addFlowLoopButton); flowLayout->addLayout(flowBuilder); - m_jointFlowTable = new QTableWidget(0, 5, flowPanel); - m_jointFlowTable->setHorizontalHeaderLabels({QStringLiteral("顺序"), QStringLiteral("动作点位"), - QStringLiteral("完成后等待"), QStringLiteral("循环组"), QStringLiteral("组循环次数")}); - m_jointFlowTable->setSelectionBehavior(QAbstractItemView::SelectRows); - m_jointFlowTable->setSelectionMode(QAbstractItemView::SingleSelection); - m_jointFlowTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - m_jointFlowTable->verticalHeader()->setVisible(false); - m_jointFlowTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); - m_jointFlowTable->setMinimumHeight(120); - flowLayout->addWidget(m_jointFlowTable); + QLabel *flowHint = new QLabel(QStringLiteral( + "默认在根流程添加;选中循环后点击“进入选中循环”,可向循环内添加节点。" + "点击“返回根流程”退出循环;双击卡片编辑参数,左键拖动节点,右键拖动画布。" + "循环卡片右上角可展开或收起子节点;循环内子节点只能在当前循环内调整顺序。"), flowPanel); + flowHint->setObjectName(QStringLiteral("mutedLabel")); + flowLayout->addWidget(flowHint); + m_jointFlowEditor = new JointFlowEditor(flowPanel); + flowLayout->addWidget(m_jointFlowEditor); QHBoxLayout *flowActions = new QHBoxLayout; - QPushButton *flowUpButton = new QPushButton(QStringLiteral("上移"), flowPanel); - QPushButton *flowDownButton = new QPushButton(QStringLiteral("下移"), flowPanel); - QPushButton *flowDeleteButton = new QPushButton(QStringLiteral("删除步骤"), flowPanel); - flowActions->addWidget(flowUpButton); - flowActions->addWidget(flowDownButton); + QPushButton *flowDeleteButton = new QPushButton(QStringLiteral("删除选中节点"), flowPanel); flowActions->addWidget(flowDeleteButton); flowActions->addStretch(1); flowActions->addWidget(loopCountLabel); @@ -577,60 +582,63 @@ QWidget *MainWindow::createArmPage() flowActions->addWidget(m_startJointPointLoopButton); flowActions->addWidget(m_stopJointPointLoopButton); flowLayout->addLayout(flowActions); - moveJLayout->addWidget(flowPanel, 1, 1); + moveJLayout->addWidget(flowPanel, 3); connect(addFlowStepButton, &QPushButton::clicked, this, [this]() { const QModelIndexList rows = m_jointPointTable->selectionModel()->selectedRows(); - if (rows.isEmpty()) + if (rows.isEmpty()) { + QMessageBox::information(this, QStringLiteral("添加单步节点"), + QStringLiteral("请先选择一个已记录点位。")); return; - QList sortedRows; - for (const QModelIndex &index : rows) - sortedRows.append(index.row()); - std::sort(sortedRows.begin(), sortedRows.end()); - for (int row : sortedRows) { - if (row < 0 || row >= m_recordedJointPoints.size()) - continue; - JointFlowStep step; - step.pointName = m_recordedJointPoints.at(row).name; - step.waitSeconds = m_jointPointInterval->value(); - step.loopGroup = m_jointFlowGroupEdit->text().trimmed(); - step.loopCount = step.loopGroup.isEmpty() ? 1 : m_jointFlowGroupCount->value(); - m_jointFlowSteps.append(step); } - refreshJointFlowTable(); - QSettings settings; - saveJointPrograms(settings); + const int row = rows.first().row(); + if (row >= 0 && row < m_recordedJointPoints.size()) { + const QString executionUnit = m_recordedJointPoints.at(row).name; + bool ok = false; + const QString nodeName = QInputDialog::getText( + this, QStringLiteral("新增单步节点"), QStringLiteral("节点名称"), + QLineEdit::Normal, executionUnit, &ok).trimmed(); + if (ok && !nodeName.isEmpty()) + m_jointFlowEditor->addSingleNode(nodeName, executionUnit, + m_jointPointInterval->value()); + } + }); + connect(addFlowLoopButton, &QPushButton::clicked, this, [this]() { + bool ok = false; + const QString nodeName = QInputDialog::getText( + this, QStringLiteral("新增循环节点"), QStringLiteral("节点名称"), + QLineEdit::Normal, QStringLiteral("循环"), &ok).trimmed(); + if (ok && !nodeName.isEmpty()) + m_jointFlowEditor->addLoopNode(nodeName, m_jointFlowGroupCount->value(), + m_jointPointInterval->value()); + }); + connect(insertAtRootButton, &QPushButton::clicked, + m_jointFlowEditor, &JointFlowEditor::setInsertionAtRoot); + connect(enterSelectedLoopButton, &QPushButton::clicked, this, [this]() { + if (!m_jointFlowEditor->useSelectedLoopAsInsertionParent()) { + QMessageBox::information(this, QStringLiteral("进入循环"), + QStringLiteral("请先在画布中选择一个循环节点。")); + } + }); + connect(m_jointFlowEditor, &JointFlowEditor::insertionContextChanged, + insertionContextLabel, [insertionContextLabel](const QString &description) { + insertionContextLabel->setText(QStringLiteral("添加到:%1").arg(description)); }); connect(flowDeleteButton, &QPushButton::clicked, this, [this]() { - const int row = m_jointFlowTable->currentRow(); - if (row >= 0 && row < m_jointFlowSteps.size()) - m_jointFlowSteps.removeAt(row); - refreshJointFlowTable(); + m_jointFlowEditor->removeSelectedNode(); + }); + connect(m_jointFlowEditor, &JointFlowEditor::changed, this, [this]() { QSettings settings; saveJointPrograms(settings); }); - const auto moveFlowStep = [this](int delta) { - const int row = m_jointFlowTable->currentRow(); - const int target = row + delta; - if (row < 0 || target < 0 || target >= m_jointFlowSteps.size()) - return; - m_jointFlowSteps.swap(row, target); - refreshJointFlowTable(); - m_jointFlowTable->selectRow(target); - QSettings settings; - saveJointPrograms(settings); - }; - connect(flowUpButton, &QPushButton::clicked, this, [moveFlowStep]() { moveFlowStep(-1); }); - connect(flowDownButton, &QPushButton::clicked, this, [moveFlowStep]() { moveFlowStep(1); }); - m_motionCommandTabs->addTab(moveJPage, QStringLiteral("MoveJ 关节角")); - - QWidget *moveLPage = new QWidget(m_motionCommandTabs); - QVBoxLayout *moveLLayout = new QVBoxLayout(moveLPage); - moveLLayout->setContentsMargins(16, 10, 16, 8); - moveLLayout->setSpacing(10); - QGridLayout *poseGrid = new QGridLayout; - poseGrid->setHorizontalSpacing(12); - poseGrid->setVerticalSpacing(8); + m_jointFlowDialog = new QDialog(this); + m_jointFlowDialog->setWindowTitle(QStringLiteral("机械臂点位与流程编排")); + m_jointFlowDialog->setModal(false); + m_jointFlowDialog->resize(1120, 780); + m_jointFlowDialog->setMinimumSize(860, 620); + QVBoxLayout *jointFlowDialogLayout = new QVBoxLayout(m_jointFlowDialog); + jointFlowDialogLayout->setContentsMargins(12, 12, 12, 12); + jointFlowDialogLayout->addWidget(moveJPage); const QStringList poseLabels = { QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z"), QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ") @@ -704,10 +712,21 @@ QWidget *MainWindow::createArmPage() jogTitle->setObjectName(QStringLiteral("sectionTitle")); QLabel *jogHint = new QLabel(QStringLiteral("按住执行,松开即停"), jogPanel); jogHint->setObjectName(QStringLiteral("panelSubtitle")); + QPushButton *openJointFlowButton = new QPushButton( + QStringLiteral("点位与流程…"), jogPanel); + openJointFlowButton->setObjectName(QStringLiteral("secondaryButton")); jogHeader->addWidget(jogTitle); jogHeader->addStretch(1); jogHeader->addWidget(jogHint); + jogHeader->addWidget(openJointFlowButton); jogLayout->addLayout(jogHeader); + connect(openJointFlowButton, &QPushButton::clicked, this, [this]() { + if (!m_jointFlowDialog) + return; + m_jointFlowDialog->show(); + m_jointFlowDialog->raise(); + m_jointFlowDialog->activateWindow(); + }); m_jogModeTabs = new QTabWidget(jogPanel); m_jogModeTabs->setObjectName(QStringLiteral("armJogModeTabs")); @@ -939,9 +958,9 @@ QWidget *MainWindow::createArmPage() jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); } m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度")); - ui.targetsPanel->setParent(m_jogModeTabs); - ui.targetsPanel->show(); - m_jogModeTabs->addTab(ui.targetsPanel, QStringLiteral("点位与流程")); + m_jogModeTabs->addTab(directMovePage, QStringLiteral("MoveJ 目标")); + ui.urdfTabLayout->removeWidget(ui.targetsPanel); + ui.targetsPanel->hide(); jogLayout->addWidget(m_jogModeTabs, 1); QHBoxLayout *speedLayout = new QHBoxLayout; @@ -2128,6 +2147,180 @@ QWidget *MainWindow::createRpcPage(const QString &serviceName) return new RpcServiceWidget(serviceName, m_client); } +QWidget *MainWindow::createDexHandPage() +{ + QWidget *page = new QWidget; + QVBoxLayout *layout = new QVBoxLayout(page); + layout->setContentsMargins(16, 12, 16, 14); + layout->setSpacing(10); + + QFrame *header = new QFrame(page); + header->setObjectName(QStringLiteral("panel")); + QHBoxLayout *headerLayout = new QHBoxLayout(header); + QLabel *title = new QLabel(QStringLiteral("灵巧手控制"), header); + title->setObjectName(QStringLiteral("sectionTitle")); + m_dexHandDeviceCombo = new QComboBox(header); + m_dexHandDeviceCombo->setMinimumWidth(320); + m_dexHandDeviceCombo->setToolTip(QStringLiteral("从 cmvr-es 在线设备列表自动加载")); + QPushButton *refreshButton = new QPushButton(QStringLiteral("刷新状态"), header); + m_dexHandStateLabel = new QLabel(QStringLiteral("未获取"), header); + m_dexHandStateLabel->setObjectName(QStringLiteral("panelSubtitle")); + headerLayout->addWidget(title); + headerLayout->addStretch(1); + headerLayout->addWidget(new QLabel(QStringLiteral("设备"), header)); + headerLayout->addWidget(m_dexHandDeviceCombo); + headerLayout->addWidget(refreshButton); + headerLayout->addWidget(m_dexHandStateLabel); + layout->addWidget(header); + + QSplitter *splitter = new QSplitter(Qt::Vertical, page); + splitter->setChildrenCollapsible(false); + m_dexHandStateTable = new QTableWidget(6, 8, splitter); + m_dexHandStateTable->setHorizontalHeaderLabels({ + QStringLiteral("自由度"), QStringLiteral("角度"), QStringLiteral("位置"), + QStringLiteral("速度"), QStringLiteral("受力"), QStringLiteral("电流"), + QStringLiteral("温度"), QStringLiteral("状态")}); + m_dexHandStateTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + m_dexHandStateTable->setSelectionBehavior(QAbstractItemView::SelectRows); + m_dexHandStateTable->verticalHeader()->setVisible(false); + m_dexHandStateTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_dexHandStateTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + + QFrame *tactilePanel = new QFrame(splitter); + m_dexHandTactilePanel = tactilePanel; + tactilePanel->setObjectName(QStringLiteral("panel")); + QVBoxLayout *tactileLayout = new QVBoxLayout(tactilePanel); + QHBoxLayout *tactileHeader = new QHBoxLayout; + QLabel *tactileTitle = new QLabel(QStringLiteral("食指触觉(12 × 5)"), tactilePanel); + tactileTitle->setObjectName(QStringLiteral("sectionTitle")); + m_dexHandTactileStateLabel = new QLabel(QStringLiteral("未启动"), tactilePanel); + m_dexHandTactileStateLabel->setObjectName(QStringLiteral("panelSubtitle")); + m_dexHandTactileStartButton = new QPushButton(QStringLiteral("开始触觉流"), tactilePanel); + m_dexHandTactileStopButton = new QPushButton(QStringLiteral("停止"), tactilePanel); + m_dexHandTactileStopButton->setEnabled(false); + tactileHeader->addWidget(tactileTitle); + tactileHeader->addStretch(1); + tactileHeader->addWidget(m_dexHandTactileStateLabel); + tactileHeader->addWidget(m_dexHandTactileStartButton); + tactileHeader->addWidget(m_dexHandTactileStopButton); + tactileLayout->addLayout(tactileHeader); + m_dexHandTactileHeatmap = new TactileHeatmapWidget(tactilePanel); + m_dexHandTactileHeatmap->setToolTip( + QStringLiteral("颜色表示单点法向力;数值单位 mN")); + tactileLayout->addWidget(m_dexHandTactileHeatmap); + // Keep tactile controls hidden until GetStatus explicitly reports support. + tactilePanel->hide(); + + m_dexHandCommandTabs = new QTabWidget(splitter); + m_dexHandCommandTabs->setDocumentMode(true); + const QStringList freedomNames = { + QStringLiteral("小拇指"), QStringLiteral("无名指"), QStringLiteral("中指"), + QStringLiteral("食指"), QStringLiteral("大拇指弯曲"), QStringLiteral("大拇指旋转")}; + const auto addCommandPage = [this, &freedomNames, refreshButton](const QString &titleText, + const QString &command, + QList &spins) { + QWidget *commandPage = new QWidget(m_dexHandCommandTabs); + QVBoxLayout *commandLayout = new QVBoxLayout(commandPage); + commandLayout->setContentsMargins(12, 12, 12, 12); + QLabel *hint = new QLabel( + QStringLiteral("按服务端统一归一化范围设置;100% 对应设备该参数最大值。"), + commandPage); + hint->setObjectName(QStringLiteral("panelSubtitle")); + commandLayout->addWidget(hint); + QGridLayout *grid = new QGridLayout; + grid->setHorizontalSpacing(12); + grid->setVerticalSpacing(8); + for (int index = 0; index < freedomNames.size(); ++index) { + QLabel *label = new QLabel(freedomNames.at(index), commandPage); + QDoubleSpinBox *spin = new QDoubleSpinBox(commandPage); + spin->setRange(0.0, 100.0); + spin->setDecimals(1); + spin->setSingleStep(1.0); + spin->setSuffix(QStringLiteral(" %")); + spins.append(spin); + grid->addWidget(label, index / 2, (index % 2) * 2); + grid->addWidget(spin, index / 2, (index % 2) * 2 + 1); + } + commandLayout->addLayout(grid); + QHBoxLayout *actions = new QHBoxLayout; + QPushButton *copyButton = new QPushButton(QStringLiteral("复制当前状态"), commandPage); + QPushButton *sendButton = new QPushButton(QStringLiteral("发送%1").arg(titleText), commandPage); + sendButton->setObjectName(QStringLiteral("primaryButton")); + actions->addStretch(1); + actions->addWidget(copyButton); + actions->addWidget(sendButton); + commandLayout->addLayout(actions); + const QList commandSpins = spins; + connect(copyButton, &QPushButton::clicked, this, [this, command, commandSpins]() { + const QString key = command == QStringLiteral("angle") ? QStringLiteral("angle") + : command == QStringLiteral("position") ? QStringLiteral("position") + : command == QStringLiteral("speed") ? QStringLiteral("speed") + : QStringLiteral("force"); + const double maximum = command == QStringLiteral("position") ? 2000.0 + : command == QStringLiteral("force") ? 3000.0 : 1000.0; + for (int row = 0; row < commandSpins.size() && row < m_dexHandStateTable->rowCount(); ++row) { + const int column = key == QStringLiteral("angle") ? 1 + : key == QStringLiteral("position") ? 2 + : key == QStringLiteral("speed") ? 3 : 4; + const QTableWidgetItem *item = m_dexHandStateTable->item(row, column); + if (item) + commandSpins.at(row)->setValue(item->text().toDouble() * 100.0 / maximum); + } + }); + connect(sendButton, &QPushButton::clicked, this, [this, command, commandSpins]() { + const QString deviceId = m_dexHandDeviceCombo->currentData().toString(); + if (deviceId.isEmpty()) { + QMessageBox::warning(this, QStringLiteral("灵巧手控制"), + QStringLiteral("服务端未返回可用灵巧手设备")); + return; + } + QVariantList values; + for (QDoubleSpinBox *spin : commandSpins) + values.append(spin->value() / 100.0); + m_client->requestDexHandCommand(deviceId, command, values); + }); + m_serviceButtons << refreshButton << copyButton << sendButton; + m_dexHandCommandTabs->addTab(commandPage, titleText); + }; + addCommandPage(QStringLiteral("角度"), QStringLiteral("angle"), m_dexHandAngleSpins); + addCommandPage(QStringLiteral("位置"), QStringLiteral("position"), m_dexHandPositionSpins); + addCommandPage(QStringLiteral("速度"), QStringLiteral("speed"), m_dexHandSpeedSpins); + addCommandPage(QStringLiteral("力"), QStringLiteral("force"), m_dexHandForceSpins); + + splitter->addWidget(m_dexHandStateTable); + splitter->addWidget(tactilePanel); + splitter->addWidget(m_dexHandCommandTabs); + splitter->setStretchFactor(0, 2); + splitter->setStretchFactor(1, 3); + splitter->setStretchFactor(2, 3); + layout->addWidget(splitter, 1); + + const auto refresh = [this]() { + const QString deviceId = m_dexHandDeviceCombo->currentData().toString(); + if (m_connected && !deviceId.isEmpty()) + m_client->requestDexHandStatus(deviceId); + }; + connect(refreshButton, &QPushButton::clicked, this, refresh); + connect(m_dexHandDeviceCombo, QOverload::of(&QComboBox::currentIndexChanged), + this, [this, refresh](int) { + m_client->stopDexHandTactileStream(); + refresh(); + }); + connect(m_dexHandTactileStartButton, &QPushButton::clicked, this, [this]() { + const QString deviceId = m_dexHandDeviceCombo->currentData().toString(); + if (!deviceId.isEmpty()) m_client->startDexHandTactileStream(deviceId); + }); + connect(m_dexHandTactileStopButton, &QPushButton::clicked, + m_client, &RobotClient::stopDexHandTactileStream); + m_serviceButtons << m_dexHandTactileStartButton << m_dexHandTactileStopButton; + m_dexHandRefreshTimer = new QTimer(page); + m_dexHandRefreshTimer->setInterval(1000); + connect(m_dexHandRefreshTimer, &QTimer::timeout, this, refresh); + m_dexHandRefreshTimer->start(); + + return withRpcExplorer(page, m_client, QStringLiteral("cmvr.api.DexHandService")); +} + QWidget *MainWindow::createQuicPage() { QWidget *page = new QWidget; diff --git a/src/robotclient.cpp b/src/robotclient.cpp index 80585e4..a8a7d75 100644 --- a/src/robotclient.cpp +++ b/src/robotclient.cpp @@ -37,6 +37,8 @@ #include "cmvr/api/arm_service.grpc.pb.h" #include "cmvr/api/camera_command.pb.h" #include "cmvr/api/camera_service.grpc.pb.h" +#include "cmvr/api/dexhand_command.pb.h" +#include "cmvr/api/dexhand_service.grpc.pb.h" #include "cmvr/api/configuration_service.grpc.pb.h" #include "cmvr/api/microphone_command.pb.h" #include "cmvr/api/microphone_service.grpc.pb.h" @@ -238,6 +240,7 @@ public: stopCameraStreamInternal(); stopSpeakerStreamInternal(true); stopMicrophoneStreamInternal(); + stopDexHandTactileStreamInternal(); stopAgvMapStreamInternal(); } @@ -277,6 +280,7 @@ public: } m_arm = cmvr::api::ArmService::NewStub(m_channel); m_camera = cmvr::api::CameraService::NewStub(m_channel); + m_dexHand = cmvr::api::DexHandService::NewStub(m_channel); m_system = cmvr::api::SystemService::NewStub(m_channel); m_agv = cmvr::api::AgvService::NewStub(m_channel); m_microphone = cmvr::api::MicPhoneService::NewStub(m_channel); @@ -300,6 +304,7 @@ public: stopCameraStreamInternal(); stopSpeakerStreamInternal(true); stopMicrophoneStreamInternal(); + stopDexHandTactileStreamInternal(); stopAgvMapStreamInternal(); if (m_cameraRecording) { m_cameraRecording = false; @@ -617,6 +622,136 @@ public: #endif } + void getDexHandStatus(const QString &deviceId) + { + if (!ensureConnected(QStringLiteral("Get DexHand Status")) + || !ensureDeviceId(QStringLiteral("Get DexHand Status"), deviceId)) + return; + QVariantList freedoms; + if (m_demoMode) { + for (int id = 0; id < 6; ++id) { + QVariantMap freedom; + freedom.insert(QStringLiteral("id"), id); + freedom.insert(QStringLiteral("angle"), id == 4 ? 280 : 120 + id * 70); + freedom.insert(QStringLiteral("position"), 240 + id * 120); + freedom.insert(QStringLiteral("speed"), 500); + freedom.insert(QStringLiteral("force"), 0); + freedom.insert(QStringLiteral("current"), 0); + freedom.insert(QStringLiteral("temperature"), 0); + freedom.insert(QStringLiteral("error"), 0); + freedoms.append(freedom); + } + if (dexHandStatusReceived) + dexHandStatusReceived(deviceId.trimmed(), true, true, + QStringLiteral("Demo DexHand"), freedoms); + return; + } +#ifdef CMVR_WITH_GRPC + cmvr::api::GetDexHandStateCommand::Request request; + fillHeader(request.mutable_header(), deviceId); + cmvr::api::GetDexHandStateCommand::Feedback response; + grpc::ClientContext context; + setDeadline(context, 1200); + const grpc::Status status = m_dexHand->GetStatus(&context, request, &response); + if (!status.ok() || !response.header().success()) { + emit commandFinished(QStringLiteral("Get DexHand Status"), false, + status.ok() ? QString::fromStdString(response.header().error_message()) + : QString::fromStdString(status.error_message())); + return; + } + for (const auto &item : response.state().hands()) { + QVariantMap freedom; + freedom.insert(QStringLiteral("id"), item.dof_id()); + freedom.insert(QStringLiteral("angle"), item.angle()); + freedom.insert(QStringLiteral("position"), item.position()); + freedom.insert(QStringLiteral("speed"), item.speed()); + freedom.insert(QStringLiteral("force"), item.force()); + freedom.insert(QStringLiteral("current"), item.current()); + freedom.insert(QStringLiteral("temperature"), item.temperature()); + freedom.insert(QStringLiteral("error"), item.error()); + QStringList errors; + for (const auto &message : item.error_message()) + errors.append(QString::fromStdString(message)); + freedom.insert(QStringLiteral("errors"), errors); + freedoms.append(freedom); + } + if (dexHandStatusReceived) + dexHandStatusReceived(deviceId.trimmed(), response.state().is_initialized(), + response.state().has_tactile_feedback(), + QString::fromStdString(response.state().model()), + freedoms); +#endif + } + + void setDexHandValues(const QString &deviceId, const QString &command, + const QVariantList &values) + { + const QString displayCommand = QStringLiteral("DexHand %1").arg(command); + if (!ensureConnected(displayCommand) || !ensureDeviceId(displayCommand, deviceId)) + return; + if (values.size() != 6) { + emit commandFinished(displayCommand, false, QStringLiteral("灵巧手命令必须包含 6 个自由度")); + return; + } + if (m_demoMode) { + emit commandFinished(displayCommand, true, QStringLiteral("演示命令已执行")); + getDexHandStatus(deviceId); + return; + } +#ifdef CMVR_WITH_GRPC + const auto fillValues = [&values](auto *request) { + for (int id = 0; id < values.size(); ++id) { + auto *value = request->add_values(); + value->set_id(id); + value->set_value(static_cast(values.at(id).toDouble())); + } + }; + grpc::Status status; + bool success = false; + QString error; + grpc::ClientContext context; + setDeadline(context, 2000); + if (command == QStringLiteral("angle")) { + cmvr::api::SetDexHandAnglesCommand::Request request; + fillHeader(request.mutable_header(), deviceId); fillValues(&request); + cmvr::api::SetDexHandAnglesCommand::Feedback response; + status = m_dexHand->SetDexHandAngle(&context, request, &response); + success = status.ok() && response.header().success(); + error = QString::fromStdString(response.header().error_message()); + } else if (command == QStringLiteral("position")) { + cmvr::api::SetDexHandPositionsCommand::Request request; + fillHeader(request.mutable_header(), deviceId); fillValues(&request); + cmvr::api::SetDexHandPositionsCommand::Feedback response; + status = m_dexHand->SetDexHandPos(&context, request, &response); + success = status.ok() && response.header().success(); + error = QString::fromStdString(response.header().error_message()); + } else if (command == QStringLiteral("speed")) { + cmvr::api::SetDexHandSpeedCommand::Request request; + fillHeader(request.mutable_header(), deviceId); fillValues(&request); + cmvr::api::SetDexHandSpeedCommand::Feedback response; + status = m_dexHand->SetDexHandSpeed(&context, request, &response); + success = status.ok() && response.header().success(); + error = QString::fromStdString(response.header().error_message()); + } else if (command == QStringLiteral("force")) { + cmvr::api::SetDexHandForceCommand::Request request; + fillHeader(request.mutable_header(), deviceId); fillValues(&request); + cmvr::api::SetDexHandForceCommand::Feedback response; + status = m_dexHand->SetDexHandForce(&context, request, &response); + success = status.ok() && response.header().success(); + error = QString::fromStdString(response.header().error_message()); + } else { + emit commandFinished(displayCommand, false, QStringLiteral("未知灵巧手命令")); + return; + } + if (!status.ok()) + error = QString::fromStdString(status.error_message()); + emit commandFinished(displayCommand, success, + success ? QStringLiteral("命令执行成功") : error); + if (success) + getDexHandStatus(deviceId); +#endif + } + void setArmTelemetryFrames(const QString &deviceId, const QString &baseFrame, const QString &tcpFrame) { @@ -938,6 +1073,72 @@ public: #endif } + void startDexHandTactileStream(const QString &deviceId) + { + if (!ensureConnected(QStringLiteral("DexHand Tactile Stream")) + || !ensureDeviceId(QStringLiteral("DexHand Tactile Stream"), deviceId)) + return; + stopDexHandTactileStreamInternal(); + m_dexHandTactileStop.store(false); + m_dexHandTactileRunning.store(true); +#ifdef CMVR_WITH_GRPC + const auto channel = m_channel; + m_dexHandTactileThread = std::thread([this, channel, deviceId]() { + auto stub = cmvr::api::DexHandService::NewStub(channel); + grpc::ClientContext context; + { + std::lock_guard lock(m_dexHandTactileContextMutex); + m_dexHandTactileContext = &context; + } + auto stream = stub->GetSensorDataStream(&context); + cmvr::api::GetSensorDataStreamCommand::Request request; + request.mutable_header()->set_device_id(deviceId.toStdString()); + bool started = stream && stream->Write(request); + if (stream) stream->WritesDone(); + quint64 frameCount = 0; + cmvr::api::GetSensorDataStreamCommand::Feedback response; + while (started && !m_dexHandTactileStop.load() && stream->Read(&response)) { + for (const auto &sensor : response.sensor()) { + if (sensor.finger_type() != cmvr::api::SensorData::INDEX) + continue; + QVariantList values; + values.reserve(sensor.rows() * sensor.cols()); + for (const auto &row : sensor.data()) + for (const auto value : row.values()) values.append(value); + ++frameCount; + emit dexHandTactileReceived(deviceId, sensor.rows(), sensor.cols(), + values, frameCount); + break; + } + } + grpc::Status status = stream ? stream->Finish() + : grpc::Status(grpc::StatusCode::UNKNOWN, + "cannot create tactile stream"); + { + std::lock_guard lock(m_dexHandTactileContextMutex); + m_dexHandTactileContext = nullptr; + } + const bool stopped = m_dexHandTactileStop.load(); + emit dexHandTactileStreamStateChanged( + false, stopped ? QStringLiteral("食指触觉流已停止") + : QStringLiteral("食指触觉流结束:%1") + .arg(QString::fromStdString(status.error_message()))); + m_dexHandTactileRunning.store(false); + }); + emit dexHandTactileStreamStateChanged(true, QStringLiteral("正在接收食指触觉数据")); +#else + Q_UNUSED(deviceId) + m_dexHandTactileRunning.store(false); + emit dexHandTactileStreamStateChanged(false, QStringLiteral("当前程序未编译 gRPC 支持")); +#endif + } + + void stopDexHandTactileStream() + { + stopDexHandTactileStreamInternal(); + emit dexHandTactileStreamStateChanged(false, QStringLiteral("食指触觉流已停止")); + } + void startCameraStream(const QString &cameraId, const QString &codec, const QString &mode) { @@ -2056,6 +2257,12 @@ public: std::function systemInfoReceived; std::function imageReceived; std::function cameraStatusReceived; + std::function + dexHandStatusReceived; + std::function + dexHandTactileReceived; + std::function dexHandTactileStreamStateChanged; std::function videoFrameReceivedForCamera; std::function @@ -2239,6 +2446,22 @@ private: } } + void stopDexHandTactileStreamInternal() + { + m_dexHandTactileStop.store(true); +#ifdef CMVR_WITH_GRPC + { + std::lock_guard lock(m_dexHandTactileContextMutex); + if (m_dexHandTactileContext) + m_dexHandTactileContext->TryCancel(); + } +#endif + if (m_dexHandTactileThread.joinable() + && m_dexHandTactileThread.get_id() != std::this_thread::get_id()) + m_dexHandTactileThread.join(); + m_dexHandTactileRunning.store(false); + } + void stopAgvMapStreamInternal() { m_agvMapStreamStop.store(true); @@ -3071,6 +3294,7 @@ private: std::shared_ptr m_configChannel; std::unique_ptr m_arm; std::unique_ptr m_camera; + std::unique_ptr m_dexHand; std::unique_ptr m_system; std::unique_ptr m_agv; std::unique_ptr m_microphone; @@ -3082,6 +3306,8 @@ private: std::mutex m_microphoneContextMutex; grpc::ClientContext *m_agvMapStreamContext = nullptr; std::mutex m_agvMapStreamContextMutex; + grpc::ClientContext *m_dexHandTactileContext = nullptr; + std::mutex m_dexHandTactileContextMutex; #endif struct SpeakerAudioFrame { @@ -3124,6 +3350,9 @@ private: std::atomic m_microphoneFrames{0}; std::atomic m_microphoneBytes{0}; std::thread m_microphoneStreamThread; + std::atomic m_dexHandTactileRunning{false}; + std::atomic m_dexHandTactileStop{false}; + std::thread m_dexHandTactileThread; std::atomic m_agvMapStreamRunning{false}; std::atomic m_agvMapStreamStop{false}; std::thread m_agvMapStreamThread; @@ -3190,6 +3419,29 @@ RobotClient::RobotClient(QObject *parent) emit cameraStatusReceived(cameraId, state); }, Qt::QueuedConnection); }; + m_worker->dexHandStatusReceived = + [this](const QString &deviceId, bool initialized, bool hasTactileFeedback, + const QString &model, + const QVariantList &freedoms) { + QMetaObject::invokeMethod(this, [this, deviceId, initialized, + hasTactileFeedback, model, freedoms]() { + emit dexHandStatusReceived(deviceId, initialized, + hasTactileFeedback, model, freedoms); + }, Qt::QueuedConnection); + }; + m_worker->dexHandTactileReceived = + [this](const QString &deviceId, int rows, int cols, + const QVariantList &values, quint64 frameCount) { + QMetaObject::invokeMethod(this, [this, deviceId, rows, cols, values, frameCount]() { + emit dexHandTactileReceived(deviceId, rows, cols, values, frameCount); + }, Qt::QueuedConnection); + }; + m_worker->dexHandTactileStreamStateChanged = + [this](bool running, const QString &detail) { + QMetaObject::invokeMethod(this, [this, running, detail]() { + emit dexHandTactileStreamStateChanged(running, detail); + }, Qt::QueuedConnection); + }; const auto queueVideoFrame = [this](const QString &cameraId, const VideoFrame &frame, const QString &detail) { @@ -3336,6 +3588,14 @@ RobotClient::RobotClient(QObject *parent) m_worker, &BackendWorker::armCalibrateZero); connect(this, &RobotClient::snapshotRequested, m_worker, &BackendWorker::snapshot); connect(this, &RobotClient::cameraStatusRequested, m_worker, &BackendWorker::getCameraStatus); + connect(this, &RobotClient::dexHandStatusRequested, + m_worker, &BackendWorker::getDexHandStatus); + connect(this, &RobotClient::dexHandCommandRequested, + m_worker, &BackendWorker::setDexHandValues); + connect(this, &RobotClient::dexHandTactileStreamStartRequested, + m_worker, &BackendWorker::startDexHandTactileStream); + connect(this, &RobotClient::dexHandTactileStreamStopRequested, + m_worker, &BackendWorker::stopDexHandTactileStream); connect(this, &RobotClient::cameraStreamStartRequested, m_worker, &BackendWorker::startCameraStream); connect(this, &RobotClient::cameraStreamCodecRequested, m_worker, &BackendWorker::setCameraStreamCodec); @@ -3463,6 +3723,25 @@ void RobotClient::requestCameraStatus(const QString &cameraId) { emit cameraStatusRequested(cameraId); } +void RobotClient::requestDexHandStatus(const QString &deviceId) +{ + emit dexHandStatusRequested(deviceId); +} +void RobotClient::requestDexHandCommand(const QString &deviceId, const QString &command, + const QVariantList &values) +{ + emit dexHandCommandRequested(deviceId, command, values); +} + +void RobotClient::startDexHandTactileStream(const QString &deviceId) +{ + emit dexHandTactileStreamStartRequested(deviceId); +} + +void RobotClient::stopDexHandTactileStream() +{ + emit dexHandTactileStreamStopRequested(); +} void RobotClient::startCameraStream(const QString &cameraId, const QString &codec, const QString &mode) { diff --git a/src/robotclient.h b/src/robotclient.h index c32732f..bfda40f 100644 --- a/src/robotclient.h +++ b/src/robotclient.h @@ -48,6 +48,11 @@ public slots: void requestArmCalibrateZero(const QString &deviceId, const QString &jointName); void requestSnapshot(const QString &cameraId); void requestCameraStatus(const QString &cameraId); + void requestDexHandStatus(const QString &deviceId); + void requestDexHandCommand(const QString &deviceId, const QString &command, + const QVariantList &values); + void startDexHandTactileStream(const QString &deviceId); + void stopDexHandTactileStream(); void startCameraStream(const QString &cameraId, const QString &codec, const QString &mode = QStringLiteral("rgb")); void setCameraStreamCodec(const QString &codec); @@ -109,6 +114,11 @@ signals: void armCalibrateZeroRequested(const QString &deviceId, const QString &jointName); void snapshotRequested(const QString &cameraId); void cameraStatusRequested(const QString &cameraId); + void dexHandStatusRequested(const QString &deviceId); + void dexHandCommandRequested(const QString &deviceId, const QString &command, + const QVariantList &values); + void dexHandTactileStreamStartRequested(const QString &deviceId); + void dexHandTactileStreamStopRequested(); void cameraStreamStartRequested(const QString &cameraId, const QString &codec, const QString &mode); void cameraStreamCodecRequested(const QString &codec); @@ -161,6 +171,13 @@ signals: void systemInfoReceived(const QVariantMap &info); void imageReceived(const QImage &image, const QString &detail); void cameraStatusReceived(const QString &cameraId, const QVariantMap &state); + void dexHandStatusReceived(const QString &deviceId, bool initialized, + bool hasTactileFeedback, + const QString &model, + const QVariantList &freedoms); + void dexHandTactileReceived(const QString &deviceId, int rows, int cols, + const QVariantList &values, quint64 frameCount); + void dexHandTactileStreamStateChanged(bool running, const QString &detail); void videoFrameReceived(const QString &cameraId, const VideoFrame &frame, const QString &detail); void cameraStreamStateChanged(const QString &cameraId, bool running, diff --git a/src/tactileheatmapwidget.cpp b/src/tactileheatmapwidget.cpp new file mode 100644 index 0000000..109de46 --- /dev/null +++ b/src/tactileheatmapwidget.cpp @@ -0,0 +1,87 @@ +#include "tactileheatmapwidget.h" + +#include +#include +#include +#include + +#include + +namespace { +QColor forceColor(double normalized) +{ + normalized = qBound(0.0, normalized, 1.0); + if (normalized < 0.25) + return QColor::fromRgbF(0.10, 0.32 + normalized * 1.6, 0.88); + if (normalized < 0.55) { + const double t = (normalized - 0.25) / 0.30; + return QColor::fromRgbF(0.10 + t * 0.85, 0.72 + t * 0.20, 0.88 - t * 0.72); + } + const double t = (normalized - 0.55) / 0.45; + return QColor::fromRgbF(0.95, 0.92 - t * 0.78, 0.16 - t * 0.08); +} +} + +TactileHeatmapWidget::TactileHeatmapWidget(QWidget *parent) + : QWidget(parent) +{ + setMinimumSize(260, 360); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} + +void TactileHeatmapWidget::setTactileData(int rows, int cols, + const QVector &values) +{ + if (rows <= 0 || cols <= 0 || values.size() < rows * cols) + return; + m_rows = rows; + m_cols = cols; + m_values = values.mid(0, rows * cols); + update(); +} + +void TactileHeatmapWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.fillRect(rect(), QColor(20, 25, 36)); + + const int legendWidth = 22; + const QRectF gridArea = rect().adjusted(18, 18, -50, -18); + const double cellWidth = gridArea.width() / m_cols; + const double cellHeight = gridArea.height() / m_rows; + const int peak = m_values.isEmpty() + ? 0 : *std::max_element(m_values.cbegin(), m_values.cend()); + const double scale = qMax(25, peak); + + for (int row = 0; row < m_rows; ++row) { + // AP001 reports matrix rows from the finger base towards the tip. + // Draw the tip at the top of the widget to match the physical finger. + const int sourceRow = m_rows - 1 - row; + for (int col = 0; col < m_cols; ++col) { + const int value = m_values.value(sourceRow * m_cols + col); + QRectF cell(gridArea.left() + col * cellWidth + 2, + gridArea.top() + row * cellHeight + 2, + cellWidth - 4, cellHeight - 4); + painter.setPen(QPen(QColor(255, 255, 255, 35), 1)); + painter.setBrush(forceColor(value / scale)); + painter.drawRoundedRect(cell, 5, 5); + painter.setPen(value / scale > 0.65 ? Qt::white : QColor(235, 242, 255)); + painter.drawText(cell, Qt::AlignCenter, QString::number(value)); + } + } + + const QRectF legend(gridArea.right() + 15, gridArea.top(), legendWidth, + gridArea.height()); + QLinearGradient gradient(legend.bottomLeft(), legend.topLeft()); + gradient.setColorAt(0.0, forceColor(0.0)); + gradient.setColorAt(0.5, forceColor(0.5)); + gradient.setColorAt(1.0, forceColor(1.0)); + painter.fillRect(legend, gradient); + painter.setPen(QColor(220, 228, 240)); + painter.drawText(QRectF(legend.right() + 3, legend.top() - 7, 30, 18), + Qt::AlignLeft, QString::number(peak)); + painter.drawText(QRectF(legend.right() + 3, legend.bottom() - 10, 30, 18), + Qt::AlignLeft, QStringLiteral("0")); +} diff --git a/src/tactileheatmapwidget.h b/src/tactileheatmapwidget.h new file mode 100644 index 0000000..60517cc --- /dev/null +++ b/src/tactileheatmapwidget.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +class TactileHeatmapWidget final : public QWidget +{ +public: + explicit TactileHeatmapWidget(QWidget *parent = nullptr); + + void setTactileData(int rows, int cols, const QVector &values); + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + int m_rows = 12; + int m_cols = 5; + QVector m_values = QVector(60, 0); +};