NJointBimanualForceMPController.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 // Simox
5 #include <VirtualRobot/Robot.h>
6 #include <VirtualRobot/IK/DifferentialIK.h>
7 
8 // DMP
9 #include <dmp/representation/dmp/umitsmp.h>
10 
11 // armarx
19 
20 // control
21 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ForceMPControllerInterface.h>
23 
24 
26 {
28 
29  TYPEDEF_PTRS_HANDLE(NJointBimanualForceMPController);
30  TYPEDEF_PTRS_HANDLE(NJointBimanualForceMPControllerControlData);
31 
32  using ViaPoint = std::pair<double, DMP::DVec >;
33  using ViaPointsSet = std::vector<ViaPoint >;
35  {
36  public:
39  };
40 
41  /**
42  * @brief The NJointBimanualForceMPController class
43  * @ingroup Library-RobotUnit-NJointControllers
44  */
46  public NJointControllerWithTripleBuffer<NJointBimanualForceMPControllerControlData>,
48  {
49  public:
50  using ConfigPtrT = NJointBimanualForceMPControllerConfigPtr;
51  NJointBimanualForceMPController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
52 
53  // NJointControllerInterface interface
54  std::string getClassName(const Ice::Current&) const override;
55 
56  // NJointController interface
57 
58  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
59 
60  // NJointBimanualForceMPControllerInterface interface
61  void learnDMPFromFiles(const std::string& whichMP, const Ice::StringSeq& fileNames, const Ice::Current&) override;
62  bool isFinished(const Ice::Current&) override
63  {
64  return finished;
65  }
66 
67  void runDMP(const Ice::DoubleSeq& leftGoals, const Ice::DoubleSeq& rightGoals, const Ice::Current&) override;
68 
69  double getCanVal(const Ice::Current&) override
70  {
71  return canVal;
72  }
73 
74  void setViaPoints(const std::string& whichDMP, double canVal, const Ice::DoubleSeq& viaPoint, const Ice::Current&) override;
75 
76  protected:
77  virtual void onPublish(const SensorAndControl&, const DebugDrawerInterfacePrx&, const DebugObserverInterfacePrx&) override;
78 
79  void onInitNJointController() override;
80  void onDisconnectNJointController() override;
81 
82  void controllerRun();
83  private:
84  struct DebugBufferData
85  {
86  StringFloatDictionary dmpTargets;
87  StringFloatDictionary currentPose;
88  double canVal;
89  float forceOnHands;
90  };
91  TripleBuffer<DebugBufferData> debugOutputData;
92 
93  struct NJointBimanualForceMPControllerSensorData
94  {
95  Eigen::Matrix4f leftPoseInRootFrame;
96  Eigen::Vector6f leftTwistInRootFrame;
97 
98  Eigen::Matrix4f rightPoseInRootFrame;
99  Eigen::Vector6f rightTwistInRootFrame;
100 
101  Eigen::Vector3f leftForceInRootFrame;
102  Eigen::Vector3f rightForceInRootFrame;
103  double deltaT;
104  };
106 
107  struct NJointBimanualForceMPControllerInterfaceData
108  {
109  Eigen::Matrix4f leftTcpPoseInRootFrame;
110  Eigen::Matrix4f rightTcpPoseInRootFrame;
111  };
113 
114  std::vector<ControlTarget1DoFActuatorVelocity*> leftTargets;
115  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
116  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
117 
118  std::vector<ControlTarget1DoFActuatorVelocity*> rightTargets;
119  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
120  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
121 
122  const SensorValueForceTorque* rightForceTorque;
123  const SensorValueForceTorque* leftForceTorque;
124 
125  VirtualRobot::DifferentialIKPtr leftIK;
126  VirtualRobot::DifferentialIKPtr rightIK;
127 
128 
129  tsvmp::TaskSpaceDMPControllerPtr leftDMPController;
130  tsvmp::TaskSpaceDMPControllerPtr rightDMPController;
131 
132  // velocity ik controller parameters
133  CartesianVelocityControllerPtr leftTCPController;
134  CartesianVelocityControllerPtr rightTCPController;
135 
136  // dmp parameters
137  bool finished;
138  VirtualRobot::RobotNodePtr leftTCP;
139  VirtualRobot::RobotNodePtr rightTCP;
140 
141 
142  Eigen::VectorXf targetVels;
143  Eigen::Matrix4f targetPose;
144 
145  NJointBimanualForceMPControllerConfigPtr cfg;
146  mutable MutexType controllerMutex;
148 
149  // velocity control
150  float Kp_LinearVel;
151  float Kd_LinearVel;
152  float Kp_AngularVel;
153  float Kd_AngularVel;
154 
155  // force control
156  float Kp_f;
157  float Kd_f;
158  float Ki_f;
159 
160  double canVal;
161  double xvel;
162 
163  float forceIterm;
164  bool leftLearned;
165  bool rightLearned;
166 
167  Eigen::Vector3f leftFilteredValue;
168  Eigen::Vector3f rightFilteredValue;
169 
170  Eigen::Vector3f leftForceOffset;
171  Eigen::Vector3f rightForceOffset;
172  float targetSupportForce;
173 
174  double I_decay;
175 
176  float forceSign;
177 
178  };
179 
180 } // namespace armarx
181 
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::learnDMPFromFiles
void learnDMPFromFiles(const std::string &whichMP, const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointBimanualForceMPController.cpp:425
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointBimanualForceMPController.cpp:156
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPointsSet
std::vector< ViaPoint > ViaPointsSet
Definition: NJointBimanualCCDMPController.h:34
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::getCanVal
double getCanVal(const Ice::Current &) override
Definition: NJointBimanualForceMPController.h:69
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPControllerControlData
Definition: NJointBimanualForceMPController.h:34
SensorValueForceTorque.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPControllerControlData::leftTargetPose
Eigen::Matrix4f leftTargetPose
Definition: NJointBimanualForceMPController.h:37
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController
The NJointBimanualForceMPController class.
Definition: NJointBimanualForceMPController.h:45
armarx::CartesianVelocityControllerPtr
std::shared_ptr< CartesianVelocityController > CartesianVelocityControllerPtr
Definition: CartesianVelocityController.h:34
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointBimanualForceMPController.cpp:258
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: NJointBimanualForceMPController.h:62
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPoint
std::pair< double, DMP::DVec > ViaPoint
Definition: NJointBimanualCCDMPController.h:33
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPControllerControlData::rightTargetPose
Eigen::Matrix4f rightTargetPose
Definition: NJointBimanualForceMPController.h:38
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::setViaPoints
void setViaPoints(const std::string &whichDMP, double canVal, const Ice::DoubleSeq &viaPoint, const Ice::Current &) override
Definition: NJointBimanualForceMPController.cpp:487
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
CartesianVelocityController.h
PIDController.h
NJointController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::onInitNJointController
void onInitNJointController() override
Definition: NJointBimanualForceMPController.cpp:537
armarx::NJointControllerWithTripleBuffer< NJointBimanualForceMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::NJointBimanualForceMPControllerInterface
Definition: ForceMPControllerInterface.ice:157
IceUtil::Handle
Definition: forward_declarations.h:29
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
Eigen::Matrix< float, 6, 1 >
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:31
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::runDMP
void runDMP(const Ice::DoubleSeq &leftGoals, const Ice::DoubleSeq &rightGoals, const Ice::Current &) override
Definition: NJointBimanualForceMPController.cpp:446
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointBimanualForceMPController.cpp:503
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::controllerRun
void controllerRun()
Definition: NJointBimanualForceMPController.cpp:162
SensorValue1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointBimanualForceMPController.cpp:545
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceMPController::NJointBimanualForceMPController
NJointBimanualForceMPController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualForceMPController.cpp:11
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::bimanual
Definition: NJointBimanualCartesianAdmittanceController.cpp:9
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::bimanual::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointBimanualCartesianAdmittanceController)