DeprecatedNJointTSDMPController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 #include <VirtualRobot/Robot.h>
6 #include <VirtualRobot/IK/DifferentialIK.h>
13 
14 #include <dmp/representation/dmp/umitsmp.h>
15 
16 #include <armarx/control/deprecated_njoint_mp_controller/task_space/ControllerInterface.h>
18 
19 
21 {
23 
24  TYPEDEF_PTRS_HANDLE(DeprecatedNJointTSDMPController);
25  TYPEDEF_PTRS_HANDLE(DeprecatedNJointTSDMPControllerControlData);
26 
27  using ViaPoint = std::pair<double, DMP::DVec >;
28  using ViaPointsSet = std::vector<ViaPoint >;
30  {
31  public:
34  // cartesian velocity control data
35  std::vector<float> nullspaceJointVelocities;
36  float avoidJointLimitsKp = 0;
37  std::vector<float> torqueKp;
38  std::vector<float> torqueKd;
39  VirtualRobot::IKSolver::CartesianSelection mode = VirtualRobot::IKSolver::All;
40  };
41 
42  /**
43  * @brief The DeprecatedNJointTSDMPController class
44  * @ingroup Library-RobotUnit-NJointControllers
45  */
47  public NJointControllerWithTripleBuffer<DeprecatedNJointTSDMPControllerControlData>,
49  {
50  class pidController
51  {
52  public:
53  float Kp = 0, Kd = 0;
54  float lastError = 0;
55  float update(float dt, float error)
56  {
57  float derivative = (error - lastError) / dt;
58  float retVal = Kp * error + Kd * derivative;
59  lastError = error;
60  return retVal;
61  }
62  };
63  public:
64  using ConfigPtrT = DeprecatedNJointTaskSpaceDMPControllerConfigPtr;
65  DeprecatedNJointTSDMPController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, 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, const IceUtil::Time& timeSinceLastIteration) override;
73 
74  // DeprecatedNJointTSDMPControllerInterface interface
75  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
76  bool isFinished(const Ice::Current&) override
77  {
78  return finished;
79  }
80 
81  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&) override;
82  void runDMPWithTime(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&) override;
83 
84  void setSpeed(Ice::Double times, const Ice::Current&) override;
85  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&) override;
86  void removeAllViaPoints(const Ice::Current&) override;
87 
88  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
89 
90  void setControllerTarget(Ice::Float avoidJointLimitsKp, NJointTaskSpaceDMPControllerMode::CartesianSelection mode, const Ice::Current&) override;
91  void setTorqueKp(const StringFloatDictionary& torqueKp, const Ice::Current&) override;
92  void setNullspaceJointVelocities(const StringFloatDictionary& nullspaceJointVelocities, const Ice::Current&) override;
93 
94 
95  void pauseDMP(const Ice::Current&) override;
96  void resumeDMP(const Ice::Current&) override;
97 
98  void resetDMP(const Ice::Current&) override;
99  void stopDMP(const Ice::Current&) override;
100  bool isDMPRunning(const Ice::Current&) override
101  {
102  return started;
103  }
104 
105  double getCanVal(const Ice::Current&) override
106  {
107  return dmpCtrl->canVal;
108  }
109  std::string getDMPAsString(const Ice::Current&) override;
110  std::vector<double> createDMPFromString(const std::string& dmpString, const Ice::Current&) override;
111 
112  // VirtualRobot::IKSolver::CartesianSelection ModeFromIce(const DeprecatedNJointTaskSpaceDMPControllerMode::CartesianSelection mode);
113  Eigen::VectorXf calcIK(const Eigen::VectorXf& cartesianVel, const Eigen::VectorXf& nullspace, VirtualRobot::IKSolver::CartesianSelection mode);
114 
115 
116  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&) override;
117  DoubleSeqSeq getMPWeights(const Ice::Current&) override;
118 
119  void setLinearVelocityKd(Ice::Float kd, const Ice::Current& = Ice::emptyCurrent) override;
120  void setLinearVelocityKp(Ice::Float kp, const Ice::Current& = Ice::emptyCurrent) override;
121  void setAngularVelocityKd(Ice::Float kd, const Ice::Current& = Ice::emptyCurrent) override;
122  void setAngularVelocityKp(Ice::Float kp, const Ice::Current& = Ice::emptyCurrent) override;
123 
124  void enableForceStop(const Ice::Current&) override
125  {
126  useForceStop = true;
127  }
128  void disableForceStop(const Ice::Current&) override
129  {
130  useForceStop = false;
131  }
132 
133  void setForceThreshold(const Eigen::Vector3f& f, const Ice::Current& current) override
134  {
135  forceThreshold.getWriteBuffer() = f;
136  forceThreshold.commitWrite();
137  }
138  protected:
139  void rtPreActivateController() override;
140  void rtPostDeactivateController() override;
142  virtual void onPublish(const SensorAndControl&, const DebugDrawerInterfacePrx&, const DebugObserverInterfacePrx&) override;
143 
144  void onInitNJointController() override;
145  void onDisconnectNJointController() override;
146  void controllerRun();
147 
148  private:
149  std::vector<std::string> jointNames;
150  struct DebugBufferData
151  {
152  StringFloatDictionary latestTargetVelocities;
153  StringFloatDictionary dmpTargets;
154  StringFloatDictionary currentPose;
155  double currentCanVal;
156  double mpcFactor;
157  double error;
158  double phaseStop;
159  double posError;
160  double oriError;
161  double deltaT;
162  };
163 
164  TripleBuffer<DebugBufferData> debugOutputData;
165 
166 
167  struct RTDebugData
168  {
169  Eigen::VectorXf targetJointVels;
170  };
171 
172  TripleBuffer<RTDebugData> rtDebugData;
173 
174 
175  struct RTToControllerData
176  {
177  double currentTime;
178  double deltaT;
179  Eigen::Matrix4f currentPose;
180  Eigen::VectorXf currentTwist;
181  };
183 
184  struct RTToUserData
185  {
186  Eigen::Matrix4f currentTcpPose;
187 
188  };
189  TripleBuffer<RTToUserData> rt2UserData;
190 
191 
193 
194  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors;
195  std::vector<const SensorValue1DoFGravityTorque*> gravityTorqueSensors;
196  std::vector<ControlTarget1DoFActuatorVelocity*> targets;
197  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
198  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
199 
200  // velocity ik controller parameters
201  std::vector<pidController> torquePIDs;
202  CartesianVelocityControllerPtr tcpController;
203  std::string nodeSetName;
204 
205  // dmp parameters
206  bool finished;
207  bool started;
208 
209  VirtualRobot::DifferentialIKPtr ik;
210  VirtualRobot::RobotNodePtr tcp;
211  VirtualRobot::RobotNodePtr refFrame;
212  Eigen::Vector6f targetVels;
213  Eigen::Matrix4f targetPose;
214 
215  DeprecatedNJointTaskSpaceDMPControllerConfigPtr cfg;
216  mutable MutexType controllerMutex;
218 
219 
220  std::string debugName;
221 
222  Eigen::VectorXf filtered_qvel;
223  Eigen::Vector3f filtered_position;
224  float vel_filter_factor;
225  float pos_filter_factor;
226  bool firstRun;
227 
228  float KpF;
229  float DpF;
230  float KoF;
231  float DoF;
232 
233  Eigen::VectorXf jointHighLimits;
234  Eigen::VectorXf jointLowLimits;
235 
236  Eigen::Vector3f filteredForce;
237  Eigen::Vector3f forceOffset;
238  Eigen::Vector3f filteredForceInRoot;
239  WriteBufferedTripleBuffer<Eigen::Vector3f> forceThreshold;
240  std::atomic<bool> useForceStop;
241  const SensorValueForceTorque* forceSensor;
242 
243  std::atomic<float> timeForCalibration;
244  std::atomic_bool stopped = false;
245  };
246 
247 } // namespace armarx
248 
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: DeprecatedNJointTSDMPController.cpp:670
armarx::control::deprecated_njoint_mp_controller::task_space::ViaPointsSet
std::vector< ViaPoint > ViaPointsSet
Definition: DeprecatedNJointTSDMPController.h:28
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: DeprecatedNJointTSDMPController.h:33
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: DeprecatedNJointTSDMPController.cpp:664
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::ModeFromIce
VirtualRobot::IKSolver::CartesianSelection ModeFromIce(const NJointTaskSpaceDMPControllerMode::CartesianSelection mode)
Definition: DeprecatedNJointTSDMPController.cpp:571
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::DeprecatedNJointTSDMPController
DeprecatedNJointTSDMPController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: DeprecatedNJointTSDMPController.cpp:27
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::isDMPRunning
bool isDMPRunning(const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.h:100
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::resumeDMP
void resumeDMP()
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:757
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface
Definition: ControllerInterface.ice:350
armarx::WriteBufferedTripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:326
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::targetTSVel
Eigen::Vector6f targetTSVel
Definition: DeprecatedNJointTSDMPController.h:32
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:434
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::disableForceStop
void disableForceStop(const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.h:128
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
SensorValueForceTorque.h
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::stopDMP
void stopDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::ViaPoint
std::pair< double, DMP::DVec > ViaPoint
Definition: DeprecatedNJointTSDMPController.h:27
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::CartesianVelocityControllerPtr
std::shared_ptr< CartesianVelocityController > CartesianVelocityControllerPtr
Definition: CartesianVelocityController.h:34
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::enableForceStop
void enableForceStop(const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.h:124
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:453
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setControllerTarget
void setControllerTarget(Ice::Float avoidJointLimitsKp, NJointTaskSpaceDMPControllerMode::CartesianSelection mode, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:492
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController
The DeprecatedNJointTSDMPController class.
Definition: DeprecatedNJointTSDMPController.h:46
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:445
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::nullspaceJointVelocities
std::vector< float > nullspaceJointVelocities
Definition: DeprecatedNJointTSDMPController.h:35
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::mode
VirtualRobot::IKSolver::CartesianSelection mode
Definition: DeprecatedNJointTSDMPController.h:39
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::torqueKd
std::vector< float > torqueKd
Definition: DeprecatedNJointTSDMPController.h:38
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: DeprecatedNJointTSDMPController.cpp:659
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: DeprecatedNJointTSDMPController.cpp:270
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::controllerRun
void controllerRun()
Definition: DeprecatedNJointTSDMPController.cpp:173
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::pauseDMP
void pauseDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::createDMPFromString
std::vector< double > createDMPFromString(const std::string &dmpString, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:562
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::runDMPWithTime
void runDMPWithTime(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:628
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setNullspaceJointVelocities
void setNullspaceJointVelocities(const StringFloatDictionary &nullspaceJointVelocities, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:477
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::avoidJointLimitsKp
float avoidJointLimitsKp
Definition: DeprecatedNJointTSDMPController.h:36
ControlTarget1DoFActuator.h
armarx::WriteBufferedTripleBuffer::getWriteBuffer
T & getWriteBuffer()
Definition: TripleBuffer.h:280
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: DeprecatedNJointTSDMPController.cpp:751
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
TaskSpaceVMP.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setAngularVelocityKp
void setAngularVelocityKp(Ice::Float kp, const Ice::Current &=Ice::emptyCurrent) override
Definition: DeprecatedNJointTSDMPController.cpp:801
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setAngularVelocityKd
void setAngularVelocityKd(Ice::Float kd, const Ice::Current &=Ice::emptyCurrent) override
Definition: DeprecatedNJointTSDMPController.cpp:795
CartesianVelocityController.h
CycleUtil.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::task_space::DeprecatedNJointTSDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.h:76
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setForceThreshold
void setForceThreshold(const Eigen::Vector3f &f, const Ice::Current &current) override
Definition: DeprecatedNJointTSDMPController.h:133
armarx::NJointControllerWithTripleBuffer< DeprecatedNJointTSDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData
Definition: DeprecatedNJointTSDMPController.h:29
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::calcIK
Eigen::VectorXf calcIK(const Eigen::VectorXf &cartesianVel, const Eigen::VectorXf &nullspace, VirtualRobot::IKSolver::CartesianSelection mode)
Definition: DeprecatedNJointTSDMPController.cpp:239
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double tau, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:592
armarx::control::deprecated_njoint_mp_controller::task_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController)
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setLinearVelocityKp
void setLinearVelocityKp(Ice::Float kp, const Ice::Current &=Ice::emptyCurrent) override
Definition: DeprecatedNJointTSDMPController.cpp:789
Eigen::Matrix< float, 6, 1 >
armarx::DeprecatedNJointTaskSpaceDMPControllerInterface::getDMPAsString
string getDMPAsString()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setTorqueKp
void setTorqueKp(const StringFloatDictionary &torqueKp, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:463
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPControllerControlData::torqueKp
std::vector< float > torqueKp
Definition: DeprecatedNJointTSDMPController.h:37
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setLinearVelocityKd
void setLinearVelocityKd(Ice::Float kd, const Ice::Current &=Ice::emptyCurrent) override
Definition: DeprecatedNJointTSDMPController.cpp:783
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::getCanVal
double getCanVal(const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.h:105
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: DeprecatedNJointTSDMPController.cpp:514
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:42
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::onInitNJointController
void onInitNJointController() override
Definition: DeprecatedNJointTSDMPController.cpp:729
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTSDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: DeprecatedNJointTSDMPController.cpp:167
armarx::TripleBuffer< DebugBufferData >