feat: display arm motor current

This commit is contained in:
linbo 2026-10-13 09:24:03 +08:00
parent 165343b0a3
commit 7804c02631
4 changed files with 9 additions and 2 deletions

View File

@ -176,6 +176,7 @@ message JointState {
repeated double velocity = 3;
repeated double effort = 4;
double timestamp = 5;
repeated double current = 6; // Motor current in mA.
}
message JointRequest {

View File

@ -1198,7 +1198,7 @@ void MainWindow::rebuildArmJointTables(const QStringList &jointNames)
m_jointTable->setRowCount(jointNames.size());
for (int row = 0; row < jointNames.size(); ++row) {
m_jointTable->setItem(row, 0, new QTableWidgetItem(jointNames.at(row)));
for (int column = 1; column < 4; ++column)
for (int column = 1; column < 5; ++column)
m_jointTable->setItem(row, column, new QTableWidgetItem(QStringLiteral("--")));
}
@ -1463,6 +1463,7 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
continue;
const double position = joint.value(QStringLiteral("position")).toDouble();
const double velocity = joint.value(QStringLiteral("velocity")).toDouble();
const double current = joint.value(QStringLiteral("current")).toDouble();
const double acceleration = deltaSeconds > 0.0001
&& m_previousJointVelocities.contains(nameItem->text())
? (velocity - m_previousJointVelocities.value(nameItem->text())) / deltaSeconds
@ -1470,6 +1471,7 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
m_jointTable->item(row, 1)->setText(QString::number(position, 'f', 5));
m_jointTable->item(row, 2)->setText(QString::number(velocity, 'f', 5));
m_jointTable->item(row, 3)->setText(QString::number(acceleration, 'f', 4));
m_jointTable->item(row, 4)->setText(QString::number(current, 'f', 0));
if (m_motionTable) {
for (int targetRow = 0; targetRow < m_motionTable->rowCount(); ++targetRow) {
QTableWidgetItem *targetName = m_motionTable->item(targetRow, 0);

View File

@ -1404,8 +1404,10 @@ QWidget *MainWindow::createArmPage()
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
this, &MainWindow::appendLog);
m_jointTable->setColumnCount(5);
m_jointTable->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("位置 rad"),
QStringLiteral("速度 rad/s"), QStringLiteral("加速度 rad/s²")});
QStringLiteral("速度 rad/s"), QStringLiteral("加速度 rad/s²"),
QStringLiteral("电流 mA")});
m_jointTable->setAlternatingRowColors(true);
m_jointTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_jointTable->setSelectionMode(QAbstractItemView::NoSelection);

View File

@ -2774,6 +2774,7 @@ private:
joint.insert(QStringLiteral("position"), position);
joint.insert(QStringLiteral("velocity"), 0.22 * qCos(phase));
joint.insert(QStringLiteral("effort"), 0.4 + 0.3 * qAbs(qSin(phase * 0.7)));
joint.insert(QStringLiteral("current"), 320.0 + 180.0 * qAbs(qSin(phase * 0.9)));
joints.append(joint);
}
QVariantMap pose;
@ -3399,6 +3400,7 @@ private:
joint.insert(QStringLiteral("position"), i < jointState.position_size() ? jointState.position(i) : 0.0);
joint.insert(QStringLiteral("velocity"), i < jointState.velocity_size() ? jointState.velocity(i) : 0.0);
joint.insert(QStringLiteral("effort"), i < jointState.effort_size() ? jointState.effort(i) : 0.0);
joint.insert(QStringLiteral("current"), i < jointState.current_size() ? jointState.current(i) : 0.0);
joints.append(joint);
}
const auto &tcp = robotState.actual_tcp_pose();