NJointBimanualCCDMPController.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include <VirtualRobot/VirtualRobot.h>
5 
8 
11 
13 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ControllerInterface.h>
14 
15 namespace armarx
16 {
17  class SensorValue1DoFActuatorTorque;
18  class SensorValue1DoFActuatorVelocity;
19  class SensorValue1DoFActuatorPosition;
20  class SensorValue1DoFActuatorAcceleration;
21  class ControlTarget1DoFActuatorTorque;
22  class SensorValueForceTorque;
23 } // namespace armarx
24 
25 namespace DMP
26 {
27  // using UMITSMPPtr = boost::shared_ptr<class UMITSMP>;
29 } // namespace DMP
30 
32 {
34 
35  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPController);
36  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPControllerControlData);
37 
38  using ViaPoint = std::pair<double, DMP::DVec>;
39  using ViaPointsSet = std::vector<ViaPoint>;
40 
42  {
43  public:
44  Eigen::VectorXf leftTargetVel;
45  Eigen::VectorXf rightTargetVel;
46 
49 
50  double virtualTime;
51  };
52 
53  /**
54  * @brief The NJointBimanualCCDMPController class
55  * @ingroup Library-RobotUnit-NJointControllers
56  */
58  public NJointControllerWithTripleBuffer<NJointBimanualCCDMPControllerControlData>,
60  {
61  public:
62  using ConfigPtrT = NJointBimanualCCDMPControllerConfigPtr;
64  const NJointControllerConfigPtr& config,
65  const VirtualRobot::RobotPtr&);
66 
67  // NJointControllerInterface interface
68  std::string getClassName(const Ice::Current&) const override;
69 
70  // NJointController interface
71 
72  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
73  const IceUtil::Time& timeSinceLastIteration) override;
74 
75  // NJointBimanualCCDMPControllerInterface interface
76  void
77  learnDMPFromFiles(const std::string&, const Ice::StringSeq&, const Ice::Current&) override;
78  bool isFinished(const Ice::Current&) override;
79 
80  void runDMP(const Ice::DoubleSeq& leftGoals,
81  const Ice::DoubleSeq& rightGoals,
82  const Ice::Current&) override;
83  void
84  setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&) override;
85  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
86 
87  void changeLeader(const Ice::Current&) override;
88 
89  double getVirtualTime(const Ice::Current&) override;
90 
91  std::string getLeaderName(const Ice::Current&) override;
92 
93  protected:
94  virtual void onPublish(const SensorAndControl&,
96  const DebugObserverInterfacePrx&) override;
97 
98  void onInitNJointController() override;
99  void onDisconnectNJointController() override;
100  void controllerRun();
101 
102  private:
103  Eigen::VectorXf getControlWrench(const Eigen::VectorXf& twist,
104  const Eigen::Matrix4f& currentPose,
105  const Eigen::Matrix4f& targetPose);
106 
107  Eigen::Matrix4f getLocalPose(const Eigen::Matrix4f& newCoordinate,
108  const Eigen::Matrix4f& globalTargetPose);
109  Eigen::Matrix4f getLocalPose(const std::vector<double>& newCoordinateVec,
110  const std::vector<double>& globalTargetPoseVec);
111 
112  struct DebugBufferData
113  {
114  StringFloatDictionary desired_torques;
115  StringFloatDictionary constrained_force;
116  float leftTargetPose_x;
117  float leftTargetPose_y;
118  float leftTargetPose_z;
119  float rightTargetPose_x;
120  float rightTargetPose_y;
121  float rightTargetPose_z;
122 
123  float leftCurrentPose_x;
124  float leftCurrentPose_y;
125  float leftCurrentPose_z;
126  float rightCurrentPose_x;
127  float rightCurrentPose_y;
128  float rightCurrentPose_z;
129 
130  float leftControlSignal_x;
131  float leftControlSignal_y;
132  float leftControlSignal_z;
133  float leftControlSignal_ro;
134  float leftControlSignal_pi;
135  float leftControlSignal_ya;
136 
137 
138  float rightControlSignal_x;
139  float rightControlSignal_y;
140  float rightControlSignal_z;
141  float rightControlSignal_ro;
142  float rightControlSignal_pi;
143  float rightControlSignal_ya;
144 
145  // StringFloatDictionary latestTargetVelocities;
146  // StringFloatDictionary dmpTargets;
147  // StringFloatDictionary currentPose;
148 
149  // double leadermpcFactor;
150  // double leadererror;
151  // double leaderposError;
152  // double leaderoriError;
153  // double leaderCanVal;
154 
155  // double followermpcFactor;
156  // double followererror;
157  // double followerposError;
158  // double followeroriError;
159  // double followerCanVal;
160 
161  double virtualTime;
162  };
163 
164  bool finished;
165  TripleBuffer<DebugBufferData> debugDataInfo;
166 
167  struct NJointBimanualCCDMPControllerSensorData
168  {
169  double currentTime;
170  double deltaT;
171  Eigen::Matrix4f currentLeftPose;
172  Eigen::Matrix4f currentRightPose;
173  Eigen::VectorXf currentLeftTwist;
174  Eigen::VectorXf currentRightTwist;
175  };
176 
178 
179  struct NJointBimanualCCDMPControllerInterfaceData
180  {
181  Eigen::Matrix4f currentLeftPose;
182  Eigen::Matrix4f currentRightPose;
183  };
184 
186 
187 
188  std::vector<ControlTarget1DoFActuatorTorque*> leftTargets;
189  std::vector<const SensorValue1DoFActuatorAcceleration*> leftAccelerationSensors;
190  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
191  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
192 
193  std::vector<ControlTarget1DoFActuatorTorque*> rightTargets;
194  std::vector<const SensorValue1DoFActuatorAcceleration*> rightAccelerationSensors;
195  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
196  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
197 
198  const SensorValueForceTorque* rightForceTorque;
199  const SensorValueForceTorque* leftForceTorque;
200 
201  NJointBimanualCCDMPControllerConfigPtr cfg;
202  VirtualRobot::DifferentialIKPtr leftIK;
203  VirtualRobot::DifferentialIKPtr rightIK;
204 
205  std::vector<tsvmp::TaskSpaceDMPControllerPtr> leftGroup;
206  std::vector<tsvmp::TaskSpaceDMPControllerPtr> rightGroup;
207  std::vector<tsvmp::TaskSpaceDMPControllerPtr> bothLeaderGroup;
208 
209 
210  std::string leaderName;
211 
212  VirtualRobot::RobotNodePtr tcpLeft;
213  VirtualRobot::RobotNodePtr tcpRight;
214 
215  double virtualtimer;
216 
217  mutable MutexType controllerMutex;
219 
220  Eigen::VectorXf leftDesiredJointValues;
221  Eigen::VectorXf rightDesiredJointValues;
222 
223  Eigen::Vector3f leftKpos;
224  Eigen::Vector3f leftKori;
225  Eigen::Vector3f leftDpos;
226  Eigen::Vector3f leftDori;
227 
228  Eigen::Vector3f rightKpos;
229  Eigen::Vector3f rightKori;
230  Eigen::Vector3f rightDpos;
231  Eigen::Vector3f rightDori;
232 
233 
234  float knull;
235  float dnull;
236 
237  std::vector<std::string> leftJointNames;
238  std::vector<std::string> rightJointNames;
239 
240  float torqueLimit;
241  VirtualRobot::RobotNodeSetPtr leftRNS;
242  VirtualRobot::RobotNodeSetPtr rightRNS;
243 
244  Eigen::VectorXf leftNullSpaceCoefs;
245  Eigen::VectorXf rightNullSpaceCoefs;
246 
247  float torqueFactor;
248  float startReduceTorque;
249 
250  float maxLinearVel;
251  float maxAngularVel;
252 
253 
254  // NJointBimanualCCDMPControllerInterface interface
255 
256  // NJointController interface
257  protected:
258  void rtPreActivateController() override;
259  };
260 
261 } // namespace armarx::control::deprecated_njoint_mp_controller::bimanual
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData::leftTargetPose
Eigen::Matrix4f leftTargetPose
Definition: NJointBimanualCCDMPController.h:47
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData::rightTargetPose
Eigen::Matrix4f rightTargetPose
Definition: NJointBimanualCCDMPController.h:48
armarx::NJointBimanualCCDMPControllerInterface::getLeaderName
string getLeaderName()
boost::shared_ptr< class UMIDMP >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::NJointBimanualCCDMPController
NJointBimanualCCDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPointsSet
std::vector< ViaPoint > ViaPointsSet
Definition: NJointBimanualCCDMPController.h:39
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointBimanualCCDMPController.cpp:860
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::controllerRun
void controllerRun()
Definition: NJointBimanualCCDMPController.cpp:258
DMP
Definition: NJointTaskSpaceAdaptiveDMPController.h:24
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData::leftTargetVel
Eigen::VectorXf leftTargetVel
Definition: NJointBimanualCCDMPController.h:44
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController
The NJointBimanualCCDMPController class.
Definition: NJointBimanualCCDMPController.h:57
armarx::NJointBimanualCCDMPControllerInterface::getVirtualTime
double getVirtualTime()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::onInitNJointController
void onInitNJointController() override
Definition: NJointBimanualCCDMPController.cpp:941
armarx::NJointBimanualCCDMPControllerInterface::isFinished
bool isFinished()
armarx::NJointBimanualCCDMPControllerInterface::changeLeader
void changeLeader()
PeriodicTask.h
DMP::UMIDMPPtr
boost::shared_ptr< class UMIDMP > UMIDMPPtr
Definition: NJointTaskSpaceAdaptiveDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointBimanualCCDMPController.cpp:442
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: NJointBimanualCCDMPController.cpp:778
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::learnDMPFromFiles
void learnDMPFromFiles(const std::string &, const Ice::StringSeq &, const Ice::Current &) override
Definition: NJointBimanualCCDMPController.cpp:739
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::runDMP
void runDMP(const Ice::DoubleSeq &leftGoals, const Ice::DoubleSeq &rightGoals, const Ice::Current &) override
Definition: NJointBimanualCCDMPController.cpp:811
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointBimanualCCDMPController.cpp:238
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPoint
std::pair< double, DMP::DVec > ViaPoint
Definition: NJointBimanualCCDMPController.h:38
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::NJointBimanualCCDMPControllerInterface
Definition: ControllerInterface.ice:85
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData::virtualTime
double virtualTime
Definition: NJointBimanualCCDMPController.h:50
PIDController.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData
Definition: NJointBimanualCCDMPController.h:41
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: NJointBimanualCCDMPController.cpp:762
armarx::NJointControllerWithTripleBuffer< NJointBimanualCCDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPControllerControlData::rightTargetVel
Eigen::VectorXf rightTargetVel
Definition: NJointBimanualCCDMPController.h:45
IceUtil::Handle< class RobotUnit >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointBimanualCCDMPController.cpp:244
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointBimanualCCDMPController.cpp:949
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:32
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
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)