27 #include <VirtualRobot/math/Helpers.h>
36 std::lock_guard g{_allMutex};
43 Qt::QueuedConnection);
47 SLOT(onDisconnectComponentQt()),
48 Qt::QueuedConnection);
55 connect(_ui.pushButtonCreateController,
63 connect(_ui.checkBoxAutoKp,
64 SIGNAL(stateChanged(
int)),
67 connect(_ui.checkBoxSetOri,
68 SIGNAL(stateChanged(
int)),
71 connect(_ui.sliderPosVel,
72 SIGNAL(valueChanged(
int)),
77 [&](QPushButton* btn,
float px,
float py,
float pz,
float rx,
float ry,
float rz)
79 _deltaMapPos[btn] = {px, py, pz};
80 _deltaMapOri[btn] = {rx, ry, rz};
85 addBtn(_ui.pushButtonPxp, +1, 0, 0, 0, 0, 0);
86 addBtn(_ui.pushButtonPxn, -1, 0, 0, 0, 0, 0);
87 addBtn(_ui.pushButtonPyp, 0, +1, 0, 0, 0, 0);
88 addBtn(_ui.pushButtonPyn, 0, -1, 0, 0, 0, 0);
89 addBtn(_ui.pushButtonPzp, 0, 0, +1, 0, 0, 0);
90 addBtn(_ui.pushButtonPzn, 0, 0, -1, 0, 0, 0);
92 addBtn(_ui.pushButtonRxp, 0, 0, 0, +1, 0, 0);
93 addBtn(_ui.pushButtonRxn, 0, 0, 0, -1, 0, 0);
94 addBtn(_ui.pushButtonRyp, 0, 0, 0, 0, +1, 0);
95 addBtn(_ui.pushButtonRyn, 0, 0, 0, 0, -1, 0);
96 addBtn(_ui.pushButtonRzp, 0, 0, 0, 0, 0, +1);
97 addBtn(_ui.pushButtonRzn, 0, 0, 0, 0, 0, -1);
100 _timer = startTimer(100);
114 std::lock_guard g{_allMutex};
115 _robotStateComponentName =
116 settings->value(
"rsc",
"Armar6StateComponent").toString().toStdString();
117 _robotUnitName = settings->value(
"ru",
"Armar6Unit").toString().toStdString();
123 std::lock_guard g{_allMutex};
124 settings->setValue(
"rsc", QString::fromStdString(_robotStateComponentName));
125 settings->setValue(
"ru", QString::fromStdString(_robotUnitName));
132 std::lock_guard g{_allMutex};
141 std::lock_guard g{_allMutex};
144 _robotStateComponent =
145 getProxy<RobotStateComponentInterfacePrx>(_robotStateComponentName);
146 _robotUnit = getProxy<RobotUnitInterfacePrx>(_robotUnitName);
151 VirtualRobot::RobotIO::eStructure);
160 _ui.comboBoxSide->addItem(
"Right");
161 _ui.comboBoxSide->addItem(
"Left");
162 _ui.comboBoxSide->setCurrentIndex(0);
167 std::lock_guard g{_allMutex};
168 deleteOldController();
169 _robotStateComponent =
nullptr;
174 std::lock_guard g{_allMutex};
175 deleteOldController();
177 std::string side = _ui.comboBoxSide->currentText().toStdString();
179 VirtualRobot::RobotNodeSetPtr rns = _robot->getRobotNodeSet(side +
"Arm");
181 _ui.gridLayoutNullspaceTargets->removeWidget(_ui.checkBoxExampleJoint1);
182 _ui.gridLayoutNullspaceTargets->removeWidget(_ui.labelExampleJoint1);
183 _ui.gridLayoutNullspaceTargets->removeWidget(_ui.horizontalSliderExampleJoint1);
185 for (
size_t i = 0; i < rns->getSize(); i++)
187 QCheckBox* checkBox =
new QCheckBox(QString::fromStdString(rns->getNode(i)->getName()));
188 QSlider* slider =
new QSlider(Qt::Orientation::Horizontal);
189 slider->setMinimum(rns->getNode(i)->getJointLimitLo() /
M_PI * 180);
190 slider->setMaximum(rns->getNode(i)->getJointLimitHi() /
M_PI * 180);
191 slider->setValue(rns->getNode(i)->getJointValue() /
M_PI * 180);
192 QLabel* label =
new QLabel(QString::number(slider->value()));
193 _ui.gridLayoutNullspaceTargets->addWidget(checkBox, i, 0);
194 _ui.gridLayoutNullspaceTargets->addWidget(slider, i, 1);
195 _ui.gridLayoutNullspaceTargets->addWidget(label, i, 2);
197 SIGNAL(stateChanged(
int)),
201 SIGNAL(valueChanged(
int)),
209 _nullspaceTargets.emplace_back(nt);
213 VirtualRobot::RobotNodePtr cla = rns->getNode(0);
214 VirtualRobot::RobotNodePtr sho1 = rns->getNode(1);
216 cla->setJointValue(0);
217 Eigen::Vector3f shoulder = sho1->getPositionInRootFrame();
218 VirtualRobot::RobotNodePtr elb = rns->getNode(4);
219 VirtualRobot::RobotNodePtr wri1 = rns->getNode(6);
220 VirtualRobot::RobotNodePtr tcp = rns->getTCP();
228 std::vector<float> jointCosts = std::vector<float>(rns->getSize(), 1);
229 jointCosts.at(0) = 4;
233 _tcpTarget = rns->getTCP()->getPoseInRootFrame();
236 float upper_arm_length =
237 (sho1->getPositionInRootFrame() - elb->getPositionInRootFrame()).
norm();
238 float lower_arm_length =
239 (elb->getPositionInRootFrame() - wri1->getPositionInRootFrame()).
norm() +
240 (wri1->getPositionInRootFrame() - tcp->getPositionInRootFrame()).
norm();
243 NJointCartesianNaturalPositionControllerConfigPtr config =
245 config->runCfg.jointCosts = jointCosts;
246 CartesianNaturalPositionControllerConfig runCfg = config->runCfg;
247 updateKpSliders(runCfg);
250 ik, arm, _robotUnit, side +
"NaturalPosition", config));
259 std::lock_guard g{_allMutex};
260 Eigen::Vector3f deltaPos = _deltaMapPos.at(QObject::sender());
261 Eigen::Vector3f deltaOri = _deltaMapOri.at(QObject::sender());
262 newTarget = math::Helpers::TranslatePose(newTarget, deltaPos * _ui.spinBoxDpos->value());
263 if (deltaOri.norm() > 0)
265 deltaOri = deltaOri * _ui.spinBoxDori->value() / 180 *
M_PI;
266 Eigen::AngleAxisf aa(deltaOri.norm(), deltaOri.normalized());
270 updateTarget(newTarget);
273 CartesianNaturalPositionControllerWidgetController::updateTarget(
276 if (!_controller->setTarget(
281 _tcpTarget = newTarget;
282 if (_controller->getDynamicKp().enabled)
284 updateKpSliders(_controller->getRuntimeConfig());
289 CartesianNaturalPositionControllerWidgetController::readRunCfgFromUi(
290 CartesianNaturalPositionControllerConfig& runCfg)
292 runCfg.elbowKp = _ui.sliderKpElbow->value() * 0.01f;
293 runCfg.jointLimitAvoidanceKp = _ui.sliderKpJla->value() * 0.01f;
296 CartesianNaturalPositionControllerWidgetController::updateKpSliderLabels(
297 const CartesianNaturalPositionControllerConfig& runCfg)
299 _ui.labelKpElbow->setText(QString::number(runCfg.elbowKp,
'f', 2));
300 _ui.labelKpJla->setText(QString::number(runCfg.jointLimitAvoidanceKp,
'f', 2));
303 CartesianNaturalPositionControllerWidgetController::updateKpSliders(
304 const CartesianNaturalPositionControllerConfig& runCfg)
306 const QSignalBlocker blockKpElb(_ui.sliderKpElbow);
307 const QSignalBlocker blockKpJla(_ui.sliderKpJla);
308 _ui.sliderKpElbow->setValue(runCfg.elbowKp * 100);
309 _ui.sliderKpJla->setValue(runCfg.jointLimitAvoidanceKp * 100);
310 updateKpSliderLabels(runCfg);
317 CartesianNaturalPositionControllerConfig runCfg = _controller->getRuntimeConfig();
319 readRunCfgFromUi(runCfg);
320 updateKpSliderLabels(runCfg);
321 _controller->setRuntimeConfig(runCfg);
322 _controller->updateBaseKpValues(runCfg);
329 dynamicKp.
enabled = _ui.checkBoxAutoKp->isChecked();
330 _controller->setDynamicKp(dynamicKp);
331 if (_controller->getDynamicKp().enabled)
333 updateKpSliders(_controller->getRuntimeConfig());
340 _setOri = _ui.checkBoxSetOri->isChecked();
341 updateTarget(_tcpTarget);
345 CartesianNaturalPositionControllerWidgetController::updateNullspaceTargets()
347 std::vector<float> nsTargets;
348 for (
const NullspaceTarget& nt : _nullspaceTargets)
350 nsTargets.push_back(nt.checkBox->isChecked() ? nt.slider->value() *
M_PI / 180
352 nt.label->setText(QString::number(nt.slider->value()));
354 _controller->setNullspaceTarget(nsTargets);
360 updateNullspaceTargets();
366 updateNullspaceTargets();
372 _ui.labelPosVel->setText(QString::number(_ui.sliderPosVel->value()));
373 float posVel = _ui.sliderPosVel->value();
374 _controller->setMaxVelocities(posVel);
392 std::lock_guard g{_allMutex};
398 {
"rsc",
"Robot State Component",
"*Component"});
400 return qobject_cast<SimpleConfigDialog*>(_dialog);
406 std::lock_guard g{_allMutex};
407 _robotStateComponentName = _dialog->getProxyName(
"rsc");
408 _robotUnitName = _dialog->getProxyName(
"ru");
441 CartesianNaturalPositionControllerWidgetController::deleteOldController()
443 std::lock_guard g{_allMutex};
446 _controller->cleanup();
451 CartesianNaturalPositionControllerWidgetController::timerEvent(QTimerEvent*)
453 std::lock_guard g{_allMutex};
454 if (!_robot || !_robotStateComponent)
462 _controller->getInternalController()->setVisualizationRobotGlobalPose(
463 _robot->getGlobalPose());