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