Merge Qt camera and arm workflow updates
This commit is contained in:
commit
ce6935e8b0
@ -246,6 +246,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 \
|
||||
@ -260,6 +262,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 \
|
||||
|
||||
@ -48,6 +48,7 @@ message CameraState {
|
||||
int32 fps = 7;
|
||||
int32 width = 8;
|
||||
int32 height = 9;
|
||||
string codec = 10;
|
||||
}
|
||||
|
||||
message GetCameraStateCommand {
|
||||
|
||||
@ -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;//所有传感器的数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
658
src/jointfloweditor.cpp
Normal file
658
src/jointfloweditor.cpp
Normal file
@ -0,0 +1,658 @@
|
||||
#include "jointfloweditor.h"
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QFormLayout>
|
||||
#include <QJsonObject>
|
||||
#include <QLineEdit>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QPushButton>
|
||||
#include <QScrollBar>
|
||||
#include <QSpinBox>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QUuid>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
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<void(const QString &, const QPointF &)> moved,
|
||||
std::function<void(const QString &)> edit,
|
||||
std::function<void(const QString &)> 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<void(const QString &, const QPointF &)> m_moved;
|
||||
std::function<void(const QString &)> m_edit;
|
||||
std::function<void(const QString &)> 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::ExecutionStep> JointFlowEditor::expandedSteps(
|
||||
QString *error, int maximumSteps) const
|
||||
{
|
||||
QList<ExecutionStep> result;
|
||||
for (const Node *node : childrenOf(QString())) {
|
||||
if (!appendExecution(*node, result, error, maximumSteps))
|
||||
return {};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JointFlowEditor::appendExecution(const Node &node, QList<ExecutionStep> &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<const Node *> 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<Node> 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<const JointFlowEditor::Node *> JointFlowEditor::childrenOf(const QString &parentId) const
|
||||
{
|
||||
QList<const Node *> 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<Node *> 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<QString, FlowCardItem *> 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<const Node *> 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));
|
||||
}
|
||||
78
src/jointfloweditor.h
Normal file
78
src/jointfloweditor.h
Normal file
@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
#include <QWidget>
|
||||
|
||||
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<ExecutionStep> 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<const Node *> 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<ExecutionStep> &steps,
|
||||
QString *error, int maximumSteps) const;
|
||||
|
||||
QList<Node> m_nodes;
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsView *m_view = nullptr;
|
||||
QString m_activeNodeId;
|
||||
QString m_selectedNodeId;
|
||||
QString m_insertionParentId;
|
||||
QStringList m_availablePointNames;
|
||||
};
|
||||
96
src/main.cpp
96
src/main.cpp
@ -4,6 +4,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLineEdit>
|
||||
@ -11,8 +12,94 @@
|
||||
#include <QTimer>
|
||||
#include <QTextStream>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
namespace {
|
||||
|
||||
LONG WINAPI writeCrashDump(EXCEPTION_POINTERS *exceptionPointers)
|
||||
{
|
||||
static LONG handlingCrash = 0;
|
||||
if (InterlockedCompareExchange(&handlingCrash, 1, 0) != 0)
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
|
||||
wchar_t executablePath[MAX_PATH] = {};
|
||||
GetModuleFileNameW(nullptr, executablePath, MAX_PATH);
|
||||
wchar_t *lastSeparator = wcsrchr(executablePath, L'\\');
|
||||
if (lastSeparator)
|
||||
*lastSeparator = L'\0';
|
||||
|
||||
wchar_t dumpDirectory[MAX_PATH] = {};
|
||||
_snwprintf(dumpDirectory, MAX_PATH - 1, L"%ls\\crash_dumps", executablePath);
|
||||
CreateDirectoryW(dumpDirectory, nullptr);
|
||||
|
||||
SYSTEMTIME time = {};
|
||||
GetLocalTime(&time);
|
||||
wchar_t baseName[96] = {};
|
||||
_snwprintf(baseName, 95,
|
||||
L"CmvrControlStation_%04u%02u%02u_%02u%02u%02u_%lu",
|
||||
time.wYear, time.wMonth, time.wDay,
|
||||
time.wHour, time.wMinute, time.wSecond,
|
||||
GetCurrentProcessId());
|
||||
|
||||
wchar_t dumpPath[MAX_PATH] = {};
|
||||
_snwprintf(dumpPath, MAX_PATH - 1, L"%ls\\%ls.dmp", dumpDirectory, baseName);
|
||||
HANDLE dumpFile = CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (dumpFile != INVALID_HANDLE_VALUE) {
|
||||
MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = {};
|
||||
exceptionInfo.ThreadId = GetCurrentThreadId();
|
||||
exceptionInfo.ExceptionPointers = exceptionPointers;
|
||||
exceptionInfo.ClientPointers = FALSE;
|
||||
const MINIDUMP_TYPE dumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithDataSegs | MiniDumpWithHandleData |
|
||||
MiniDumpWithThreadInfo | MiniDumpWithIndirectlyReferencedMemory);
|
||||
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile,
|
||||
dumpType, &exceptionInfo, nullptr, nullptr);
|
||||
FlushFileBuffers(dumpFile);
|
||||
CloseHandle(dumpFile);
|
||||
}
|
||||
|
||||
wchar_t summaryPath[MAX_PATH] = {};
|
||||
_snwprintf(summaryPath, MAX_PATH - 1, L"%ls\\%ls.txt", dumpDirectory, baseName);
|
||||
HANDLE summaryFile = CreateFileW(summaryPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (summaryFile != INVALID_HANDLE_VALUE) {
|
||||
const DWORD exceptionCode = exceptionPointers && exceptionPointers->ExceptionRecord
|
||||
? exceptionPointers->ExceptionRecord->ExceptionCode : 0;
|
||||
const void *exceptionAddress = exceptionPointers && exceptionPointers->ExceptionRecord
|
||||
? exceptionPointers->ExceptionRecord->ExceptionAddress : nullptr;
|
||||
char summary[512] = {};
|
||||
const int length = _snprintf(summary, sizeof(summary) - 1,
|
||||
"Application: CmvrControlStation.exe\r\n"
|
||||
"Timestamp: %04u-%02u-%02u %02u:%02u:%02u\r\n"
|
||||
"Exception code: 0x%08lX\r\n"
|
||||
"Exception address: %p\r\n"
|
||||
"Process ID: %lu\r\nThread ID: %lu\r\n"
|
||||
"Dump: %ls\r\n",
|
||||
time.wYear, time.wMonth, time.wDay,
|
||||
time.wHour, time.wMinute, time.wSecond,
|
||||
exceptionCode, exceptionAddress,
|
||||
GetCurrentProcessId(), GetCurrentThreadId(), dumpPath);
|
||||
DWORD written = 0;
|
||||
if (length > 0)
|
||||
WriteFile(summaryFile, summary, static_cast<DWORD>(length), &written, nullptr);
|
||||
FlushFileBuffers(summaryFile);
|
||||
CloseHandle(summaryFile);
|
||||
}
|
||||
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
SetUnhandledExceptionFilter(writeCrashDump);
|
||||
#endif
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName(QStringLiteral("CMVR Control Station"));
|
||||
app.setOrganizationName(QStringLiteral("CMVR"));
|
||||
@ -117,16 +204,17 @@ int main(int argc, char *argv[])
|
||||
QMetaObject::invokeMethod(&window, "selectPage", Qt::DirectConnection,
|
||||
Q_ARG(int, 2));
|
||||
QCheckBox *demoCheck = window.findChild<QCheckBox *>(QStringLiteral("demoCheck"));
|
||||
QLineEdit *cameraIdEdit =
|
||||
window.findChild<QLineEdit *>(QStringLiteral("cameraIdEdit"));
|
||||
QComboBox *cameraDeviceCombo =
|
||||
window.findChild<QComboBox *>(QStringLiteral("cameraDeviceCombo"));
|
||||
QPushButton *connectButton =
|
||||
window.findChild<QPushButton *>(QStringLiteral("connectButton"));
|
||||
if (!demoCheck || !cameraIdEdit || !connectButton) {
|
||||
if (!demoCheck || !cameraDeviceCombo || !connectButton) {
|
||||
finishSmoke(3, QStringLiteral("未找到相机自检所需控件"));
|
||||
return;
|
||||
}
|
||||
demoCheck->setChecked(true);
|
||||
cameraIdEdit->setText(QStringLiteral("demo_camera_1,demo_camera_2"));
|
||||
cameraDeviceCombo->addItem(QStringLiteral("demo_camera_1"),
|
||||
QStringLiteral("demo_camera_1"));
|
||||
appendCameraSmokeLog(QStringLiteral("STEP 等待应用自动连接 Demo"));
|
||||
|
||||
QTimer::singleShot(1500, &window,
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
#include "tactileheatmapwidget.h"
|
||||
#include "jointfloweditor.h"
|
||||
#include "videorenderwidget.h"
|
||||
|
||||
#include "agvmapviewwidget.h"
|
||||
@ -30,6 +32,7 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QImage>
|
||||
#include <QKeyEvent>
|
||||
#include <QJsonDocument>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListView>
|
||||
@ -412,7 +415,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")));
|
||||
@ -438,7 +441,25 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
break;
|
||||
case 2:
|
||||
pageIndex = 2;
|
||||
if (m_cameraIdEdit) m_cameraIdEdit->setText(deviceId);
|
||||
if (m_cameraDeviceCombo) {
|
||||
int index = m_cameraDeviceCombo->findData(deviceId);
|
||||
if (index < 0) {
|
||||
m_cameraDeviceCombo->addItem(deviceId, deviceId);
|
||||
index = m_cameraDeviceCombo->count() - 1;
|
||||
}
|
||||
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;
|
||||
@ -452,9 +473,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;
|
||||
@ -512,6 +530,36 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(m_client, &RobotClient::systemStatusReceived, this, &MainWindow::updateSystemStatus);
|
||||
connect(m_client, &RobotClient::systemInfoReceived, this, &MainWindow::updateSystemInfo);
|
||||
connect(m_client, &RobotClient::imageReceived, this, &MainWindow::updateImage);
|
||||
connect(m_client, &RobotClient::cameraStatusReceived, this,
|
||||
[this](const QString &cameraId, const QVariantMap &state) {
|
||||
if (!m_cameraDeviceCombo || !m_cameraCodecCombo
|
||||
|| m_cameraDeviceCombo->currentData().toString() != cameraId) {
|
||||
return;
|
||||
}
|
||||
const QString codec = state.value(QStringLiteral("codec")).toString().toLower();
|
||||
if (codec.isEmpty())
|
||||
return;
|
||||
const bool isH265 = codec.contains(QStringLiteral("265"))
|
||||
|| codec.contains(QStringLiteral("hevc"));
|
||||
{
|
||||
const QSignalBlocker blocker(m_cameraCodecCombo);
|
||||
m_cameraCodecCombo->setCurrentIndex(isH265 ? 1 : 0);
|
||||
}
|
||||
m_cameraCodecCombo->setToolTip(
|
||||
QStringLiteral("服务端当前编码器:%1").arg(codec.toUpper()));
|
||||
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);
|
||||
@ -1276,6 +1324,7 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
|
||||
byName.insert(name, joint);
|
||||
jointPositions.insert(name, joint.value(QStringLiteral("position")).toDouble());
|
||||
}
|
||||
m_latestArmJointPositions = jointPositions;
|
||||
|
||||
const qint64 nowMs = QDateTime::currentMSecsSinceEpoch();
|
||||
const double deltaSeconds = m_lastArmTelemetryMs > 0
|
||||
@ -1354,7 +1403,25 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
|
||||
if (row == 0 && m_trend)
|
||||
m_trend->appendSample(position, velocity);
|
||||
}
|
||||
m_lastArmTelemetryMs = nowMs;
|
||||
|
||||
const QList<QTableWidget *> motionTables = {m_leftMotionTable, m_motionTable};
|
||||
for (QTableWidget *table : motionTables) {
|
||||
if (!table)
|
||||
continue;
|
||||
for (int row = 0; row < table->rowCount(); ++row) {
|
||||
const QTableWidgetItem *nameItem = table->item(row, 0);
|
||||
if (!nameItem)
|
||||
continue;
|
||||
const QVariantMap joint = byName.value(nameItem->text());
|
||||
if (!joint.isEmpty()) {
|
||||
const double position = joint.value(QStringLiteral("position")).toDouble();
|
||||
table->item(row, 1)->setText(QStringLiteral("%1°").arg(
|
||||
qRadiansToDegrees(position),
|
||||
0, 'f', 2));
|
||||
table->item(row, 2)->setText(QString::number(position, 'f', 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pose.isEmpty()) {
|
||||
m_latestArmPose = pose;
|
||||
@ -1522,9 +1589,6 @@ void MainWindow::updateSystemStatus(double cpu, double memory, double disk,
|
||||
m_memoryValue->setText(QString::number(memory, 'f', 0));
|
||||
m_diskValue->setText(QString::number(disk, 'f', 0));
|
||||
m_deviceValue->setText(QString::number(devices.size()));
|
||||
if (!m_armSideCombo)
|
||||
return;
|
||||
|
||||
const QString previousId = m_armIdEdit && !m_armIdEdit->text().trimmed().isEmpty()
|
||||
? m_armIdEdit->text().trimmed() : m_armSideCombo->currentData().toString();
|
||||
QString firstArmId;
|
||||
@ -1572,6 +1636,70 @@ void MainWindow::updateSystemStatus(double cpu, double memory, double disk,
|
||||
setArmTelemetryEnabled(true);
|
||||
}
|
||||
|
||||
if (m_cameraDeviceCombo) {
|
||||
const QString previousCameraId = m_cameraDeviceCombo->currentData().toString();
|
||||
{
|
||||
const QSignalBlocker blocker(m_cameraDeviceCombo);
|
||||
m_cameraDeviceCombo->clear();
|
||||
for (const QVariant &value : devices) {
|
||||
const QVariantMap device = value.toMap();
|
||||
if (device.value(QStringLiteral("type")).toInt() != 2)
|
||||
continue;
|
||||
const QString deviceId = device.value(QStringLiteral("deviceId")).toString();
|
||||
if (deviceId.isEmpty())
|
||||
continue;
|
||||
const QString vendor = device.value(QStringLiteral("vendor")).toString();
|
||||
const QString driver = device.value(QStringLiteral("driverType")).toString();
|
||||
const QString detail = !vendor.isEmpty() ? vendor : driver;
|
||||
m_cameraDeviceCombo->addItem(
|
||||
detail.isEmpty() ? deviceId
|
||||
: QStringLiteral("%1 · %2").arg(deviceId, detail),
|
||||
deviceId);
|
||||
}
|
||||
int index = m_cameraDeviceCombo->findData(previousCameraId);
|
||||
if (index < 0 && m_cameraDeviceCombo->count() > 0)
|
||||
index = 0;
|
||||
if (index >= 0)
|
||||
m_cameraDeviceCombo->setCurrentIndex(index);
|
||||
}
|
||||
m_cameraDeviceCombo->setEnabled(!m_cameraStreaming && !m_cameraRecording
|
||||
&& m_cameraDeviceCombo->count() > 0);
|
||||
if (!m_cameraStreaming
|
||||
&& previousCameraId != m_cameraDeviceCombo->currentData().toString())
|
||||
rebuildCameraPreviewGrid(configuredCameraIds());
|
||||
const QString cameraId = m_cameraDeviceCombo->currentData().toString();
|
||||
if (!cameraId.isEmpty()
|
||||
&& (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)
|
||||
@ -1584,6 +1712,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<int> 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)
|
||||
{
|
||||
m_latestAgvState = state;
|
||||
@ -1797,7 +2013,8 @@ void MainWindow::updateCameraRecordingState(bool recording, const QString &detai
|
||||
m_cameraRecordButton->style()->unpolish(m_cameraRecordButton);
|
||||
m_cameraRecordButton->style()->polish(m_cameraRecordButton);
|
||||
m_cameraRecordPathEdit->setEnabled(!recording);
|
||||
m_cameraIdEdit->setEnabled(!m_cameraStreaming && !recording);
|
||||
m_cameraDeviceCombo->setEnabled(!m_cameraStreaming && !recording
|
||||
&& m_cameraDeviceCombo->count() > 0);
|
||||
m_cameraRecordStateLabel->setText(recording ? QStringLiteral("录像中")
|
||||
: QStringLiteral("未录像"));
|
||||
m_cameraRecordStateLabel->setToolTip(detail);
|
||||
@ -1841,6 +2058,19 @@ void MainWindow::handleCommand(const QString &command, bool success, const QStri
|
||||
|
||||
appendLog(success ? QStringLiteral("OK") : QStringLiteral("ERROR"),
|
||||
QStringLiteral("%1 · %2").arg(command, detail));
|
||||
if (command == QStringLiteral("MoveJ") && m_jointPointMovePending) {
|
||||
m_jointPointMovePending = false;
|
||||
if (!success) {
|
||||
stopJointPointLoop(QStringLiteral("MoveJ 执行失败:%1").arg(detail));
|
||||
} else if (m_jointPointLoopActive) {
|
||||
const int completedIndex = m_jointPointLoopCursor - 1;
|
||||
const double waitSeconds = completedIndex >= 0
|
||||
&& completedIndex < m_jointPointExecutionWaits.size()
|
||||
? m_jointPointExecutionWaits.at(completedIndex) : 0.0;
|
||||
const int delayMs = qRound(waitSeconds * 1000.0);
|
||||
QTimer::singleShot(delayMs, this, &MainWindow::advanceJointPointLoop);
|
||||
}
|
||||
}
|
||||
if (!success)
|
||||
m_connectionText->setToolTip(detail);
|
||||
}
|
||||
@ -1875,12 +2105,254 @@ void MainWindow::appendLog(const QString &level, const QString &message)
|
||||
void MainWindow::sendMoveJ()
|
||||
{
|
||||
QVariantList positions;
|
||||
for (QDoubleSpinBox *spin : m_targetSpins)
|
||||
const bool leftArm = m_armSideCombo
|
||||
&& m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
const QList<QDoubleSpinBox *> &spins = leftArm
|
||||
? m_leftTargetSpins : m_rightTargetSpins;
|
||||
for (QDoubleSpinBox *spin : spins)
|
||||
positions.append(qDegreesToRadians(spin->value()));
|
||||
m_client->requestMoveJ(m_armIdEdit->text().trimmed(), positions,
|
||||
m_velocitySpin->value(), m_accelerationSpin->value());
|
||||
}
|
||||
|
||||
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);
|
||||
QStringList values;
|
||||
for (double position : point.positions)
|
||||
values.append(QString::number(position, 'f', 6));
|
||||
m_jointPointTable->setItem(row, 0, new QTableWidgetItem(point.name));
|
||||
m_jointPointTable->setItem(row, 1, new QTableWidgetItem(
|
||||
point.side == QStringLiteral("left") ? QStringLiteral("左臂")
|
||||
: QStringLiteral("右臂")));
|
||||
m_jointPointTable->setItem(row, 2, new QTableWidgetItem(point.deviceId));
|
||||
m_jointPointTable->setItem(row, 3, new QTableWidgetItem(
|
||||
QString::number(point.positions.size())));
|
||||
QTableWidgetItem *positionsItem = new QTableWidgetItem(values.join(QStringLiteral(", ")));
|
||||
positionsItem->setToolTip(QStringLiteral("关节顺序:%1\n角度(rad):%2")
|
||||
.arg(point.jointNames.join(QStringLiteral(", ")),
|
||||
values.join(QStringLiteral(", "))));
|
||||
m_jointPointTable->setItem(row, 4, positionsItem);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::refreshJointFlowTable()
|
||||
{
|
||||
if (m_jointFlowEditor)
|
||||
m_jointFlowEditor->update();
|
||||
}
|
||||
|
||||
void MainWindow::recordCurrentJointPoint()
|
||||
{
|
||||
const QString name = m_jointPointNameEdit
|
||||
? m_jointPointNameEdit->text().trimmed() : QString();
|
||||
if (name.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
|
||||
QStringLiteral("请输入动作名称。"));
|
||||
return;
|
||||
}
|
||||
for (const RecordedJointPoint &point : m_recordedJointPoints) {
|
||||
if (point.name.compare(name, Qt::CaseInsensitive) == 0) {
|
||||
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
|
||||
QStringLiteral("动作名称“%1”已存在,请使用其他名称。")
|
||||
.arg(name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const bool leftArm = m_armSideCombo
|
||||
&& m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
const QStringList jointNames = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
|
||||
if (jointNames.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
|
||||
QStringLiteral("当前 URDF 中没有该机械臂的可运动关节。"));
|
||||
return;
|
||||
}
|
||||
|
||||
RecordedJointPoint point;
|
||||
point.name = name;
|
||||
point.side = leftArm ? QStringLiteral("left") : QStringLiteral("right");
|
||||
point.deviceId = m_armIdEdit->text().trimmed();
|
||||
point.jointNames = jointNames;
|
||||
QStringList missing;
|
||||
for (const QString &jointName : jointNames) {
|
||||
if (!m_latestArmJointPositions.contains(jointName)) {
|
||||
missing.append(jointName);
|
||||
continue;
|
||||
}
|
||||
point.positions.append(m_latestArmJointPositions.value(jointName));
|
||||
}
|
||||
if (!missing.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
|
||||
QStringLiteral("尚未收到以下关节的实时角度:\n%1\n\n请先启动遥测。")
|
||||
.arg(missing.join(QStringLiteral(", "))));
|
||||
return;
|
||||
}
|
||||
if (point.deviceId.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
|
||||
QStringLiteral("当前 Device ID 为空。"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_recordedJointPoints.append(point);
|
||||
refreshRecordedJointPoints();
|
||||
QSettings settings;
|
||||
saveJointPrograms(settings);
|
||||
m_jointPointNameEdit->clear();
|
||||
m_jointPointTable->selectRow(m_recordedJointPoints.size() - 1);
|
||||
appendLog(QStringLiteral("OK"),
|
||||
QStringLiteral("已记录动作“%1”,%2 个关节(rad)")
|
||||
.arg(point.name).arg(point.positions.size()));
|
||||
}
|
||||
|
||||
void MainWindow::executeSelectedJointPoint()
|
||||
{
|
||||
if (m_jointPointLoopActive || m_jointPointMovePending)
|
||||
return;
|
||||
const QModelIndexList selected = m_jointPointTable
|
||||
? m_jointPointTable->selectionModel()->selectedRows() : QModelIndexList();
|
||||
if (selected.isEmpty()) {
|
||||
QMessageBox::information(this, QStringLiteral("执行关节点位"),
|
||||
QStringLiteral("请先选择一个已记录动作。"));
|
||||
return;
|
||||
}
|
||||
const int row = selected.first().row();
|
||||
if (row < 0 || row >= m_recordedJointPoints.size())
|
||||
return;
|
||||
const RecordedJointPoint &point = m_recordedJointPoints.at(row);
|
||||
QVariantList positions;
|
||||
for (double position : point.positions)
|
||||
positions.append(position);
|
||||
m_jointPointMovePending = true;
|
||||
m_client->requestMoveJ(point.deviceId, positions,
|
||||
m_velocitySpin->value(), m_accelerationSpin->value());
|
||||
if (m_jointPointLoopStatus)
|
||||
m_jointPointLoopStatus->setText(QStringLiteral("执行:%1").arg(point.name));
|
||||
}
|
||||
|
||||
void MainWindow::startJointPointLoop()
|
||||
{
|
||||
if (m_jointPointLoopActive || m_jointPointMovePending)
|
||||
return;
|
||||
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)
|
||||
return row;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
QString flowError;
|
||||
const QList<JointFlowEditor::ExecutionStep> 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;
|
||||
}
|
||||
m_jointPointLoopRows.append(row);
|
||||
m_jointPointExecutionWaits.append(step.intervalSeconds);
|
||||
m_jointPointExecutionNodeIds.append(step.nodeId);
|
||||
}
|
||||
if (m_jointPointLoopRows.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("执行自定义流程"),
|
||||
QStringLiteral("流程引用的点位已不存在。"));
|
||||
return;
|
||||
}
|
||||
m_jointPointLoopCursor = 0;
|
||||
m_jointPointLoopTarget = m_jointPointLoopRows.size();
|
||||
m_jointPointLoopActive = true;
|
||||
m_startJointPointLoopButton->setEnabled(false);
|
||||
m_runJointPointButton->setEnabled(false);
|
||||
m_deleteJointPointButton->setEnabled(false);
|
||||
m_recordJointPointButton->setEnabled(false);
|
||||
m_stopJointPointLoopButton->setEnabled(true);
|
||||
m_jointPointTable->setEnabled(false);
|
||||
advanceJointPointLoop();
|
||||
}
|
||||
|
||||
void MainWindow::advanceJointPointLoop()
|
||||
{
|
||||
if (!m_jointPointLoopActive || m_jointPointMovePending)
|
||||
return;
|
||||
if (m_jointPointLoopCursor >= m_jointPointLoopRows.size()) {
|
||||
stopJointPointLoop(QStringLiteral("循环执行完成"));
|
||||
return;
|
||||
}
|
||||
const int executionIndex = m_jointPointLoopCursor;
|
||||
const int row = m_jointPointLoopRows.at(m_jointPointLoopCursor++);
|
||||
if (row < 0 || row >= m_recordedJointPoints.size()) {
|
||||
stopJointPointLoop(QStringLiteral("点位列表已发生变化"));
|
||||
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);
|
||||
m_jointPointMovePending = true;
|
||||
m_jointPointLoopStatus->setText(QStringLiteral("步骤 %1/%2 · %3")
|
||||
.arg(executionIndex + 1).arg(m_jointPointLoopRows.size()).arg(point.name));
|
||||
m_client->requestMoveJ(point.deviceId, positions,
|
||||
m_velocitySpin->value(), m_accelerationSpin->value());
|
||||
}
|
||||
|
||||
void MainWindow::stopJointPointLoop(const QString &reason)
|
||||
{
|
||||
const bool wasActive = m_jointPointLoopActive;
|
||||
m_jointPointLoopActive = false;
|
||||
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)
|
||||
m_runJointPointButton->setEnabled(true);
|
||||
if (m_deleteJointPointButton)
|
||||
m_deleteJointPointButton->setEnabled(true);
|
||||
if (m_recordJointPointButton)
|
||||
m_recordJointPointButton->setEnabled(true);
|
||||
if (m_stopJointPointLoopButton)
|
||||
m_stopJointPointLoopButton->setEnabled(false);
|
||||
if (m_jointPointTable)
|
||||
m_jointPointTable->setEnabled(true);
|
||||
if (m_jointPointLoopStatus)
|
||||
m_jointPointLoopStatus->setText(reason.isEmpty() ? QStringLiteral("未运行") : reason);
|
||||
if (wasActive && !reason.isEmpty())
|
||||
appendLog(reason == QStringLiteral("循环执行完成") ? QStringLiteral("OK")
|
||||
: QStringLiteral("WARN"),
|
||||
reason);
|
||||
}
|
||||
|
||||
void MainWindow::sendMoveJPose()
|
||||
{
|
||||
if (m_moveJPoseSpins.size() != 6 || !m_moveJPoseBaseLinkCombo)
|
||||
@ -1919,17 +2391,37 @@ void MainWindow::saveSnapshot()
|
||||
void MainWindow::loadSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
loadJointPrograms(settings);
|
||||
m_hostEdit->setText(settings.value(QStringLiteral("connection/host"), QStringLiteral("192.168.0.28")).toString());
|
||||
m_hostEdit->setCursorPosition(0);
|
||||
m_portSpin->setValue(settings.value(QStringLiteral("connection/port"), 50052).toInt());
|
||||
m_demoCheck->setChecked(settings.value(QStringLiteral("connection/demo"), true).toBool());
|
||||
m_systemTargetEdit->setText(settings.value(QStringLiteral("system/target"), QStringLiteral("*")).toString());
|
||||
const QString armSide = settings.value(QStringLiteral("arm/side"),
|
||||
QStringLiteral("right")).toString();
|
||||
if (m_armSideCombo) {
|
||||
const int sideIndex = m_armSideCombo->findData(armSide);
|
||||
if (sideIndex >= 0)
|
||||
m_armSideCombo->setCurrentIndex(sideIndex);
|
||||
}
|
||||
const QString defaultArmDeviceId = armSide == QStringLiteral("left")
|
||||
? QStringLiteral("left_ethercat_arm") : QStringLiteral("right_ethercat_arm");
|
||||
QString armDeviceId = settings.value(QStringLiteral("arm/device"),
|
||||
QStringLiteral("demo_arm")).toString().trimmed();
|
||||
defaultArmDeviceId).toString().trimmed();
|
||||
if (armDeviceId == QStringLiteral("left_arm") ||
|
||||
armDeviceId == QStringLiteral("eyou_left_arm")) {
|
||||
armDeviceId = QStringLiteral("left_ethercat_arm");
|
||||
} else if (armDeviceId == QStringLiteral("right_arm") ||
|
||||
armDeviceId == QStringLiteral("eyou_arm") ||
|
||||
armDeviceId == QStringLiteral("eyou_right_arm")) {
|
||||
armDeviceId = QStringLiteral("right_ethercat_arm");
|
||||
}
|
||||
m_armIdEdit->setText(armDeviceId);
|
||||
if (m_armSideCombo && !armDeviceId.isEmpty())
|
||||
m_armSideCombo->addItem(armDeviceId, armDeviceId);
|
||||
m_cameraIdEdit->setText(settings.value(QStringLiteral("camera/device"), QStringLiteral("camera")).toString());
|
||||
const QString cameraDeviceId = settings.value(QStringLiteral("camera/device"), QString()).toString().trimmed();
|
||||
if (m_cameraDeviceCombo && !cameraDeviceId.isEmpty())
|
||||
m_cameraDeviceCombo->addItem(cameraDeviceId, cameraDeviceId);
|
||||
rebuildCameraPreviewGrid(configuredCameraIds());
|
||||
m_cameraRecordPathEdit->setText(settings.value(
|
||||
QStringLiteral("camera/recordPath"),
|
||||
@ -1996,12 +2488,14 @@ void MainWindow::loadSettings()
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
saveJointPrograms(settings);
|
||||
settings.setValue(QStringLiteral("connection/host"), m_hostEdit->text().trimmed());
|
||||
settings.setValue(QStringLiteral("connection/port"), m_portSpin->value());
|
||||
settings.setValue(QStringLiteral("connection/demo"), m_demoCheck->isChecked());
|
||||
settings.setValue(QStringLiteral("system/target"), m_systemTargetEdit->text().trimmed());
|
||||
settings.setValue(QStringLiteral("arm/device"), m_armIdEdit->text().trimmed());
|
||||
settings.setValue(QStringLiteral("camera/device"), m_cameraIdEdit->text().trimmed());
|
||||
settings.setValue(QStringLiteral("camera/device"),
|
||||
configuredCameraIds().value(0));
|
||||
settings.setValue(QStringLiteral("camera/recordPath"),
|
||||
m_cameraRecordPathEdit->text().trimmed());
|
||||
settings.setValue(QStringLiteral("camera/codec"),
|
||||
@ -2039,6 +2533,92 @@ void MainWindow::saveSettings()
|
||||
: certificatePath);
|
||||
}
|
||||
|
||||
void MainWindow::loadJointPrograms(QSettings &settings)
|
||||
{
|
||||
m_recordedJointPoints.clear();
|
||||
const int pointCount = settings.beginReadArray(QStringLiteral("arm/jointPoints"));
|
||||
for (int i = 0; i < pointCount; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
RecordedJointPoint point;
|
||||
point.name = settings.value(QStringLiteral("name")).toString();
|
||||
point.side = settings.value(QStringLiteral("side")).toString();
|
||||
point.deviceId = settings.value(QStringLiteral("deviceId")).toString();
|
||||
point.jointNames = settings.value(QStringLiteral("jointNames")).toStringList();
|
||||
const QVariantList storedPositions = settings.value(QStringLiteral("positions")).toList();
|
||||
for (const QVariant &value : storedPositions)
|
||||
point.positions.append(value.toDouble());
|
||||
if (!point.name.isEmpty() && point.jointNames.size() == point.positions.size())
|
||||
m_recordedJointPoints.append(point);
|
||||
}
|
||||
settings.endArray();
|
||||
|
||||
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<LegacyStep> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshRecordedJointPoints();
|
||||
refreshJointFlowTable();
|
||||
}
|
||||
|
||||
void MainWindow::saveJointPrograms(QSettings &settings) const
|
||||
{
|
||||
settings.remove(QStringLiteral("arm/jointPoints"));
|
||||
settings.beginWriteArray(QStringLiteral("arm/jointPoints"));
|
||||
for (int i = 0; i < m_recordedJointPoints.size(); ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
const RecordedJointPoint &point = m_recordedJointPoints.at(i);
|
||||
QVariantList positions;
|
||||
for (double value : point.positions)
|
||||
positions.append(value);
|
||||
settings.setValue(QStringLiteral("name"), point.name);
|
||||
settings.setValue(QStringLiteral("side"), point.side);
|
||||
settings.setValue(QStringLiteral("deviceId"), point.deviceId);
|
||||
settings.setValue(QStringLiteral("jointNames"), point.jointNames);
|
||||
settings.setValue(QStringLiteral("positions"), positions);
|
||||
}
|
||||
settings.endArray();
|
||||
if (m_jointFlowEditor) {
|
||||
settings.setValue(QStringLiteral("arm/jointFlowGraph"),
|
||||
QJsonDocument(m_jointFlowEditor->toJson()).toJson(QJsonDocument::Compact));
|
||||
settings.remove(QStringLiteral("arm/jointFlow"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setControlsEnabled(bool enabled)
|
||||
{
|
||||
for (QPushButton *button : m_serviceButtons) {
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <QStringList>
|
||||
#include <QVariantList>
|
||||
#include <QVariantMap>
|
||||
#include <QVector>
|
||||
|
||||
#include "videoframe.h"
|
||||
|
||||
@ -25,6 +26,7 @@ class QLineEdit;
|
||||
class QProgressBar;
|
||||
class QPushButton;
|
||||
class QResizeEvent;
|
||||
class QSettings;
|
||||
class QSlider;
|
||||
class QSpinBox;
|
||||
class QStackedWidget;
|
||||
@ -40,6 +42,8 @@ class UrdfViewerWidget;
|
||||
class AudioStreamManager;
|
||||
class VideoRenderWidget;
|
||||
class AgvMapViewWidget;
|
||||
class TactileHeatmapWidget;
|
||||
class JointFlowEditor;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
@ -73,6 +77,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);
|
||||
@ -82,12 +92,20 @@ private slots:
|
||||
void appendQuicLog(const QString &level, const QString &message);
|
||||
void sendMoveJ();
|
||||
void sendMoveJPose();
|
||||
void recordCurrentJointPoint();
|
||||
void executeSelectedJointPoint();
|
||||
void startJointPointLoop();
|
||||
void stopJointPointLoop(const QString &reason = QString());
|
||||
void advanceJointPointLoop();
|
||||
void refreshRecordedJointPoints();
|
||||
void refreshJointFlowTable();
|
||||
void saveSnapshot();
|
||||
|
||||
private:
|
||||
QWidget *createSystemPage();
|
||||
QWidget *createArmPage();
|
||||
QWidget *createCameraPage();
|
||||
QWidget *createDexHandPage();
|
||||
QStringList configuredCameraIds() const;
|
||||
void rebuildCameraPreviewGrid(const QStringList &cameraIds);
|
||||
void refreshCameraStreamControls();
|
||||
@ -98,6 +116,8 @@ private:
|
||||
QWidget *createDiagnosticsPage();
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
void loadJointPrograms(QSettings &settings);
|
||||
void saveJointPrograms(QSettings &settings) const;
|
||||
void setControlsEnabled(bool enabled);
|
||||
void updateWindowChrome();
|
||||
void ensureArmModelLoaded();
|
||||
@ -173,9 +193,13 @@ private:
|
||||
TrendWidget *m_trend = nullptr;
|
||||
QTableWidget *m_jointTable = nullptr;
|
||||
QTableWidget *m_motionTable = nullptr;
|
||||
QTableWidget *m_leftMotionTable = nullptr;
|
||||
QList<QDoubleSpinBox *> m_targetSpins;
|
||||
QList<QDoubleSpinBox *> m_leftTargetSpins;
|
||||
QList<QDoubleSpinBox *> m_rightTargetSpins;
|
||||
QStringList m_leftArmJointNames;
|
||||
QStringList m_rightArmJointNames;
|
||||
QStringList m_activeArmJointNames;
|
||||
QTabWidget *m_motionCommandTabs = nullptr;
|
||||
QList<QDoubleSpinBox *> m_moveJPoseSpins;
|
||||
QComboBox *m_moveJPoseBaseLinkCombo = nullptr;
|
||||
QPushButton *m_copyCurrentPoseButton = nullptr;
|
||||
@ -221,8 +245,39 @@ private:
|
||||
QString m_teachSelectedJoint;
|
||||
QString m_pendingUrdfPath;
|
||||
bool m_armModelLoadScheduled = false;
|
||||
struct RecordedJointPoint {
|
||||
QString name;
|
||||
QString side;
|
||||
QString deviceId;
|
||||
QStringList jointNames;
|
||||
QVector<double> positions;
|
||||
};
|
||||
QList<RecordedJointPoint> m_recordedJointPoints;
|
||||
QHash<QString, double> m_latestArmJointPositions;
|
||||
QLineEdit *m_jointPointNameEdit = nullptr;
|
||||
QTableWidget *m_jointPointTable = nullptr;
|
||||
QLabel *m_jointPointDetailLabel = nullptr;
|
||||
QSpinBox *m_jointPointLoopCount = nullptr;
|
||||
QDoubleSpinBox *m_jointPointInterval = nullptr;
|
||||
QSpinBox *m_jointFlowGroupCount = nullptr;
|
||||
JointFlowEditor *m_jointFlowEditor = nullptr;
|
||||
QDialog *m_jointFlowDialog = nullptr;
|
||||
QPushButton *m_recordJointPointButton = nullptr;
|
||||
QPushButton *m_runJointPointButton = nullptr;
|
||||
QPushButton *m_deleteJointPointButton = nullptr;
|
||||
QPushButton *m_startJointPointLoopButton = nullptr;
|
||||
QPushButton *m_stopJointPointLoopButton = nullptr;
|
||||
QLabel *m_jointPointLoopStatus = nullptr;
|
||||
QVector<int> m_jointPointLoopRows;
|
||||
QVector<double> m_jointPointExecutionWaits;
|
||||
QStringList m_jointPointExecutionNodeIds;
|
||||
int m_jointPointLoopCursor = 0;
|
||||
int m_jointPointLoopsCompleted = 0;
|
||||
int m_jointPointLoopTarget = 0;
|
||||
bool m_jointPointLoopActive = false;
|
||||
bool m_jointPointMovePending = false;
|
||||
|
||||
QLineEdit *m_cameraIdEdit = nullptr;
|
||||
QComboBox *m_cameraDeviceCombo = nullptr;
|
||||
VideoRenderWidget *m_videoRender = nullptr;
|
||||
QLabel *m_imageMetaLabel = nullptr;
|
||||
QPushButton *m_snapshotButton = nullptr;
|
||||
@ -248,6 +303,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<QDoubleSpinBox *> m_dexHandAngleSpins;
|
||||
QList<QDoubleSpinBox *> m_dexHandPositionSpins;
|
||||
QList<QDoubleSpinBox *> m_dexHandSpeedSpins;
|
||||
QList<QDoubleSpinBox *> 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;
|
||||
QTimer *m_agvStatusRefreshTimer = nullptr;
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include "agvmapviewwidget.h"
|
||||
#include "audiostreammanager.h"
|
||||
#include "robotclient.h"
|
||||
#include "tactileheatmapwidget.h"
|
||||
#include "jointfloweditor.h"
|
||||
#include "rpcservicewidget.h"
|
||||
#include "uiicons.h"
|
||||
#include "urdfviewerwidget.h"
|
||||
@ -44,6 +46,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QSignalBlocker>
|
||||
#include <QSlider>
|
||||
#include <QSpinBox>
|
||||
@ -137,6 +140,31 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
QStringList armJointNames(bool leftArm)
|
||||
{
|
||||
const QString prefix = leftArm ? QStringLiteral("L_") : QStringLiteral("R_");
|
||||
return {
|
||||
prefix + QStringLiteral("SHOULDER_P"), prefix + QStringLiteral("SHOULDER_R"),
|
||||
prefix + QStringLiteral("SHOULDER_Y"), prefix + QStringLiteral("ELBOW_R"),
|
||||
prefix + QStringLiteral("WRIST_P"), prefix + QStringLiteral("WRIST_Y"),
|
||||
prefix + QStringLiteral("WRIST_R")
|
||||
};
|
||||
}
|
||||
|
||||
bool isArmJointForSide(const QString &jointName, bool leftArm)
|
||||
{
|
||||
const QString lower = jointName.toLower();
|
||||
const QString sideWord = leftArm ? QStringLiteral("left") : QStringLiteral("right");
|
||||
const QString sidePrefix = leftArm ? QStringLiteral("l_") : QStringLiteral("r_");
|
||||
return lower.contains(sideWord + QStringLiteral("_arm"))
|
||||
|| lower.contains(sideWord + QStringLiteral("arm"))
|
||||
|| (lower.startsWith(sidePrefix)
|
||||
&& (lower.contains(QStringLiteral("shoulder"))
|
||||
|| lower.contains(QStringLiteral("elbow"))
|
||||
|| lower.contains(QStringLiteral("wrist"))
|
||||
|| lower.contains(QStringLiteral("arm"))));
|
||||
}
|
||||
|
||||
QWidget *withRpcExplorer(QWidget *commonPage, RobotClient *client,
|
||||
const QString &serviceName)
|
||||
{
|
||||
@ -268,6 +296,29 @@ QWidget *MainWindow::createArmPage()
|
||||
ui.armTabs->insertTab(0, ui.urdfTab, QStringLiteral("模型与控制"));
|
||||
}
|
||||
|
||||
// Keep device safety controls, the model, MoveJ targets and teaching in one workspace.
|
||||
ui.commandPanel->setParent(ui.urdfTab);
|
||||
ui.urdfTabLayout->insertWidget(0, ui.commandPanel);
|
||||
|
||||
// Qt3D preview is disabled in release builds. Keep the viewer alive and
|
||||
// hidden so it can still parse the URDF and provide the joint list, while
|
||||
// giving the complete workspace height to the command/point-flow tables.
|
||||
ui.urdfTabLayout->removeWidget(ui.urdfViewer);
|
||||
ui.urdfViewer->hide();
|
||||
ui.targetsPanel->setMinimumHeight(0);
|
||||
ui.targetsPanel->setMaximumHeight(QWIDGETSIZE_MAX);
|
||||
ui.targetsPanel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
ui.urdfTabLayout->insertWidget(1, ui.targetsPanel, 1);
|
||||
ui.urdfTabLayout->setStretch(0, 0);
|
||||
ui.urdfTabLayout->setStretch(1, 1);
|
||||
|
||||
const int legacyCommandTabIndex = ui.armTabs->indexOf(ui.jointControlTab);
|
||||
if (legacyCommandTabIndex >= 0) {
|
||||
ui.armTabs->removeTab(legacyCommandTabIndex);
|
||||
ui.jointControlTab->hide();
|
||||
}
|
||||
ui.armTabs->setCurrentWidget(ui.urdfTab);
|
||||
|
||||
m_armIdEdit = ui.armIdEdit;
|
||||
m_armTelemetryButton = ui.armTelemetryButton;
|
||||
m_armDeviceSummary = ui.commandSubtitle;
|
||||
@ -328,13 +379,270 @@ QWidget *MainWindow::createArmPage()
|
||||
ui.poseValue->hide();
|
||||
ui.updatedValue->hide();
|
||||
|
||||
QFrame *poseMetrics = new QFrame(ui.telemetryPanel);
|
||||
poseMetrics->setObjectName(QStringLiteral("poseMetrics"));
|
||||
QGridLayout *poseMetricsLayout = new QGridLayout(poseMetrics);
|
||||
poseMetricsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
poseMetricsLayout->setHorizontalSpacing(8);
|
||||
poseMetricsLayout->setVerticalSpacing(8);
|
||||
const QStringList poseAxes = {
|
||||
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);
|
||||
leftTargets->setObjectName(QStringLiteral("armTargetGroup"));
|
||||
QVBoxLayout *leftTargetsLayout = new QVBoxLayout(leftTargets);
|
||||
leftTargetsLayout->setContentsMargins(0, 4, 6, 0);
|
||||
QLabel *leftTargetsTitle = new QLabel(QStringLiteral("左臂 · left_ethercat_arm"), leftTargets);
|
||||
leftTargetsTitle->setObjectName(QStringLiteral("eyebrow"));
|
||||
m_leftMotionTable = new QTableWidget(7, 4, leftTargets);
|
||||
m_leftMotionTable->setObjectName(QStringLiteral("leftMotionTable"));
|
||||
leftTargetsLayout->addWidget(leftTargetsTitle);
|
||||
leftTargetsLayout->addWidget(m_leftMotionTable);
|
||||
QWidget *rightTargets = new QWidget(armTargetTables);
|
||||
rightTargets->setObjectName(QStringLiteral("armTargetGroup"));
|
||||
QVBoxLayout *rightTargetsLayout = new QVBoxLayout(rightTargets);
|
||||
rightTargetsLayout->setContentsMargins(6, 4, 0, 0);
|
||||
QLabel *rightTargetsTitle = new QLabel(QStringLiteral("右臂 · right_ethercat_arm"), rightTargets);
|
||||
rightTargetsTitle->setObjectName(QStringLiteral("eyebrow"));
|
||||
m_motionTable->setParent(rightTargets);
|
||||
rightTargetsLayout->addWidget(rightTargetsTitle);
|
||||
rightTargetsLayout->addWidget(m_motionTable);
|
||||
armTargetTables->addWidget(leftTargets);
|
||||
armTargetTables->addWidget(rightTargets);
|
||||
armTargetTables->setSizes({340, 340});
|
||||
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"));
|
||||
QVBoxLayout *pointLayout = new QVBoxLayout(pointPanel);
|
||||
pointLayout->setContentsMargins(12, 10, 12, 10);
|
||||
pointLayout->setSpacing(8);
|
||||
QHBoxLayout *pointHeader = new QHBoxLayout;
|
||||
QLabel *pointTitle = new QLabel(QStringLiteral("关节点位记录与循环"), pointPanel);
|
||||
pointTitle->setObjectName(QStringLiteral("panelTitle"));
|
||||
m_jointPointNameEdit = new QLineEdit(pointPanel);
|
||||
m_jointPointNameEdit->setPlaceholderText(QStringLiteral("动作名称,例如:抓取准备"));
|
||||
m_jointPointNameEdit->setMinimumWidth(220);
|
||||
m_recordJointPointButton = new QPushButton(QStringLiteral("记录当前角度"), pointPanel);
|
||||
pointHeader->addWidget(pointTitle);
|
||||
pointHeader->addStretch(1);
|
||||
pointHeader->addWidget(m_jointPointNameEdit);
|
||||
pointHeader->addWidget(m_recordJointPointButton);
|
||||
pointLayout->addLayout(pointHeader);
|
||||
|
||||
m_jointPointTable = new QTableWidget(0, 5, pointPanel);
|
||||
m_jointPointTable->setHorizontalHeaderLabels({
|
||||
QStringLiteral("动作名称"), QStringLiteral("机械臂"), QStringLiteral("Device ID"),
|
||||
QStringLiteral("关节数"), QStringLiteral("关节角度(rad)")});
|
||||
m_jointPointTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_jointPointTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
m_jointPointTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
m_jointPointTable->verticalHeader()->setVisible(false);
|
||||
m_jointPointTable->verticalHeader()->setDefaultSectionSize(28);
|
||||
m_jointPointTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
m_jointPointTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
m_jointPointTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
m_jointPointTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
m_jointPointTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
|
||||
m_jointPointTable->setMinimumHeight(132);
|
||||
pointLayout->addWidget(m_jointPointTable);
|
||||
m_jointPointDetailLabel = new QLabel(QStringLiteral("选择点位后查看详细关节角度"), pointPanel);
|
||||
m_jointPointDetailLabel->setObjectName(QStringLiteral("mutedLabel"));
|
||||
m_jointPointDetailLabel->setWordWrap(true);
|
||||
m_jointPointDetailLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
pointLayout->addWidget(m_jointPointDetailLabel);
|
||||
|
||||
QHBoxLayout *pointActions = new QHBoxLayout;
|
||||
m_runJointPointButton = new QPushButton(QStringLiteral("执行选中点位"), pointPanel);
|
||||
m_deleteJointPointButton = new QPushButton(QStringLiteral("删除选中"), pointPanel);
|
||||
QLabel *loopCountLabel = new QLabel(QStringLiteral("循环次数"), pointPanel);
|
||||
m_jointPointLoopCount = new QSpinBox(pointPanel);
|
||||
m_jointPointLoopCount->setRange(1, 10000);
|
||||
m_jointPointLoopCount->setValue(1);
|
||||
m_startJointPointLoopButton = new QPushButton(QStringLiteral("执行自定义流程"), pointPanel);
|
||||
m_stopJointPointLoopButton = new QPushButton(QStringLiteral("停止循环"), pointPanel);
|
||||
m_stopJointPointLoopButton->setEnabled(false);
|
||||
m_jointPointLoopStatus = new QLabel(QStringLiteral("未运行"), pointPanel);
|
||||
m_jointPointLoopStatus->setObjectName(QStringLiteral("mutedLabel"));
|
||||
pointActions->addWidget(m_runJointPointButton);
|
||||
pointActions->addWidget(m_deleteJointPointButton);
|
||||
pointActions->addStretch(1);
|
||||
pointActions->addWidget(m_jointPointLoopStatus);
|
||||
pointLayout->addLayout(pointActions);
|
||||
moveJLayout->addWidget(pointPanel, 2);
|
||||
|
||||
connect(m_recordJointPointButton, &QPushButton::clicked,
|
||||
this, &MainWindow::recordCurrentJointPoint);
|
||||
connect(m_runJointPointButton, &QPushButton::clicked,
|
||||
this, &MainWindow::executeSelectedJointPoint);
|
||||
connect(m_startJointPointLoopButton, &QPushButton::clicked,
|
||||
this, &MainWindow::startJointPointLoop);
|
||||
connect(m_stopJointPointLoopButton, &QPushButton::clicked, this, [this]() {
|
||||
stopJointPointLoop(QStringLiteral("用户停止"));
|
||||
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
||||
});
|
||||
connect(m_deleteJointPointButton, &QPushButton::clicked, this, [this]() {
|
||||
if (m_jointPointLoopActive)
|
||||
return;
|
||||
QList<int> rows;
|
||||
for (const QModelIndex &index : m_jointPointTable->selectionModel()->selectedRows())
|
||||
rows.append(index.row());
|
||||
std::sort(rows.begin(), rows.end(), std::greater<int>());
|
||||
QStringList removedNames;
|
||||
for (int row : rows) {
|
||||
if (row >= 0 && row < m_recordedJointPoints.size()) {
|
||||
removedNames.append(m_recordedJointPoints.at(row).name);
|
||||
m_recordedJointPoints.removeAt(row);
|
||||
}
|
||||
}
|
||||
if (m_jointFlowEditor)
|
||||
m_jointFlowEditor->removePointReferences(removedNames);
|
||||
refreshRecordedJointPoints();
|
||||
refreshJointFlowTable();
|
||||
QSettings settings;
|
||||
saveJointPrograms(settings);
|
||||
});
|
||||
connect(m_jointPointTable, &QTableWidget::cellClicked, this,
|
||||
[this](int row, int) {
|
||||
if (row < 0 || row >= m_recordedJointPoints.size())
|
||||
return;
|
||||
const RecordedJointPoint &point = m_recordedJointPoints.at(row);
|
||||
QStringList details;
|
||||
for (int i = 0; i < point.jointNames.size() && i < point.positions.size(); ++i) {
|
||||
details.append(QStringLiteral("%1 = %2 rad")
|
||||
.arg(point.jointNames.at(i))
|
||||
.arg(point.positions.at(i), 0, 'f', 6));
|
||||
}
|
||||
m_jointPointDetailLabel->setText(
|
||||
QStringLiteral("%1 · %2 · %3\n%4")
|
||||
.arg(point.name,
|
||||
point.side == QStringLiteral("left") ? QStringLiteral("左臂")
|
||||
: QStringLiteral("右臂"),
|
||||
point.deviceId, details.join(QStringLiteral(" "))));
|
||||
});
|
||||
|
||||
QFrame *flowPanel = new QFrame(moveJPage);
|
||||
flowPanel->setObjectName(QStringLiteral("panelCard"));
|
||||
QVBoxLayout *flowLayout = new QVBoxLayout(flowPanel);
|
||||
flowLayout->setContentsMargins(12, 10, 12, 10);
|
||||
flowLayout->setSpacing(8);
|
||||
QHBoxLayout *flowBuilder = new QHBoxLayout;
|
||||
QLabel *flowTitle = new QLabel(QStringLiteral("自定义执行流程"), flowPanel);
|
||||
flowTitle->setObjectName(QStringLiteral("panelTitle"));
|
||||
QLabel *intervalLabel = new QLabel(QStringLiteral("完成后等待"), flowPanel);
|
||||
m_jointPointInterval = new QDoubleSpinBox(flowPanel);
|
||||
m_jointPointInterval->setRange(0.0, 3600.0);
|
||||
m_jointPointInterval->setDecimals(1);
|
||||
m_jointPointInterval->setValue(1.0);
|
||||
m_jointPointInterval->setSuffix(QStringLiteral(" s"));
|
||||
m_jointFlowGroupCount = new QSpinBox(flowPanel);
|
||||
m_jointFlowGroupCount->setRange(1, 10000);
|
||||
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(addFlowStepButton);
|
||||
flowBuilder->addWidget(new QLabel(QStringLiteral("循环次数"), flowPanel));
|
||||
flowBuilder->addWidget(m_jointFlowGroupCount);
|
||||
flowBuilder->addWidget(addFlowLoopButton);
|
||||
flowLayout->addLayout(flowBuilder);
|
||||
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 *flowDeleteButton = new QPushButton(QStringLiteral("删除选中节点"), flowPanel);
|
||||
flowActions->addWidget(flowDeleteButton);
|
||||
flowActions->addStretch(1);
|
||||
flowActions->addWidget(loopCountLabel);
|
||||
loopCountLabel->setVisible(false);
|
||||
m_jointPointLoopCount->setVisible(false);
|
||||
flowActions->addWidget(m_startJointPointLoopButton);
|
||||
flowActions->addWidget(m_stopJointPointLoopButton);
|
||||
flowLayout->addLayout(flowActions);
|
||||
moveJLayout->addWidget(flowPanel, 3);
|
||||
|
||||
connect(addFlowStepButton, &QPushButton::clicked, this, [this]() {
|
||||
const QModelIndexList rows = m_jointPointTable->selectionModel()->selectedRows();
|
||||
if (rows.isEmpty()) {
|
||||
QMessageBox::information(this, QStringLiteral("添加单步节点"),
|
||||
QStringLiteral("请先选择一个已记录点位。"));
|
||||
return;
|
||||
}
|
||||
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]() {
|
||||
m_jointFlowEditor->removeSelectedNode();
|
||||
});
|
||||
connect(m_jointFlowEditor, &JointFlowEditor::changed, this, [this]() {
|
||||
QSettings settings;
|
||||
saveJointPrograms(settings);
|
||||
});
|
||||
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")
|
||||
};
|
||||
@ -342,6 +650,13 @@ QWidget *MainWindow::createArmPage()
|
||||
QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m"),
|
||||
QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")
|
||||
};
|
||||
QFrame *poseMetrics = new QFrame(ui.telemetryPanel);
|
||||
poseMetrics->setObjectName(QStringLiteral("poseMetrics"));
|
||||
QGridLayout *poseMetricsLayout = new QGridLayout(poseMetrics);
|
||||
poseMetricsLayout->setContentsMargins(0, 0, 0, 0);
|
||||
poseMetricsLayout->setHorizontalSpacing(8);
|
||||
poseMetricsLayout->setVerticalSpacing(8);
|
||||
const QStringList poseAxes = poseLabels;
|
||||
m_poseMetricValues.clear();
|
||||
for (int index = 0; index < poseAxes.size(); ++index) {
|
||||
QFrame *metricCard = new QFrame(poseMetrics);
|
||||
@ -371,9 +686,9 @@ QWidget *MainWindow::createArmPage()
|
||||
ui.telemetryLayout->setStretch(0, 1);
|
||||
ui.telemetryLayout->setStretch(1, 1);
|
||||
|
||||
// Replace the old target/teaching workspace with hold-to-jog controls and
|
||||
// a read-only telemetry panel.
|
||||
ui.targetsPanel->hide();
|
||||
// Combine the new hold-to-jog controls with the point/flow editor retained
|
||||
// from the arm workflow branch. The URDF viewer remains alive for parsing,
|
||||
// but stays hidden to avoid the release-only Qt3D crash and free the space.
|
||||
ui.teachPanel->hide();
|
||||
ui.urdfTabLayout->removeWidget(ui.urdfViewer);
|
||||
ui.urdfTabLayout->removeWidget(ui.teachPanel);
|
||||
@ -400,10 +715,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"));
|
||||
@ -635,6 +961,9 @@ QWidget *MainWindow::createArmPage()
|
||||
jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
}
|
||||
m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度"));
|
||||
m_jogModeTabs->addTab(directMovePage, QStringLiteral("MoveJ 目标"));
|
||||
ui.urdfTabLayout->removeWidget(ui.targetsPanel);
|
||||
ui.targetsPanel->hide();
|
||||
jogLayout->addWidget(m_jogModeTabs, 1);
|
||||
|
||||
QHBoxLayout *speedLayout = new QHBoxLayout;
|
||||
@ -663,9 +992,10 @@ QWidget *MainWindow::createArmPage()
|
||||
jogFooter->addWidget(m_jogStopButton);
|
||||
jogLayout->addLayout(jogFooter);
|
||||
modelJogWorkspace->addWidget(jogPanel);
|
||||
modelJogWorkspace->setStretchFactor(0, 3);
|
||||
modelJogWorkspace->setStretchFactor(1, 2);
|
||||
modelJogWorkspace->setSizes({780, 520});
|
||||
ui.urdfViewer->hide();
|
||||
modelJogWorkspace->setStretchFactor(0, 0);
|
||||
modelJogWorkspace->setStretchFactor(1, 1);
|
||||
modelJogWorkspace->setSizes({0, 1300});
|
||||
workspaceLayout->addWidget(modelJogWorkspace, 3);
|
||||
|
||||
ui.telemetryPanel->setParent(workspace);
|
||||
@ -740,9 +1070,12 @@ QWidget *MainWindow::createArmPage()
|
||||
connect(m_stopButton, &QPushButton::clicked, this, [this]() {
|
||||
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
||||
});
|
||||
connect(m_jogStopButton, &QPushButton::clicked, this, &MainWindow::stopArmJog);
|
||||
connect(m_jogSpeedSlider, &QSlider::valueChanged, this, [this](int value) {
|
||||
m_jogSpeedValue->setText(QStringLiteral("%1%").arg(value));
|
||||
connect(ui.zeroButton, &QPushButton::clicked, this, [this]() {
|
||||
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
const QList<QDoubleSpinBox *> &spins = leftArm
|
||||
? m_leftTargetSpins : m_rightTargetSpins;
|
||||
for (QDoubleSpinBox *spin : spins)
|
||||
spin->setValue(0.0);
|
||||
});
|
||||
connect(m_jogModeTabs, &QTabWidget::currentChanged, this, [this](int index) {
|
||||
stopArmJog();
|
||||
@ -792,6 +1125,33 @@ QWidget *MainWindow::createArmPage()
|
||||
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
|
||||
this, &MainWindow::appendLog);
|
||||
|
||||
const auto configureMotionTable = [](QTableWidget *table) {
|
||||
table->setColumnCount(5);
|
||||
table->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("当前角度"),
|
||||
QStringLiteral("当前弧度"), QStringLiteral("目标角度"),
|
||||
QStringLiteral("目标弧度")});
|
||||
table->setAlternatingRowColors(true);
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
table->setShowGrid(false);
|
||||
table->verticalHeader()->setVisible(false);
|
||||
table->verticalHeader()->setDefaultSectionSize(29);
|
||||
table->horizontalHeader()->setFixedHeight(32);
|
||||
table->horizontalHeader()->setHighlightSections(false);
|
||||
for (int column = 0; column < 5; ++column)
|
||||
table->horizontalHeader()->setSectionResizeMode(column, QHeaderView::Fixed);
|
||||
table->setColumnWidth(0, 112);
|
||||
table->setColumnWidth(1, 76);
|
||||
table->setColumnWidth(2, 92);
|
||||
table->setColumnWidth(3, 118);
|
||||
table->setColumnWidth(4, 96);
|
||||
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
table->setMinimumHeight(32 + 7 * 29 + 2);
|
||||
};
|
||||
configureMotionTable(m_leftMotionTable);
|
||||
configureMotionTable(m_motionTable);
|
||||
|
||||
m_jointTable->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("位置 rad"),
|
||||
QStringLiteral("速度 rad/s"), QStringLiteral("加速度 rad/s²")});
|
||||
m_jointTable->setAlternatingRowColors(true);
|
||||
@ -801,9 +1161,81 @@ QWidget *MainWindow::createArmPage()
|
||||
m_jointTable->verticalHeader()->setDefaultSectionSize(28);
|
||||
m_jointTable->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
m_activeArmJointNames.clear();
|
||||
m_jointTable->setRowCount(0);
|
||||
m_zeroJointCombo->clear();
|
||||
m_targetSpins.clear();
|
||||
m_leftArmJointNames = armJointNames(true);
|
||||
m_rightArmJointNames = armJointNames(false);
|
||||
const auto populateMotionTable = [this](QTableWidget *table, bool leftArm,
|
||||
const QStringList &jointNames) {
|
||||
QList<QDoubleSpinBox *> &sideSpins = leftArm
|
||||
? m_leftTargetSpins : m_rightTargetSpins;
|
||||
sideSpins.clear();
|
||||
table->clearContents();
|
||||
table->setRowCount(jointNames.size());
|
||||
table->setMinimumHeight(32 + qMin(jointNames.size(), 10) * 29 + 2);
|
||||
for (int row = 0; row < jointNames.size(); ++row) {
|
||||
const QString jointName = jointNames.at(row);
|
||||
table->setItem(row, 0, new QTableWidgetItem(jointName));
|
||||
table->setItem(row, 1, new QTableWidgetItem(QStringLiteral("--")));
|
||||
table->setItem(row, 2, new QTableWidgetItem(QStringLiteral("--")));
|
||||
QDoubleSpinBox *target = new QDoubleSpinBox(table);
|
||||
target->setRange(-180.0, 180.0);
|
||||
target->setDecimals(3);
|
||||
target->setSingleStep(1.0);
|
||||
target->setSuffix(QStringLiteral(" °"));
|
||||
target->setFrame(false);
|
||||
target->setEnabled(m_connected);
|
||||
m_targetSpins.append(target);
|
||||
sideSpins.append(target);
|
||||
table->setCellWidget(row, 3, target);
|
||||
QTableWidgetItem *radians = new QTableWidgetItem(QStringLiteral("0.000000"));
|
||||
radians->setFlags(radians->flags() & ~Qt::ItemIsEditable);
|
||||
table->setItem(row, 4, radians);
|
||||
connect(target, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||
[this, table, row, jointName](double degrees) {
|
||||
if (row < table->rowCount() && table->item(row, 4))
|
||||
table->item(row, 4)->setText(
|
||||
QString::number(qDegreesToRadians(degrees), 'f', 6));
|
||||
if (m_teachModeButton->isChecked())
|
||||
m_urdfViewer->setTeachingJointPosition(
|
||||
jointName, qDegreesToRadians(degrees));
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
populateMotionTable(m_leftMotionTable, true, m_leftArmJointNames);
|
||||
populateMotionTable(m_motionTable, false, m_rightArmJointNames);
|
||||
|
||||
const QStringList allJointNames = armJointNames(true) + armJointNames(false);
|
||||
m_jointTable->clearContents();
|
||||
m_jointTable->setRowCount(allJointNames.size());
|
||||
for (int row = 0; row < allJointNames.size(); ++row) {
|
||||
m_jointTable->setItem(row, 0, new QTableWidgetItem(allJointNames.at(row)));
|
||||
for (int column = 1; column < 4; ++column)
|
||||
m_jointTable->setItem(row, column, new QTableWidgetItem(QStringLiteral("--")));
|
||||
}
|
||||
|
||||
const auto refreshActiveArmControls = [this]() {
|
||||
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
m_activeArmJointNames = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
|
||||
QStringList zeroJointNames;
|
||||
const QStringList urdfNames = m_urdfViewer->jointNames();
|
||||
for (const QString &name : urdfNames) {
|
||||
if (isArmJointForSide(name, leftArm))
|
||||
zeroJointNames.append(name);
|
||||
}
|
||||
if (zeroJointNames.isEmpty())
|
||||
zeroJointNames = m_activeArmJointNames;
|
||||
const QString selectedJoint = m_zeroJointCombo->currentText();
|
||||
const QSignalBlocker blocker(m_zeroJointCombo);
|
||||
m_zeroJointCombo->clear();
|
||||
m_zeroJointCombo->addItems(zeroJointNames);
|
||||
const int selectedIndex = m_zeroJointCombo->findText(selectedJoint);
|
||||
if (selectedIndex >= 0)
|
||||
m_zeroJointCombo->setCurrentIndex(selectedIndex);
|
||||
m_zeroJointCombo->setEnabled(!zeroJointNames.isEmpty());
|
||||
m_calibrateZeroButton->setEnabled(m_connected && !zeroJointNames.isEmpty());
|
||||
};
|
||||
refreshActiveArmControls();
|
||||
|
||||
connect(m_armSideCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
[this, poseSubtitle = ui.poseSubtitle](int) {
|
||||
@ -814,13 +1246,9 @@ QWidget *MainWindow::createArmPage()
|
||||
const bool telemetryRunning = m_armTelemetryButton->isChecked();
|
||||
if (telemetryRunning)
|
||||
m_client->setArmTelemetry(oldDeviceId, false);
|
||||
m_armIdEdit->setText(newDeviceId);
|
||||
m_activeArmJointNames.clear();
|
||||
m_jointTable->setRowCount(0);
|
||||
rebuildArmJogControls();
|
||||
m_zeroJointCombo->clear();
|
||||
m_armDefaultBaseFrame.clear();
|
||||
m_armDefaultTcpFrame.clear();
|
||||
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
m_armIdEdit->setText(leftArm ? QStringLiteral("left_ethercat_arm")
|
||||
: QStringLiteral("right_ethercat_arm"));
|
||||
m_latestArmPose.clear();
|
||||
for (QLabel *valueLabel : m_poseMetricValues)
|
||||
valueLabel->setText(QStringLiteral("--"));
|
||||
@ -832,6 +1260,110 @@ QWidget *MainWindow::createArmPage()
|
||||
if (telemetryRunning)
|
||||
m_client->setArmTelemetry(newDeviceId, true);
|
||||
});
|
||||
connect(m_urdfViewer, &UrdfViewerWidget::modelLoaded, this,
|
||||
[this, refreshActiveArmControls, populateMotionTable](const QString &, int, int) {
|
||||
const QStringList urdfNames = m_urdfViewer->jointNames();
|
||||
QStringList leftNames;
|
||||
QStringList rightNames;
|
||||
for (const QString &name : urdfNames) {
|
||||
if (isArmJointForSide(name, true))
|
||||
leftNames.append(name);
|
||||
else if (isArmJointForSide(name, false))
|
||||
rightNames.append(name);
|
||||
}
|
||||
// A single-arm URDF often uses neutral names such as joint1..joint6.
|
||||
// In that case bind all movable joints to the currently selected arm.
|
||||
if (leftNames.isEmpty() && rightNames.isEmpty() && !urdfNames.isEmpty()) {
|
||||
if (m_armSideCombo->currentData().toString() == QStringLiteral("left"))
|
||||
leftNames = urdfNames;
|
||||
else
|
||||
rightNames = urdfNames;
|
||||
}
|
||||
m_leftArmJointNames = leftNames;
|
||||
m_rightArmJointNames = rightNames;
|
||||
m_targetSpins.clear();
|
||||
populateMotionTable(m_leftMotionTable, true, m_leftArmJointNames);
|
||||
populateMotionTable(m_motionTable, false, m_rightArmJointNames);
|
||||
|
||||
m_jointTable->clearContents();
|
||||
m_jointTable->setRowCount(urdfNames.size());
|
||||
for (int row = 0; row < urdfNames.size(); ++row) {
|
||||
m_jointTable->setItem(row, 0, new QTableWidgetItem(urdfNames.at(row)));
|
||||
for (int column = 1; column < 4; ++column)
|
||||
m_jointTable->setItem(row, column,
|
||||
new QTableWidgetItem(QStringLiteral("--")));
|
||||
}
|
||||
refreshActiveArmControls();
|
||||
m_teachModeButton->setEnabled(!urdfNames.isEmpty());
|
||||
});
|
||||
connect(m_teachModeButton, &QPushButton::toggled, this, [this](bool enabled) {
|
||||
m_urdfViewer->setTeachingEnabled(enabled);
|
||||
if (enabled && !m_activeArmJointNames.isEmpty())
|
||||
m_urdfViewer->selectTeachingJoint(m_activeArmJointNames.first());
|
||||
});
|
||||
connect(m_urdfViewer, &UrdfViewerWidget::teachingModeChanged, this,
|
||||
[this](bool enabled) {
|
||||
const QSignalBlocker blocker(m_teachModeButton);
|
||||
m_teachModeButton->setChecked(enabled);
|
||||
m_teachModeButton->setText(enabled ? QStringLiteral("退出示教")
|
||||
: QStringLiteral("示教模式"));
|
||||
m_teachRestoreButton->setEnabled(enabled);
|
||||
if (!enabled) {
|
||||
m_teachSelectedJoint.clear();
|
||||
m_leftMotionTable->clearSelection();
|
||||
m_motionTable->clearSelection();
|
||||
}
|
||||
});
|
||||
connect(m_urdfViewer, &UrdfViewerWidget::teachingJointSelected, this,
|
||||
[this](const QString &jointName, double, double, double) {
|
||||
const int row = m_activeArmJointNames.indexOf(jointName);
|
||||
if (row < 0) {
|
||||
if (!m_activeArmJointNames.isEmpty())
|
||||
m_urdfViewer->selectTeachingJoint(m_activeArmJointNames.first());
|
||||
return;
|
||||
}
|
||||
m_teachSelectedJoint = jointName;
|
||||
const int zeroIndex = m_zeroJointCombo->findText(jointName);
|
||||
if (zeroIndex >= 0)
|
||||
m_zeroJointCombo->setCurrentIndex(zeroIndex);
|
||||
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||||
(leftArm ? m_leftMotionTable : m_motionTable)->selectRow(row);
|
||||
});
|
||||
connect(m_urdfViewer, &UrdfViewerWidget::teachingPositionsChanged, this,
|
||||
[this](const QHash<QString, double> &positions) {
|
||||
for (int side = 0; side < 2; ++side) {
|
||||
const bool leftArm = side == 0;
|
||||
QTableWidget *table = leftArm ? m_leftMotionTable : m_motionTable;
|
||||
const QStringList &names = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
|
||||
const QList<QDoubleSpinBox *> &spins = leftArm
|
||||
? m_leftTargetSpins : m_rightTargetSpins;
|
||||
for (int row = 0; row < names.size() && row < spins.size(); ++row) {
|
||||
if (!positions.contains(names.at(row)))
|
||||
continue;
|
||||
const double radians = positions.value(names.at(row));
|
||||
const QSignalBlocker blocker(spins.at(row));
|
||||
spins.at(row)->setValue(qRadiansToDegrees(radians));
|
||||
table->item(row, 4)->setText(QString::number(radians, 'f', 6));
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(m_teachRestoreButton, &QPushButton::clicked,
|
||||
m_urdfViewer, &UrdfViewerWidget::restoreTeachingFromTelemetry);
|
||||
|
||||
const auto connectMotionTable = [this](QTableWidget *table, bool leftArm) {
|
||||
connect(table, &QTableWidget::cellClicked, this,
|
||||
[this, leftArm](int row, int) {
|
||||
const int sideIndex = m_armSideCombo->findData(
|
||||
leftArm ? QStringLiteral("left") : QStringLiteral("right"));
|
||||
if (sideIndex >= 0 && sideIndex != m_armSideCombo->currentIndex())
|
||||
m_armSideCombo->setCurrentIndex(sideIndex);
|
||||
const QStringList &names = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
|
||||
if (m_teachModeButton->isChecked() && row >= 0 && row < names.size())
|
||||
m_urdfViewer->selectTeachingJoint(names.at(row));
|
||||
});
|
||||
};
|
||||
connectMotionTable(m_leftMotionTable, true);
|
||||
connectMotionTable(m_motionTable, false);
|
||||
|
||||
m_serviceButtons << m_armTelemetryButton << m_armGlobalStopButton
|
||||
<< m_torqueOnButton << m_torqueOffButton
|
||||
@ -842,20 +1374,10 @@ QWidget *MainWindow::createArmPage()
|
||||
|
||||
QStringList MainWindow::configuredCameraIds() const
|
||||
{
|
||||
if (!m_cameraIdEdit)
|
||||
if (!m_cameraDeviceCombo)
|
||||
return {};
|
||||
const QStringList values = m_cameraIdEdit->text().split(
|
||||
QRegularExpression(QStringLiteral("[,;\\s]+")), QString::SkipEmptyParts);
|
||||
QStringList result;
|
||||
QSet<QString> seen;
|
||||
for (const QString &value : values) {
|
||||
const QString cameraId = value.trimmed();
|
||||
if (!cameraId.isEmpty() && !seen.contains(cameraId)) {
|
||||
seen.insert(cameraId);
|
||||
result.append(cameraId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
const QString cameraId = m_cameraDeviceCombo->currentData().toString().trimmed();
|
||||
return cameraId.isEmpty() ? QStringList() : QStringList{cameraId};
|
||||
}
|
||||
|
||||
void MainWindow::rebuildCameraPreviewGrid(const QStringList &cameraIds)
|
||||
@ -940,8 +1462,9 @@ void MainWindow::refreshCameraStreamControls()
|
||||
? QStringLiteral("dangerButton") : QStringLiteral("primaryButton"));
|
||||
m_cameraStreamButton->style()->unpolish(m_cameraStreamButton);
|
||||
m_cameraStreamButton->style()->polish(m_cameraStreamButton);
|
||||
m_cameraIdEdit->setEnabled(!m_cameraStreaming && !m_cameraRecording);
|
||||
m_cameraCodecCombo->setEnabled(!m_cameraStreaming);
|
||||
m_cameraDeviceCombo->setEnabled(!m_cameraStreaming && !m_cameraRecording
|
||||
&& m_cameraDeviceCombo->count() > 0);
|
||||
m_cameraCodecCombo->setEnabled(false);
|
||||
m_cameraStreamModeCombo->setEnabled(!m_cameraStreaming);
|
||||
m_snapshotButton->setEnabled(m_connected && !m_cameraStreaming);
|
||||
m_cameraStreamStateLabel->setText(m_cameraStreaming
|
||||
@ -966,7 +1489,7 @@ QWidget *MainWindow::createCameraPage()
|
||||
m_cameraPreviewGrid->setContentsMargins(0, 0, 0, 0);
|
||||
m_cameraPreviewGrid->setSpacing(10);
|
||||
ui.viewerLayout->addWidget(m_cameraPreviewContainer, 1);
|
||||
m_cameraIdEdit = ui.cameraIdEdit;
|
||||
m_cameraDeviceCombo = ui.cameraDeviceCombo;
|
||||
m_snapshotButton = ui.snapshotButton;
|
||||
m_cameraStreamButton = ui.cameraStreamButton;
|
||||
m_cameraCodecCombo = ui.codecCombo;
|
||||
@ -1001,9 +1524,15 @@ QWidget *MainWindow::createCameraPage()
|
||||
.arg(index == 1 ? QStringLiteral("H.265") : QStringLiteral("H.264")));
|
||||
}
|
||||
});
|
||||
connect(m_cameraIdEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
if (!m_cameraStreaming)
|
||||
connect(m_cameraDeviceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, [this](int) {
|
||||
if (!m_cameraStreaming) {
|
||||
rebuildCameraPreviewGrid(configuredCameraIds());
|
||||
saveSettings();
|
||||
}
|
||||
const QStringList cameraIds = configuredCameraIds();
|
||||
if (m_connected && !cameraIds.isEmpty())
|
||||
m_client->requestCameraStatus(cameraIds.first());
|
||||
});
|
||||
connect(m_cameraStreamButton, &QPushButton::clicked, this, [this]() {
|
||||
if (m_cameraStreaming) {
|
||||
@ -1014,7 +1543,7 @@ QWidget *MainWindow::createCameraPage()
|
||||
const QStringList cameraIds = configuredCameraIds();
|
||||
if (cameraIds.isEmpty()) {
|
||||
appendLog(QStringLiteral("WARN"),
|
||||
QStringLiteral("请至少填写一个摄像头设备 ID"));
|
||||
QStringLiteral("服务端未返回可用的摄像头设备"));
|
||||
return;
|
||||
}
|
||||
saveSettings();
|
||||
@ -1047,7 +1576,7 @@ QWidget *MainWindow::createCameraPage()
|
||||
if (cameraIds.isEmpty()) {
|
||||
m_cameraRecordButton->setEnabled(m_connected);
|
||||
appendLog(QStringLiteral("WARN"),
|
||||
QStringLiteral("请先填写摄像头设备 ID"));
|
||||
QStringLiteral("服务端未返回可用的摄像头设备"));
|
||||
return;
|
||||
}
|
||||
m_client->startCameraRecording(cameraIds.first(), path);
|
||||
@ -1815,6 +2344,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<QDoubleSpinBox *> &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<QDoubleSpinBox *> 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<int>::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;
|
||||
|
||||
@ -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;
|
||||
@ -576,6 +581,177 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
void getCameraStatus(const QString &cameraId)
|
||||
{
|
||||
if (!ensureConnected(QStringLiteral("Get Camera Status"))
|
||||
|| !ensureDeviceId(QStringLiteral("Get Camera Status"), cameraId)) {
|
||||
return;
|
||||
}
|
||||
QVariantMap state;
|
||||
if (m_demoMode) {
|
||||
state.insert(QStringLiteral("codec"), QStringLiteral("h264"));
|
||||
state.insert(QStringLiteral("fps"), 30);
|
||||
state.insert(QStringLiteral("width"), 1280);
|
||||
state.insert(QStringLiteral("height"), 720);
|
||||
if (cameraStatusReceived)
|
||||
cameraStatusReceived(cameraId.trimmed(), state);
|
||||
return;
|
||||
}
|
||||
#ifdef CMVR_WITH_GRPC
|
||||
cmvr::api::GetCameraStateCommand::Request request;
|
||||
fillHeader(request.mutable_header(), cameraId);
|
||||
cmvr::api::GetCameraStateCommand::Feedback response;
|
||||
grpc::ClientContext context;
|
||||
setDeadline(context, 1200);
|
||||
const grpc::Status status = m_camera->GetStatus(&context, request, &response);
|
||||
if (!status.ok() || !response.header().success()) {
|
||||
const QString detail = status.ok()
|
||||
? QString::fromStdString(response.header().error_message())
|
||||
: QString::fromStdString(status.error_message());
|
||||
emit commandFinished(QStringLiteral("Get Camera Status"), false, detail);
|
||||
return;
|
||||
}
|
||||
const auto &cameraState = response.state();
|
||||
state.insert(QStringLiteral("codec"), QString::fromStdString(cameraState.codec()));
|
||||
state.insert(QStringLiteral("fps"), cameraState.fps());
|
||||
state.insert(QStringLiteral("width"), cameraState.width());
|
||||
state.insert(QStringLiteral("height"), cameraState.height());
|
||||
state.insert(QStringLiteral("streaming"), cameraState.is_streaming());
|
||||
if (cameraStatusReceived)
|
||||
cameraStatusReceived(cameraId.trimmed(), state);
|
||||
#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<float>(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)
|
||||
{
|
||||
@ -897,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<std::mutex> 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<std::mutex> 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)
|
||||
{
|
||||
@ -2081,6 +2323,13 @@ public:
|
||||
std::function<void(double, double, double, const QVariantList &)> systemStatusReceived;
|
||||
std::function<void(const QVariantMap &)> systemInfoReceived;
|
||||
std::function<void(const QImage &, const QString &)> imageReceived;
|
||||
std::function<void(const QString &, const QVariantMap &)> cameraStatusReceived;
|
||||
std::function<void(const QString &, bool, bool, const QString &,
|
||||
const QVariantList &)>
|
||||
dexHandStatusReceived;
|
||||
std::function<void(const QString &, int, int, const QVariantList &, quint64)>
|
||||
dexHandTactileReceived;
|
||||
std::function<void(bool, const QString &)> dexHandTactileStreamStateChanged;
|
||||
std::function<void(const QString &, const VideoFrame &, const QString &)>
|
||||
videoFrameReceivedForCamera;
|
||||
std::function<void(const QString &, bool, const QString &)>
|
||||
@ -2265,6 +2514,22 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void stopDexHandTactileStreamInternal()
|
||||
{
|
||||
m_dexHandTactileStop.store(true);
|
||||
#ifdef CMVR_WITH_GRPC
|
||||
{
|
||||
std::lock_guard<std::mutex> 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);
|
||||
@ -3051,27 +3316,6 @@ private:
|
||||
pose.insert(QStringLiteral("rx"), tcp.rx());
|
||||
pose.insert(QStringLiteral("ry"), tcp.ry());
|
||||
pose.insert(QStringLiteral("rz"), tcp.rz());
|
||||
if (robotState.connected()
|
||||
&& !m_armBaseFrame.isEmpty() && !m_armTcpFrame.isEmpty()) {
|
||||
cmvr::api::GetPose::Request poseRequest;
|
||||
fillHeader(poseRequest.mutable_header(), polledDeviceId);
|
||||
poseRequest.set_base_link(m_armBaseFrame.toStdString());
|
||||
poseRequest.set_ee_link(m_armTcpFrame.toStdString());
|
||||
cmvr::api::GetPose::Response poseResponse;
|
||||
grpc::ClientContext poseContext;
|
||||
setDeadline(poseContext, 250);
|
||||
const grpc::Status poseStatus =
|
||||
m_arm->getPose(&poseContext, poseRequest, &poseResponse);
|
||||
if (poseStatus.ok() && poseResponse.header().success()) {
|
||||
const auto &selectedPose = poseResponse.pose();
|
||||
pose.insert(QStringLiteral("x"), selectedPose.x());
|
||||
pose.insert(QStringLiteral("y"), selectedPose.y());
|
||||
pose.insert(QStringLiteral("z"), selectedPose.z());
|
||||
pose.insert(QStringLiteral("rx"), selectedPose.rx());
|
||||
pose.insert(QStringLiteral("ry"), selectedPose.ry());
|
||||
pose.insert(QStringLiteral("rz"), selectedPose.rz());
|
||||
}
|
||||
}
|
||||
QVariantMap state;
|
||||
state.insert(QStringLiteral("robotMode"), static_cast<int>(robotState.robot_mode()));
|
||||
state.insert(QStringLiteral("safetyMode"), static_cast<int>(robotState.safety_mode()));
|
||||
@ -3112,27 +3356,13 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if (m_tick % 10 != 0)
|
||||
return;
|
||||
cmvr::api::GetSystemStatusCommand::Request statusRequest;
|
||||
cmvr::api::GetSystemStatusCommand::Feedback statusResponse;
|
||||
grpc::ClientContext statusContext;
|
||||
setDeadline(statusContext, 500);
|
||||
const grpc::Status rpcStatus = m_system->GetSystemStatus(&statusContext, statusRequest, &statusResponse);
|
||||
if (rpcStatus.ok() && statusResponse.header().success()) {
|
||||
const double memory = statusResponse.mem_total_mb() > 0
|
||||
? statusResponse.mem_used_mb() * 100.0 / statusResponse.mem_total_mb() : 0.0;
|
||||
const double disk = statusResponse.disk_total_gb() > 0
|
||||
? statusResponse.disk_used_gb() * 100.0 / statusResponse.disk_total_gb() : 0.0;
|
||||
emit systemStatusReceived(statusResponse.cpu_usage(), memory, disk,
|
||||
deviceListFromStatus(statusResponse));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<grpc::Channel> m_channel;
|
||||
std::shared_ptr<grpc::Channel> m_configChannel;
|
||||
std::unique_ptr<cmvr::api::ArmService::Stub> m_arm;
|
||||
std::unique_ptr<cmvr::api::CameraService::Stub> m_camera;
|
||||
std::unique_ptr<cmvr::api::DexHandService::Stub> m_dexHand;
|
||||
std::unique_ptr<cmvr::api::SystemService::Stub> m_system;
|
||||
std::unique_ptr<cmvr::api::AgvService::Stub> m_agv;
|
||||
std::unique_ptr<cmvr::api::MicPhoneService::Stub> m_microphone;
|
||||
@ -3144,6 +3374,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 {
|
||||
@ -3186,6 +3418,9 @@ private:
|
||||
std::atomic<quint64> m_microphoneFrames{0};
|
||||
std::atomic<quint64> m_microphoneBytes{0};
|
||||
std::thread m_microphoneStreamThread;
|
||||
std::atomic<bool> m_dexHandTactileRunning{false};
|
||||
std::atomic<bool> m_dexHandTactileStop{false};
|
||||
std::thread m_dexHandTactileThread;
|
||||
std::atomic<bool> m_agvMapStreamRunning{false};
|
||||
std::atomic<bool> m_agvMapStreamStop{false};
|
||||
std::thread m_agvMapStreamThread;
|
||||
@ -3246,6 +3481,35 @@ RobotClient::RobotClient(QObject *parent)
|
||||
emit imageReceived(image, detail);
|
||||
}, Qt::QueuedConnection);
|
||||
};
|
||||
m_worker->cameraStatusReceived = [this](const QString &cameraId,
|
||||
const QVariantMap &state) {
|
||||
QMetaObject::invokeMethod(this, [this, cameraId, state]() {
|
||||
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) {
|
||||
@ -3393,6 +3657,15 @@ RobotClient::RobotClient(QObject *parent)
|
||||
connect(this, &RobotClient::armCalibrateZeroRequested,
|
||||
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);
|
||||
@ -3518,6 +3791,29 @@ void RobotClient::requestArmCalibrateZero(const QString &deviceId, const QString
|
||||
emit armCalibrateZeroRequested(deviceId, jointName);
|
||||
}
|
||||
void RobotClient::requestSnapshot(const QString &cameraId) { emit snapshotRequested(cameraId); }
|
||||
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)
|
||||
{
|
||||
|
||||
@ -47,6 +47,12 @@ public slots:
|
||||
void requestArmClearFault(const QString &deviceId);
|
||||
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 +115,12 @@ signals:
|
||||
void armClearFaultRequested(const QString &deviceId);
|
||||
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);
|
||||
@ -162,6 +174,14 @@ signals:
|
||||
const QVariantList &devices);
|
||||
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,
|
||||
|
||||
87
src/tactileheatmapwidget.cpp
Normal file
87
src/tactileheatmapwidget.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "tactileheatmapwidget.h"
|
||||
|
||||
#include <QLinearGradient>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QtMath>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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<int> &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"));
|
||||
}
|
||||
20
src/tactileheatmapwidget.h
Normal file
20
src/tactileheatmapwidget.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
class TactileHeatmapWidget final : public QWidget
|
||||
{
|
||||
public:
|
||||
explicit TactileHeatmapWidget(QWidget *parent = nullptr);
|
||||
|
||||
void setTactileData(int rows, int cols, const QVector<int> &values);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
int m_rows = 12;
|
||||
int m_cols = 5;
|
||||
QVector<int> m_values = QVector<int>(60, 0);
|
||||
};
|
||||
@ -66,6 +66,7 @@
|
||||
#include <QMatrix3x3>
|
||||
#include <QMouseEvent>
|
||||
#include <QProgressBar>
|
||||
#include <QPointer>
|
||||
#include <QPushButton>
|
||||
#include <QQuaternion>
|
||||
#include <QSignalBlocker>
|
||||
@ -692,7 +693,29 @@ void UrdfViewerWidget::setLoading(bool loading, const QString &message)
|
||||
|
||||
UrdfViewerWidget::~UrdfViewerWidget()
|
||||
{
|
||||
// Qt3DWindow's aspect engine owns and synchronously tears down the scene.
|
||||
if (m_demoTimer)
|
||||
m_demoTimer->stop();
|
||||
|
||||
// Qt 5.12/MinGW has a reproducible access violation in Qt53DRender.dll
|
||||
// when an embedded Qt3DWindow is destroyed while its render aspect is
|
||||
// winding down. Detach this process-lifetime viewer so normal QWidget
|
||||
// destruction cannot enter the faulty Qt3D teardown path; the OS reclaims
|
||||
// it immediately when the process exits.
|
||||
if (m_viewContainer)
|
||||
m_viewContainer->removeEventFilter(this);
|
||||
if (m_view)
|
||||
m_view->removeEventFilter(this);
|
||||
if (m_viewContainer) {
|
||||
m_layout->removeWidget(m_viewContainer);
|
||||
m_viewContainer->hide();
|
||||
m_viewContainer->setParent(nullptr);
|
||||
}
|
||||
m_viewContainer = nullptr;
|
||||
m_view = nullptr;
|
||||
m_camera = nullptr;
|
||||
m_teachingRayCaster = nullptr;
|
||||
m_modelRoot = nullptr;
|
||||
m_rootEntity = nullptr;
|
||||
}
|
||||
|
||||
void UrdfViewerWidget::showEvent(QShowEvent *event)
|
||||
@ -916,8 +939,7 @@ bool UrdfViewerWidget::loadUrdf(const QString &filePath)
|
||||
return false;
|
||||
}
|
||||
|
||||
setLoading(true, QStringLiteral("正在初始化 Qt3D 场景…"));
|
||||
ensureSceneInitialized();
|
||||
setLoading(true, QStringLiteral("正在解析 URDF 关节数据…"));
|
||||
m_statusLabel->setText(QStringLiteral("正在解析 %1…").arg(fileInfo.fileName()));
|
||||
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
@ -939,6 +961,60 @@ bool UrdfViewerWidget::loadUrdf(const QString &filePath)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
// Qt 5.12.4/MinGW's Qt3D renderer crashes in its backend entity
|
||||
// synchronization code while a URDF component tree is being published.
|
||||
// Parse the complete URDF for control tables without creating a 3D scene.
|
||||
clearModel();
|
||||
m_currentFile = fileInfo.absoluteFilePath();
|
||||
m_urdfDirectory = fileInfo.absolutePath();
|
||||
m_pathEdit->setText(fileInfo.fileName());
|
||||
m_pathEdit->setToolTip(QDir::toNativeSeparators(m_currentFile));
|
||||
m_reloadButton->setEnabled(true);
|
||||
|
||||
std::function<void(const urdf::LinkConstSharedPtr &)> collectJoints;
|
||||
collectJoints = [this, &collectJoints](const urdf::LinkConstSharedPtr &link) {
|
||||
if (!link)
|
||||
return;
|
||||
for (const urdf::JointSharedPtr &joint : link->child_joints) {
|
||||
if (!joint)
|
||||
continue;
|
||||
if (joint->type == urdf::Joint::REVOLUTE
|
||||
|| joint->type == urdf::Joint::CONTINUOUS
|
||||
|| joint->type == urdf::Joint::PRISMATIC) {
|
||||
const QString jointName = QString::fromStdString(joint->name);
|
||||
m_jointOrder.append(jointName);
|
||||
m_jointPositions.insert(jointName,
|
||||
m_latestTelemetryPositions.value(jointName, 0.0));
|
||||
}
|
||||
urdf::LinkConstSharedPtr childLink;
|
||||
for (const urdf::LinkSharedPtr &candidate : link->child_links) {
|
||||
if (candidate && candidate->name == joint->child_link_name) {
|
||||
childLink = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
collectJoints(childLink);
|
||||
}
|
||||
};
|
||||
collectJoints(model->getRoot());
|
||||
|
||||
const int linkCount = static_cast<int>(model->links_.size());
|
||||
const int jointCount = static_cast<int>(model->joints_.size());
|
||||
m_modelSummary = QStringLiteral("%1 个 Link · %2 个 Joint · 仅关节数据")
|
||||
.arg(linkCount).arg(jointCount);
|
||||
m_statusLabel->setText(m_modelSummary);
|
||||
m_loadingTitle->setText(QStringLiteral("3D 模型预览暂时关闭"));
|
||||
m_loadingDetail->setText(QStringLiteral("URDF 已解析,关节表和控制功能可正常使用"));
|
||||
m_loadingProgress->setVisible(false);
|
||||
m_viewportPlaceholder->show();
|
||||
emit logMessage(QStringLiteral("OK"),
|
||||
QStringLiteral("URDF 已加载(关节数据模式):%1(%2 Link,%3 Joint)")
|
||||
.arg(fileInfo.fileName()).arg(linkCount).arg(jointCount));
|
||||
emit modelLoaded(m_currentFile, linkCount, jointCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
clearModel();
|
||||
m_currentFile = fileInfo.absoluteFilePath();
|
||||
m_urdfDirectory = fileInfo.absolutePath();
|
||||
@ -1041,9 +1117,13 @@ bool UrdfViewerWidget::loadUrdf(const QString &filePath)
|
||||
QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 90.0f));
|
||||
}
|
||||
Qt3DRender::QSceneLoader *loader = new Qt3DRender::QSceneLoader(geometryEntity);
|
||||
const QPointer<Qt3DRender::QSceneLoader> guardedLoader(loader);
|
||||
const QPointer<Qt3DCore::QEntity> guardedGeometry(geometryEntity);
|
||||
connect(loader, &Qt3DRender::QSceneLoader::statusChanged, this,
|
||||
[this, loader, source, geometryEntity, teachingJointName]
|
||||
[this, guardedLoader, source, guardedGeometry, teachingJointName]
|
||||
(Qt3DRender::QSceneLoader::Status status) {
|
||||
if (!guardedLoader || !guardedGeometry)
|
||||
return;
|
||||
if (status == Qt3DRender::QSceneLoader::Error) {
|
||||
m_statusLabel->setText(
|
||||
QStringLiteral("网格加载失败 · 请检查 Qt3D Assimp 插件"));
|
||||
@ -1051,12 +1131,12 @@ bool UrdfViewerWidget::loadUrdf(const QString &filePath)
|
||||
QStringLiteral("Qt3D 无法加载网格:%1").arg(source));
|
||||
} else if (status == Qt3DRender::QSceneLoader::Ready
|
||||
&& !teachingJointName.isEmpty()) {
|
||||
const QStringList entityNames = loader->entityNames();
|
||||
const QStringList entityNames = guardedLoader->entityNames();
|
||||
for (const QString &entityName : entityNames) {
|
||||
Qt3DCore::QEntity *loadedEntity = loader->entity(entityName);
|
||||
Qt3DCore::QEntity *loadedEntity = guardedLoader->entity(entityName);
|
||||
if (!loadedEntity)
|
||||
continue;
|
||||
if (loader->component(
|
||||
if (guardedLoader->component(
|
||||
entityName,
|
||||
Qt3DRender::QSceneLoader::GeometryRendererComponent)) {
|
||||
attachTeachingPicker(loadedEntity, teachingJointName);
|
||||
@ -1064,7 +1144,7 @@ bool UrdfViewerWidget::loadUrdf(const QString &filePath)
|
||||
attachTeachingPickersRecursively(loadedEntity,
|
||||
teachingJointName);
|
||||
}
|
||||
attachTeachingPickersRecursively(geometryEntity,
|
||||
attachTeachingPickersRecursively(guardedGeometry.data(),
|
||||
teachingJointName);
|
||||
}
|
||||
if (m_view)
|
||||
@ -1638,18 +1718,16 @@ QString UrdfViewerWidget::resolveMeshPath(const QString &uri) const
|
||||
|
||||
void UrdfViewerWidget::scheduleViewAll()
|
||||
{
|
||||
// QCamera::viewEntity() starts a backend bounding-volume query. In Qt
|
||||
// 5.12 on Windows that query can race the first scene synchronization and
|
||||
// crash inside Qt53DRender.dll. The viewer already has a deterministic
|
||||
// camera in resetView(), so only request frames after the scene settles.
|
||||
QTimer::singleShot(120, this, [this]() {
|
||||
if (m_camera && m_modelRoot) {
|
||||
m_camera->viewEntity(m_modelRoot);
|
||||
if (m_view)
|
||||
m_view->requestUpdate();
|
||||
}
|
||||
if (m_view && m_modelRoot)
|
||||
m_view->requestUpdate();
|
||||
});
|
||||
QTimer::singleShot(700, this, [this]() {
|
||||
if (m_camera && m_modelRoot) {
|
||||
m_camera->viewEntity(m_modelRoot);
|
||||
if (m_view)
|
||||
m_view->requestUpdate();
|
||||
}
|
||||
if (m_view && m_modelRoot)
|
||||
m_view->requestUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
307
src/videorenderwidget.cpp
Normal file
307
src/videorenderwidget.cpp
Normal file
@ -0,0 +1,307 @@
|
||||
#include "videorenderwidget.h"
|
||||
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QPainter>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
const char *vertexShaderSource = R"(
|
||||
attribute vec2 position;
|
||||
attribute vec2 texCoord;
|
||||
varying vec2 textureCoordinate;
|
||||
uniform vec2 contentScale;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(position * contentScale, 0.0, 1.0);
|
||||
textureCoordinate = texCoord;
|
||||
}
|
||||
)";
|
||||
|
||||
const char *fragmentShaderSource = R"(
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
varying vec2 textureCoordinate;
|
||||
uniform sampler2D textureY;
|
||||
uniform sampler2D textureU;
|
||||
uniform sampler2D textureV;
|
||||
uniform float pixelFormat;
|
||||
uniform float scaleY;
|
||||
uniform float scaleU;
|
||||
uniform float scaleV;
|
||||
void main()
|
||||
{
|
||||
if (pixelFormat > 1.5) {
|
||||
gl_FragColor = texture2D(textureY, textureCoordinate);
|
||||
return;
|
||||
}
|
||||
|
||||
float y = texture2D(textureY,
|
||||
vec2(textureCoordinate.x * scaleY, textureCoordinate.y)).r;
|
||||
float u;
|
||||
float v;
|
||||
if (pixelFormat > 0.5) {
|
||||
vec4 uv = texture2D(textureU,
|
||||
vec2(textureCoordinate.x * scaleU, textureCoordinate.y));
|
||||
u = uv.r - 0.5;
|
||||
v = uv.a - 0.5;
|
||||
} else {
|
||||
u = texture2D(textureU,
|
||||
vec2(textureCoordinate.x * scaleU, textureCoordinate.y)).r - 0.5;
|
||||
v = texture2D(textureV,
|
||||
vec2(textureCoordinate.x * scaleV, textureCoordinate.y)).r - 0.5;
|
||||
}
|
||||
y = 1.16438356 * (y - 0.0625);
|
||||
gl_FragColor = vec4(y + 1.59602678 * v,
|
||||
y - 0.39176229 * u - 0.81296764 * v,
|
||||
y + 2.01723214 * u, 1.0);
|
||||
}
|
||||
)";
|
||||
}
|
||||
|
||||
VideoRenderWidget::VideoRenderWidget(QWidget *parent)
|
||||
: QOpenGLWidget(parent)
|
||||
{
|
||||
setAutoFillBackground(false);
|
||||
setUpdateBehavior(QOpenGLWidget::NoPartialUpdate);
|
||||
}
|
||||
|
||||
VideoRenderWidget::~VideoRenderWidget()
|
||||
{
|
||||
if (context()) {
|
||||
makeCurrent();
|
||||
releaseTextures();
|
||||
doneCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoRenderWidget::setFrameAspectLayoutEnabled(bool enabled)
|
||||
{
|
||||
m_frameAspectLayout = enabled;
|
||||
QSizePolicy policy(QSizePolicy::Expanding, enabled ? QSizePolicy::Fixed : QSizePolicy::Expanding);
|
||||
policy.setHeightForWidth(enabled);
|
||||
setSizePolicy(policy);
|
||||
if (enabled) updateAspectHeight();
|
||||
else { setMinimumHeight(0); setMaximumHeight(QWIDGETSIZE_MAX); }
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
int VideoRenderWidget::heightForWidth(int width) const
|
||||
{
|
||||
return m_frameAspectLayout ? qMax(1, qRound(double(width) * m_layoutFrameSize.height()
|
||||
/ m_layoutFrameSize.width())) : -1;
|
||||
}
|
||||
|
||||
QSize VideoRenderWidget::sizeHint() const
|
||||
{
|
||||
return m_frameAspectLayout ? QSize(640,heightForWidth(640)) : QOpenGLWidget::sizeHint();
|
||||
}
|
||||
|
||||
void VideoRenderWidget::updateAspectHeight()
|
||||
{
|
||||
if (!m_frameAspectLayout) return;
|
||||
const int wanted = heightForWidth(width());
|
||||
if (minimumHeight() != wanted || maximumHeight() != wanted) setFixedHeight(wanted);
|
||||
}
|
||||
|
||||
void VideoRenderWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QOpenGLWidget::resizeEvent(event);
|
||||
updateAspectHeight();
|
||||
}
|
||||
|
||||
void VideoRenderWidget::setFrame(const VideoFrame &frame)
|
||||
{
|
||||
if (!frame.isValid())
|
||||
return;
|
||||
m_frame = frame;
|
||||
if (m_layoutFrameSize != QSize(frame.width, frame.height)) {
|
||||
m_layoutFrameSize = QSize(frame.width, frame.height);
|
||||
updateAspectHeight();
|
||||
if (m_frameAspectLayout) updateGeometry();
|
||||
}
|
||||
m_message.clear();
|
||||
m_frameDirty = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void VideoRenderWidget::setImage(const QImage &image)
|
||||
{
|
||||
if (image.isNull())
|
||||
return;
|
||||
const QImage converted = image.convertToFormat(QImage::Format_RGBA8888);
|
||||
VideoFrame frame;
|
||||
frame.width = converted.width();
|
||||
frame.height = converted.height();
|
||||
frame.format = VideoPixelFormat::RGBA;
|
||||
frame.stride0 = frame.width * 4;
|
||||
frame.plane0.resize(frame.width * frame.height * 4);
|
||||
for (int row = 0; row < frame.height; ++row) {
|
||||
std::memcpy(frame.plane0.data() + row * frame.width * 4,
|
||||
converted.constScanLine(row), static_cast<size_t>(frame.width * 4));
|
||||
}
|
||||
setFrame(frame);
|
||||
}
|
||||
|
||||
void VideoRenderWidget::clearFrame(const QString &message)
|
||||
{
|
||||
m_frame = VideoFrame();
|
||||
m_message = message;
|
||||
m_frameDirty = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void VideoRenderWidget::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
glClearColor(0.055f, 0.067f, 0.078f, 1.0f);
|
||||
glGenTextures(3, m_textures);
|
||||
|
||||
m_program.reset(new QOpenGLShaderProgram);
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource) ||
|
||||
!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource) ||
|
||||
!m_program->link()) {
|
||||
m_message = QStringLiteral("OpenGL 视频着色器初始化失败:%1").arg(m_program->log());
|
||||
m_program.reset();
|
||||
return;
|
||||
}
|
||||
m_glReady = true;
|
||||
}
|
||||
|
||||
void VideoRenderWidget::uploadPlane(unsigned int texture, int unit, int width,
|
||||
int height, unsigned int format,
|
||||
const QByteArray &data, int textureIndex)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + unit);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (m_textureWidths[textureIndex] != width ||
|
||||
m_textureHeights[textureIndex] != height ||
|
||||
m_textureFormats[textureIndex] != format) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, static_cast<int>(format), width, height, 0,
|
||||
format, GL_UNSIGNED_BYTE, data.constData());
|
||||
m_textureWidths[textureIndex] = width;
|
||||
m_textureHeights[textureIndex] = height;
|
||||
m_textureFormats[textureIndex] = format;
|
||||
} else {
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format,
|
||||
GL_UNSIGNED_BYTE, data.constData());
|
||||
}
|
||||
}
|
||||
|
||||
void VideoRenderWidget::paintGL()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
if (!m_glReady || !m_program || !m_frame.isValid()) {
|
||||
drawMessage(m_message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Qt 5.12's ANGLE backend can upload RGBA QImage data with an incorrect
|
||||
// channel layout. Draw still RGBA frames with the CPU painter instead.
|
||||
if (m_frame.format == VideoPixelFormat::RGBA) {
|
||||
const QImage image(reinterpret_cast<const uchar *>(m_frame.plane0.constData()),
|
||||
m_frame.width, m_frame.height, m_frame.stride0,
|
||||
QImage::Format_RGBA8888);
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), QColor(QStringLiteral("#0e1115")));
|
||||
QSize target = image.size();
|
||||
target.scale(size(), Qt::KeepAspectRatio);
|
||||
const QRect destination((width() - target.width()) / 2,
|
||||
(height() - target.height()) / 2,
|
||||
target.width(), target.height());
|
||||
painter.drawImage(destination, image);
|
||||
m_frameDirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (m_frameDirty) {
|
||||
if (m_frame.format == VideoPixelFormat::I420) {
|
||||
uploadPlane(m_textures[0], 0, m_frame.stride0, m_frame.height,
|
||||
GL_LUMINANCE, m_frame.plane0, 0);
|
||||
uploadPlane(m_textures[1], 1, m_frame.stride1,
|
||||
(m_frame.height + 1) / 2, GL_LUMINANCE, m_frame.plane1, 1);
|
||||
uploadPlane(m_textures[2], 2, m_frame.stride2,
|
||||
(m_frame.height + 1) / 2, GL_LUMINANCE, m_frame.plane2, 2);
|
||||
} else if (m_frame.format == VideoPixelFormat::NV12) {
|
||||
uploadPlane(m_textures[0], 0, m_frame.stride0, m_frame.height,
|
||||
GL_LUMINANCE, m_frame.plane0, 0);
|
||||
uploadPlane(m_textures[1], 1, m_frame.stride1 / 2,
|
||||
(m_frame.height + 1) / 2, GL_LUMINANCE_ALPHA,
|
||||
m_frame.plane1, 1);
|
||||
} else {
|
||||
uploadPlane(m_textures[0], 0, m_frame.width, m_frame.height,
|
||||
GL_RGBA, m_frame.plane0, 0);
|
||||
}
|
||||
m_frameDirty = false;
|
||||
}
|
||||
|
||||
const GLfloat vertices[] = {
|
||||
-1.0f, -1.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 1.0f, 1.0f, 0.0f
|
||||
};
|
||||
float scaleX = 1.0f;
|
||||
float scaleY = 1.0f;
|
||||
const float frameAspect = static_cast<float>(m_frame.width) / m_frame.height;
|
||||
const float widgetAspect = width() > 0 && height() > 0
|
||||
? static_cast<float>(width()) / height() : frameAspect;
|
||||
if (frameAspect > widgetAspect)
|
||||
scaleY = widgetAspect / frameAspect;
|
||||
else
|
||||
scaleX = frameAspect / widgetAspect;
|
||||
|
||||
m_program->bind();
|
||||
m_program->setUniformValue("contentScale", scaleX, scaleY);
|
||||
m_program->setUniformValue("textureY", 0);
|
||||
m_program->setUniformValue("textureU", 1);
|
||||
m_program->setUniformValue("textureV", 2);
|
||||
m_program->setUniformValue("pixelFormat",
|
||||
m_frame.format == VideoPixelFormat::NV12 ? 1.0f :
|
||||
m_frame.format == VideoPixelFormat::RGBA ? 2.0f : 0.0f);
|
||||
m_program->setUniformValue("scaleY", m_frame.format == VideoPixelFormat::RGBA
|
||||
? 1.0f : static_cast<float>(m_frame.width) / m_frame.stride0);
|
||||
m_program->setUniformValue("scaleU", m_frame.format == VideoPixelFormat::NV12
|
||||
? static_cast<float>((m_frame.width + 1) / 2) / (m_frame.stride1 / 2)
|
||||
: static_cast<float>((m_frame.width + 1) / 2) / m_frame.stride1);
|
||||
m_program->setUniformValue("scaleV", m_frame.format == VideoPixelFormat::I420
|
||||
? static_cast<float>((m_frame.width + 1) / 2) / m_frame.stride2 : 1.0f);
|
||||
const int position = m_program->attributeLocation("position");
|
||||
const int texCoord = m_program->attributeLocation("texCoord");
|
||||
m_program->enableAttributeArray(position);
|
||||
m_program->enableAttributeArray(texCoord);
|
||||
m_program->setAttributeArray(position, GL_FLOAT, vertices, 2, 4 * sizeof(GLfloat));
|
||||
m_program->setAttributeArray(texCoord, GL_FLOAT, vertices + 2, 2,
|
||||
4 * sizeof(GLfloat));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
m_program->disableAttributeArray(position);
|
||||
m_program->disableAttributeArray(texCoord);
|
||||
m_program->release();
|
||||
}
|
||||
|
||||
void VideoRenderWidget::drawMessage(const QString &message)
|
||||
{
|
||||
if (message.isEmpty())
|
||||
return;
|
||||
QPainter painter(this);
|
||||
painter.setPen(QColor(QStringLiteral("#8d98a5")));
|
||||
painter.drawText(rect(), Qt::AlignCenter | Qt::TextWordWrap, message);
|
||||
}
|
||||
|
||||
void VideoRenderWidget::releaseTextures()
|
||||
{
|
||||
if (m_textures[0]) {
|
||||
glDeleteTextures(3, m_textures);
|
||||
m_textures[0] = m_textures[1] = m_textures[2] = 0;
|
||||
std::fill(m_textureWidths, m_textureWidths + 3, 0);
|
||||
std::fill(m_textureHeights, m_textureHeights + 3, 0);
|
||||
std::fill(m_textureFormats, m_textureFormats + 3, 0);
|
||||
}
|
||||
}
|
||||
48
styles.qss
48
styles.qss
@ -747,9 +747,51 @@ QTabWidget#armMotionCommandTabs QTabBar::tab:selected {
|
||||
font-weight: 600;
|
||||
}
|
||||
QSplitter#armTargetTables::handle {
|
||||
background: #dfe5ec;
|
||||
width: 1px;
|
||||
margin: 26px 5px 4px 5px;
|
||||
background: transparent;
|
||||
width: 12px;
|
||||
}
|
||||
QWidget#armTargetGroup {
|
||||
background: transparent;
|
||||
}
|
||||
QTableWidget#leftMotionTable,
|
||||
QTableWidget#motionTable {
|
||||
background: #ffffff;
|
||||
alternate-background-color: #f8fafc;
|
||||
border: 1px solid #dce3ea;
|
||||
border-radius: 6px;
|
||||
color: #26323d;
|
||||
}
|
||||
QTableWidget#leftMotionTable QHeaderView::section,
|
||||
QTableWidget#motionTable QHeaderView::section {
|
||||
background: #eef3f7;
|
||||
color: #526171;
|
||||
border: none;
|
||||
border-bottom: 1px solid #d7e0e8;
|
||||
padding: 6px 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
QTableWidget#leftMotionTable::item,
|
||||
QTableWidget#motionTable::item {
|
||||
padding: 3px 8px;
|
||||
border-bottom: 1px solid #edf1f4;
|
||||
}
|
||||
QTableWidget#leftMotionTable QDoubleSpinBox,
|
||||
QTableWidget#motionTable QDoubleSpinBox {
|
||||
min-height: 24px;
|
||||
padding: 1px 7px;
|
||||
background: #f5f8fb;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
color: #1d5fa7;
|
||||
font-weight: 600;
|
||||
}
|
||||
QTableWidget#leftMotionTable QDoubleSpinBox:hover,
|
||||
QTableWidget#motionTable QDoubleSpinBox:hover,
|
||||
QTableWidget#leftMotionTable QDoubleSpinBox:focus,
|
||||
QTableWidget#motionTable QDoubleSpinBox:focus {
|
||||
background: #ffffff;
|
||||
border-color: #6aa7ea;
|
||||
}
|
||||
|
||||
QFrame#urdfToolbar, QFrame#urdfStatusBar {
|
||||
|
||||
@ -20,12 +20,12 @@
|
||||
<layout class="QVBoxLayout" name="controlsLayout">
|
||||
<property name="spacing"><number>12</number></property><property name="leftMargin"><number>18</number></property><property name="topMargin"><number>16</number></property><property name="rightMargin"><number>18</number></property><property name="bottomMargin"><number>18</number></property>
|
||||
<item><widget class="QLabel" name="controlsTitle"><property name="text"><string>CameraService</string></property><property name="objectName"><string>sectionTitle</string></property></widget></item>
|
||||
<item><layout class="QFormLayout" name="deviceForm"><item row="0" column="0"><widget class="QLabel" name="cameraIdLabel"><property name="text"><string>设备 ID</string></property></widget></item><item row="0" column="1"><widget class="QLineEdit" name="cameraIdEdit"><property name="text"><string>camera</string></property></widget></item></layout></item>
|
||||
<item><layout class="QFormLayout" name="deviceForm"><item row="0" column="0"><widget class="QLabel" name="cameraIdLabel"><property name="text"><string>摄像头</string></property></widget></item><item row="0" column="1"><widget class="QComboBox" name="cameraDeviceCombo"><property name="toolTip"><string>由服务端设备列表自动加载</string></property></widget></item></layout></item>
|
||||
<item><widget class="QLabel" name="snapshotTitle"><property name="text"><string>单帧抓图</string></property><property name="objectName"><string>eyebrow</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="snapshotButton"><property name="text"><string>获取 RGB 图像</string></property><property name="objectName"><string>primaryButton</string></property></widget></item>
|
||||
<item><spacer name="controlSpacing"><property name="orientation"><enum>Qt::Vertical</enum></property><property name="sizeType"><enum>QSizePolicy::Fixed</enum></property><property name="sizeHint" stdset="0"><size><width>20</width><height>10</height></size></property></spacer></item>
|
||||
<item><widget class="QLabel" name="streamTitle"><property name="text"><string>实时视频</string></property><property name="objectName"><string>eyebrow</string></property></widget></item>
|
||||
<item><layout class="QFormLayout" name="streamOptionsForm"><item row="0" column="0"><widget class="QLabel" name="codecLabel"><property name="text"><string>解码格式</string></property></widget></item><item row="0" column="1"><widget class="QComboBox" name="codecCombo"><item><property name="text"><string>H.264 / AVC</string></property></item><item><property name="text"><string>H.265 / HEVC</string></property></item></widget></item><item row="1" column="0"><widget class="QLabel" name="streamModeLabel"><property name="text"><string>流模式</string></property></widget></item><item row="1" column="1"><widget class="QComboBox" name="streamModeCombo"><item><property name="text"><string>RGB</string></property><property name="userData"><string>rgb</string></property></item><item><property name="text"><string>Depth</string></property><property name="userData"><string>depth</string></property></item><item><property name="text"><string>RGBD</string></property><property name="userData"><string>rgbd</string></property></item></widget></item></layout></item>
|
||||
<item><layout class="QFormLayout" name="streamOptionsForm"><item row="0" column="0"><widget class="QLabel" name="codecLabel"><property name="text"><string>当前编码器</string></property></widget></item><item row="0" column="1"><widget class="QComboBox" name="codecCombo"><property name="enabled"><bool>false</bool></property><item><property name="text"><string>H.264 / AVC</string></property></item><item><property name="text"><string>H.265 / HEVC</string></property></item></widget></item><item row="1" column="0"><widget class="QLabel" name="streamModeLabel"><property name="text"><string>流模式</string></property></widget></item><item row="1" column="1"><widget class="QComboBox" name="streamModeCombo"><item><property name="text"><string>RGB</string></property><property name="userData"><string>rgb</string></property></item><item><property name="text"><string>Depth</string></property><property name="userData"><string>depth</string></property></item><item><property name="text"><string>RGBD</string></property><property name="userData"><string>rgbd</string></property></item></widget></item></layout></item>
|
||||
<item><widget class="QPushButton" name="cameraStreamButton"><property name="text"><string>开始预览</string></property><property name="objectName"><string>primaryButton</string></property></widget></item>
|
||||
<item><layout class="QHBoxLayout" name="stateLayout"><item><widget class="QLabel" name="streamStateTitle"><property name="text"><string>流状态</string></property><property name="objectName"><string>mutedLabel</string></property></widget></item><item><spacer name="stateSpacer"><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>40</width><height>20</height></size></property></spacer></item><item><widget class="QLabel" name="cameraStreamStateLabel"><property name="text"><string>已停止</string></property><property name="objectName"><string>panelSubtitle</string></property></widget></item></layout></item>
|
||||
<item><spacer name="recordSpacing"><property name="orientation"><enum>Qt::Vertical</enum></property><property name="sizeType"><enum>QSizePolicy::Fixed</enum></property><property name="sizeHint" stdset="0"><size><width>20</width><height>8</height></size></property></spacer></item>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user