26 #include <VirtualRobot/RobotNodeSet.h>
30 #include "../RobotUnit.h"
32 #define DEFAULT_TCP_STRING "default TCP"
37 NJointControllerRegistration<NJointCartesianVelocityControllerWithRamp>
39 "NJointCartesianVelocityControllerWithRamp");
44 return "NJointCartesianVelocityControllerWithRamp";
49 const NJointCartesianVelocityControllerWithRampConfigPtr& config,
55 VirtualRobot::RobotNodeSetPtr rns =
rtGetRobot()->getRobotNodeSet(config->nodeSetName);
57 for (
size_t i = 0; i < rns->getSize(); ++i)
59 std::string jointName = rns->getNode(i)->getName();
62 targets.push_back(ct->
asA<ControlTarget1DoFActuatorVelocity>());
64 const SensorValue1DoFActuatorFilteredVelocity* filteredVelocitySensor =
65 sv->
asA<SensorValue1DoFActuatorFilteredVelocity>();
66 const SensorValue1DoFActuatorVelocity* velocitySensor =
67 sv->
asA<SensorValue1DoFActuatorVelocity>();
69 if (filteredVelocitySensor)
72 velocitySensors.push_back(&filteredVelocitySensor->filteredvelocity);
74 else if (velocitySensor)
77 velocitySensors.push_back(&velocitySensor->velocity);
81 VirtualRobot::RobotNodePtr tcp =
87 nodeSetName = config->nodeSetName;
88 jointLimitAvoidanceScale = config->jointLimitAvoidanceScale;
89 KpJointLimitAvoidance = config->KpJointLimitAvoidance;
94 Eigen::VectorXf::Zero(rns->getSize()),
96 config->maxPositionAcceleration,
97 config->maxOrientationAcceleration,
98 config->maxNullspaceAcceleration));
104 #pragma GCC diagnostic push
105 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
106 Eigen::VectorXf currentJointVelocities(velocitySensors.size());
107 for (
size_t i = 0; i < velocitySensors.size(); i++)
109 currentJointVelocities(i) = *velocitySensors.at(i);
111 controller->setCurrentJointVelocity(currentJointVelocities);
112 #pragma GCC diagnostic pop
113 ARMARX_IMPORTANT <<
"initial joint velocities: " << currentJointVelocities.transpose();
121 if (mode == VirtualRobot::IKSolver::All)
145 Eigen::VectorXf jnv =
146 KpJointLimitAvoidance *
controller->controller.calculateJointLimitAvoidance();
147 jnv +=
controller->controller.calculateNullspaceVelocity(x, jointLimitAvoidanceScale, mode);
148 Eigen::VectorXf jointTargetVelocities =
149 controller->calculate(x, jnv, timeSinceLastIteration.toSecondsDouble());
150 for (
size_t i = 0; i < targets.size(); ++i)
152 targets.at(i)->velocity = jointTargetVelocities(i);
158 float maxOrientationAcceleration,
159 float maxNullspaceAcceleration,
163 maxPositionAcceleration, maxOrientationAcceleration, maxNullspaceAcceleration);
187 float jointLimitAvoidanceScale,
190 this->jointLimitAvoidanceScale = jointLimitAvoidanceScale;
197 this->KpJointLimitAvoidance = KpJointLimitAvoidance;
204 #pragma GCC diagnostic push
205 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
206 controller->setCurrentJointVelocity(Eigen::VectorXf::Zero(velocitySensors.size()));
207 #pragma GCC diagnostic pop
237 const std::string& name,
241 if (name ==
"ControllerTarget")
250 KpJointLimitAvoidance = valueMap.at(
"KpJointLimitAvoidance")->getFloat();
251 jointLimitAvoidanceScale = valueMap.at(
"jointLimitAvoidanceScale")->getFloat();
254 else if (name ==
"ControllerParameters")
258 valueMap.at(
"maxOrientationAcceleration")->getFloat(),
259 valueMap.at(
"maxNullspaceAcceleration")->getFloat());
267 WidgetDescription::VBoxLayoutPtr
278 layout.
addSlider(
"KpJointLimitAvoidance", -10, 10, KpJointLimitAvoidance);
279 layout.
addSlider(
"jointLimitAvoidanceScale", -10, 10, jointLimitAvoidanceScale);
283 WidgetDescription::VBoxLayoutPtr
288 "maxPositionAcceleration", 0, 1000,
controller->getMaxPositionAcceleration());
290 "maxOrientationAcceleration", 0, 100,
controller->getMaxOrientationAcceleration());
292 "maxNullspaceAcceleration", 0, 100,
controller->getMaxNullspaceAcceleration());
299 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
300 const std::map<std::string, ConstSensorDevicePtr>&)
305 LabelPtr label =
new Label;
306 label->text =
"nodeset name";
307 layout->children.emplace_back(label);
308 StringComboBoxPtr box =
new StringComboBox;
309 box->defaultIndex = 0;
311 box->options = robot->getRobotNodeSetNames();
312 box->name =
"nodeSetName";
313 layout->children.emplace_back(box);
315 LabelPtr labelTCP =
new Label;
316 labelTCP->text =
"tcp name";
317 layout->children.emplace_back(labelTCP);
318 StringComboBoxPtr boxTCP =
new StringComboBox;
319 boxTCP->defaultIndex = 0;
321 boxTCP->options = robot->getRobotNodeNames();
323 boxTCP->name =
"tcpName";
324 layout->children.emplace_back(boxTCP);
326 LabelPtr labelMode =
new Label;
327 labelMode->text =
"mode";
328 layout->children.emplace_back(labelMode);
329 StringComboBoxPtr boxMode =
new StringComboBox;
331 boxMode->options = {
"Position",
"Orientation",
"Both"};
332 boxMode->name =
"mode";
333 layout->children.emplace_back(boxMode);
334 layout->children.emplace_back(
new HSpacer);
335 boxMode->defaultIndex = 2;
338 auto addSlider = [&](
const std::string& label,
float max,
float defaultValue)
340 layout->children.emplace_back(
new Label(
false, label));
342 floatSlider->name = label;
343 floatSlider->min = 0;
344 floatSlider->defaultValue = defaultValue;
345 floatSlider->max =
max;
346 layout->children.emplace_back(floatSlider);
348 addSlider(
"maxPositionAcceleration", 1000, 100);
349 addSlider(
"maxOrientationAcceleration", 10, 1);
350 addSlider(
"maxNullspaceAcceleration", 10, 2);
351 addSlider(
"KpJointLimitAvoidance", 10, 2);
352 addSlider(
"jointLimitAvoidanceScale", 10, 2);
357 NJointCartesianVelocityControllerWithRampConfigPtr
361 return new NJointCartesianVelocityControllerWithRampConfig(
362 values.at(
"nodeSetName")->getString(),
363 values.at(
"tcpName")->getString(),
365 values.at(
"maxPositionAcceleration")->getFloat(),
366 values.at(
"maxOrientationAcceleration")->getFloat(),
367 values.at(
"maxNullspaceAcceleration")->getFloat(),
368 values.at(
"KpJointLimitAvoidance")->getFloat(),
369 values.at(
"jointLimitAvoidanceScale")->getFloat());
376 if (mode ==
"Position")
380 if (mode ==
"Orientation")
386 return VirtualRobot::IKSolver::CartesianSelection::All;
395 if (mode ==
"Position")
399 if (mode ==
"Orientation")
425 return VirtualRobot::IKSolver::CartesianSelection::All;