23 #ifndef _ARMARX_LIB_DSController_DSRTBimanualController_H
24 #define _ARMARX_LIB_DSController_DSRTBimanualController_H
26 #include <VirtualRobot/Robot.h>
27 #include <VirtualRobot/Tools/Gravity.h>
28 #include <VirtualRobot/IK/DifferentialIK.h>
37 #include <armarx/control/ds_controller/DSControllerInterface.h>
65 std::vector<double>
Mu_;
102 std::ifstream infile { fileName };
103 std::string objDefs = { std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>() };
111 json->fromString(objDefs);
145 scaling = json->getDouble(
"Scaling");
146 v_max = json->getDouble(
"MaxVelocity");
165 std::cout <<
"line 162." << std::endl;
168 for (
int i = 0; i < 3; ++i)
174 std::cout <<
"Finished GMM." << std::endl;
180 const Eigen::Vector3f& leftarm_PositionInMeter,
181 const Eigen::Vector3f& rightarm_PositionInMeter,
182 float positionErrorToleranceInMeter,
189 position_error.Resize(3);
192 desired_vel.Resize(3);
199 leftarm_Target_corrected(0) += correction_x;
200 rightarm_Target_corrected(0) += correction_x;
202 leftarm_Target_corrected(1) += correction_y;
203 rightarm_Target_corrected(1) += correction_y;
205 leftarm_Target_corrected(2) = desiredZ + correction_z;
206 rightarm_Target_corrected(2) = desiredZ + correction_z;
211 Eigen::Vector3f leftarm_PositionError = leftarm_PositionInMeter - leftarm_Target_corrected;
212 if (leftarm_PositionError.norm() < positionErrorToleranceInMeter)
214 leftarm_PositionError.setZero();
217 for (
int i = 0; i < 3; ++i)
219 position_error(i) = leftarm_PositionError(i);
222 desired_vel =
leftarm_gmm->getVelocity(position_error);
224 Eigen::Vector3f leftarm_desired_vel;
225 leftarm_desired_vel << desired_vel(0), desired_vel(1), desired_vel(2);
227 leftarm_desired_vel =
scaling * leftarm_desired_vel;
229 float lenVec = leftarm_desired_vel.norm();
231 if (std::isnan(lenVec))
233 leftarm_desired_vel.setZero();
247 leftarm_desired_vel = (
v_max / lenVec) * leftarm_desired_vel;
254 Eigen::Vector3f rightarm_PositionError = rightarm_PositionInMeter - rightarm_Target_corrected;
255 if (rightarm_PositionError.norm() < positionErrorToleranceInMeter)
257 rightarm_PositionError.setZero();
260 for (
int i = 0; i < 3; ++i)
262 position_error(i) = rightarm_PositionError(i);
265 desired_vel =
rightarm_gmm->getVelocity(position_error);
267 Eigen::Vector3f rightarm_desired_vel;
268 rightarm_desired_vel << desired_vel(0), desired_vel(1), desired_vel(2);
270 rightarm_desired_vel =
scaling * rightarm_desired_vel;
272 lenVec = rightarm_desired_vel.norm();
273 if (std::isnan(lenVec))
275 rightarm_desired_vel.setZero();
280 rightarm_desired_vel = (
v_max / lenVec) * rightarm_desired_vel;
331 return "DSRTBimanualController";
340 float deadzone(
float currentValue,
float targetValue,
float threshold);
345 struct DSRTBimanualControllerSensorData
353 Eigen::Vector3f left_force;
354 Eigen::Vector3f right_force;
363 struct DSCtrlDebugInfo
367 float guardXYHighFrequency;
368 float guard_mounting_correction_x;
369 float guard_mounting_correction_y;
370 float guard_mounting_correction_z;
376 StringFloatDictionary desired_torques;
377 float desiredForce_x;
378 float desiredForce_y;
379 float desiredForce_z;
380 float tcpDesiredTorque_x;
381 float tcpDesiredTorque_y;
382 float tcpDesiredTorque_z;
384 float tcpDesiredAngularError_x;
385 float tcpDesiredAngularError_y;
386 float tcpDesiredAngularError_z;
388 float currentTCPAngularVelocity_x;
389 float currentTCPAngularVelocity_y;
390 float currentTCPAngularVelocity_z;
392 float currentTCPLinearVelocity_x;
393 float currentTCPLinearVelocity_y;
394 float currentTCPLinearVelocity_z;
397 float left_realForce_x;
398 float left_realForce_y;
399 float left_realForce_z;
400 float right_realForce_x;
401 float right_realForce_y;
402 float right_realForce_z;
403 float left_force_error;
404 float right_force_error;
406 float left_tcpDesiredTorque_x;
407 float left_tcpDesiredTorque_y;
408 float left_tcpDesiredTorque_z;
409 float right_tcpDesiredTorque_x;
410 float right_tcpDesiredTorque_y;
411 float right_tcpDesiredTorque_z;
414 TripleBuffer<DSRTDebugInfo> debugDataInfo;
417 std::vector<const SensorValue1DoFActuatorTorque*> left_torqueSensors;
418 std::vector<const SensorValue1DoFGravityTorque*> left_gravityTorqueSensors;
419 std::vector<const SensorValue1DoFActuatorVelocity*> left_velocitySensors;
420 std::vector<const SensorValue1DoFActuatorPosition*> left_positionSensors;
422 std::vector<const SensorValue1DoFActuatorTorque*> right_torqueSensors;
423 std::vector<const SensorValue1DoFGravityTorque*> right_gravityTorqueSensors;
424 std::vector<const SensorValue1DoFActuatorVelocity*> right_velocitySensors;
425 std::vector<const SensorValue1DoFActuatorPosition*> right_positionSensors;
427 const SensorValueForceTorque* leftForceTorque;
428 const SensorValueForceTorque* rightForceTorque;
430 std::vector<ControlTarget1DoFActuatorTorque*> left_torque_targets;
431 std::vector<ControlTarget1DoFActuatorTorque*> right_torque_targets;
434 VirtualRobot::RobotNodePtr left_arm_tcp;
435 VirtualRobot::RobotNodePtr right_arm_tcp;
437 VirtualRobot::RobotNodePtr left_sensor_frame;
438 VirtualRobot::RobotNodePtr right_sensor_frame;
440 VirtualRobot::DifferentialIKPtr left_ik;
441 Eigen::MatrixXf left_jacobip;
442 Eigen::MatrixXf left_jacobio;
444 VirtualRobot::DifferentialIKPtr right_ik;
445 Eigen::MatrixXf right_jacobip;
446 Eigen::MatrixXf right_jacobio;
449 Eigen::Vector3f left_oldPosition;
453 Eigen::Vector3f right_oldPosition;
456 Eigen::Vector3f left_currentTCPLinearVelocity_filtered;
457 Eigen::Vector3f left_currentTCPAngularVelocity_filtered;
459 Eigen::VectorXf left_jointVelocity_filtered;
460 Eigen::VectorXf right_jointVelocity_filtered;
462 Eigen::VectorXf left_desiredTorques_filtered;
463 Eigen::VectorXf right_desiredTorques_filtered;
466 Eigen::Vector3f left_tcpDesiredTorque_filtered;
467 Eigen::Vector3f right_tcpDesiredTorque_filtered;
469 Eigen::Vector3f leftForceOffset;
470 Eigen::Vector3f rightForceOffset;
472 float left_contactForceZ_correction;
473 float right_contactForceZ_correction;
475 float smooth_startup;
477 DSRTBimanualControllerConfigPtr cfg;
479 Eigen::Vector3f right_currentTCPLinearVelocity_filtered;
480 Eigen::Vector3f right_currentTCPAngularVelocity_filtered;
482 float filterTimeConstant;
484 std::vector<std::string> left_jointNames;
485 std::vector<std::string> right_jointNames;
489 std::vector<float> Damping;
491 float null_torqueLimit;
493 float Coupling_stiffness;
494 float Coupling_force_limit;
502 float nullspaceDamping;
506 float guardTargetZUp;
507 float guardTargetZDown;
509 float guard_mounting_correction_z;
511 float guardXYHighFrequency;
512 Eigen::Vector3f left_force_old;
513 Eigen::Vector3f right_force_old;
515 Eigen::VectorXf left_qnullspace;
516 Eigen::VectorXf right_qnullspace;
526 float forceFilterCoeff;
528 float positionErrorTolerance;
529 bool controllerStopRequested =
false;
530 bool controllerRunFinished =
false;
532 bool isDefaultTarget =
true;
541 unsigned int nJointLeft = 0;
542 unsigned int nJointRight = 0;
544 Eigen::MatrixXf left_jacobi;
545 Eigen::MatrixXf right_jacobi;
547 Eigen::VectorXf left_qpos;
548 Eigen::VectorXf left_qvel;
550 Eigen::VectorXf right_qpos;
551 Eigen::VectorXf right_qvel;
553 Eigen::Vector3f left_forceInRoot;
554 Eigen::Vector3f right_forceInRoot;
558 Eigen::Vector3f left_DS_force;
559 Eigen::Vector3f right_DS_force;
560 Eigen::Vector3f coupling_force;
562 Eigen::Vector3f left_tcpDesiredForce;
563 Eigen::Vector3f right_tcpDesiredForce;
564 Eigen::Vector3f left_tcpDesiredTorque;
565 Eigen::Vector3f right_tcpDesiredTorque;
567 Eigen::VectorXf left_nullspaceTorque;
568 Eigen::VectorXf right_nullspaceTorque;
575 Eigen::VectorXf left_jointDesiredTorques;
576 Eigen::VectorXf right_jointDesiredTorques;
578 Eigen::MatrixXf left_jtpinv;
579 Eigen::MatrixXf right_jtpinv;
581 Eigen::VectorXf left_nullqerror;
582 Eigen::VectorXf right_nullqerror;