NJointJSDMPController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <Eigen/Dense>
5 #include <VirtualRobot/Robot.h>
6 
8 
13 
14 #include <dmp/representation/dmp/umidmp.h>
15 
16 // control
17 #include <armarx/control/deprecated_njoint_mp_controller/joint_space/ControllerInterface.h>
18 
19 
21 {
22  TYPEDEF_PTRS_HANDLE(NJointJSDMPController);
23  TYPEDEF_PTRS_HANDLE(NJointJSDMPControllerControlData);
24 
26  {
27  public:
28  Eigen::VectorXf targetJointVels;
29  };
30 
31  /**
32  * @brief The NJointJSDMPController class
33  * @ingroup Library-RobotUnit-NJointControllers
34  */
36  public NJointControllerWithTripleBuffer<NJointJSDMPControllerControlData>,
38  {
39  public:
40  using ConfigPtrT = NJointJointSpaceDMPControllerConfigPtr;
41  NJointJSDMPController(const RobotUnitPtr& robotUnit, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
42 
43  // NJointControllerInterface interface
44  std::string getClassName(const Ice::Current&) const override;
45 
46  // NJointController interface
47  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
48 
49  bool isFinished(const Ice::Current&) override
50  {
51  return finished;
52  }
53 
54  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
55  void setSpeed(double times, const Ice::Current&) override;
56 
57  void runDMP(const Ice::DoubleSeq& goals, double times, const Ice::Current&) override;
58 
59  void showMessages(const Ice::Current&) override;
60  // std::string getDMPAsString(const Ice::Current&) override;
61  std::string getDMPAsString(const Ice::Current&) override;
62  std::vector<double> createDMPFromString(const std::string& dmpString, const Ice::Current&) override;
63  void setViaPoints(Ice::Double u, double viapoint, const Ice::Current&) override;
64 
65  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&) override;
66  DoubleSeqSeq getMPWeights(const Ice::Current&) override;
67 
68 
69  protected:
70  void rtPreActivateController() override;
71  void rtPostDeactivateController() override;
72 
73  virtual void onPublish(const SensorAndControl&, const DebugDrawerInterfacePrx&, const DebugObserverInterfacePrx&) override;
74  private:
75  NJointJointSpaceDMPControllerConfigPtr cfg;
76  struct DebugBufferData
77  {
78  StringFloatDictionary latestTargetVelocities;
79  StringFloatDictionary latestTargets;
80 
81  double currentCanVal;
82  double mpcFactor;
83  };
84  TripleBuffer<DebugBufferData> debugOutputData;
85 
86 
87  struct NJointJSDMPControllerSensorData
88  {
89  double currentTime;
90  double deltaT;
91  DMP::Vec<DMP::DMPState> currentState;
92  };
94 
95  struct RTToUserData
96  {
97  Eigen::VectorXf qpos;
98  Eigen::VectorXf qvel;
99  };
100  TripleBuffer<RTToUserData> rt2UserData;
101 
102 
103  std::map<std::string, const SensorValue1DoFActuatorPosition*> positionSensors;
104  std::map<std::string, const SensorValue1DoFActuatorVelocity*> velocitySensors;
105  std::map<std::string, ControlTarget1DoFActuatorVelocity*> targets;
106 
107  IceUtil::Time last;
108 
109  DMP::UMIDMPPtr dmpPtr;
110  double timeDuration;
111  DMP::Vec<DMP::DMPState> currentState;
112  DMP::Vec<DMP::DMPState> currentDMPState;
113 
114  double canVal;
115  double deltaT;
116  double tau;
117 
118  double finished;
119 
120  // phaseStop parameters
121  double phaseL;
122  double phaseK;
123  double phaseDist0;
124  double phaseDist1;
125  double phaseKp;
126 
127  bool isDisturbance;
128  bool started;
129  std::vector<std::string> dimNames;
130  DMP::DVec targetState;
131  Eigen::VectorXf targetVels;
132 
133  mutable MutexType controllerMutex;
134 
135  Eigen::VectorXf qpos;
136  Eigen::VectorXf qvel;
137  // ManagedIceObject interface
138  protected:
139  void controllerRun();
140  void onInitNJointController() override;
141  void onDisconnectNJointController() override;
142 
143  };
144 
145 } // namespace armarx
146 
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::NJointJSDMPController
NJointJSDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointJSDMPController.cpp:22
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointJSDMPController.cpp:385
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointJSDMPController.cpp:390
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::onInitNJointController
void onInitNJointController() override
Definition: NJointJSDMPController.cpp:419
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::createDMPFromString
std::vector< double > createDMPFromString(const std::string &dmpString, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:335
RunningTask.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPControllerControlData
Definition: NJointJSDMPController.h:25
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::setSpeed
void setSpeed(double times, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:378
armarx::NJointJointSpaceDMPControllerInterface::getDMPAsString
string getDMPAsString()
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::NJointJointSpaceDMPControllerInterface::showMessages
void showMessages()
armarx::NJointJointSpaceDMPControllerInterface
Definition: ControllerInterface.ice:47
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointJSDMPController.cpp:440
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:46
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:227
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointJSDMPController.cpp:395
armarx::control::deprecated_njoint_mp_controller::joint_space
Definition: NJointJointSpaceDMPController.cpp:5
ControlTarget1DoFActuator.h
armarx::NJointJointSpaceDMPControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::setViaPoints
void setViaPoints(Ice::Double u, double viapoint, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:347
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: NJointJSDMPController.h:49
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
NJointController.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:354
armarx::NJointControllerWithTripleBuffer< NJointJSDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::controllerRun
void controllerRun()
Definition: NJointJSDMPController.cpp:84
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::joint_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPController)
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController
The NJointJSDMPController class.
Definition: NJointJSDMPController.h:35
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointJSDMPController.cpp:181
SensorValue1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, double times, const Ice::Current &) override
Definition: NJointJSDMPController.cpp:255
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPControllerControlData::targetJointVels
Eigen::VectorXf targetJointVels
Definition: NJointJSDMPController.h:28
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJSDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointJSDMPController.cpp:17
armarx::TripleBuffer< DebugBufferData >