NJointJointSpaceDMPController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/Robot.h>
5 #include <dmp/representation/dmp/umidmp.h>
6 
11 
12 // control
13 #include <armarx/control/deprecated_njoint_mp_controller/joint_space/ControllerInterface.h>
14 
15 
17 {
18 
19  TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPController);
20 
21  TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPControllerControlData);
23  {
24  public:
25  double tau;
26  bool isStart;
27  };
28 
29 
30  // class SimplePID
31  // {
32  // public:
33  // float Kp = 0, Kd = 0;
34  // float lastError = 0;
35  // float update(float dt, float error);
36  // };
37 
38  /**
39  * @brief The NJointJointSpaceDMPController class
40  * @ingroup Library-RobotUnit-NJointControllers
41  */
43  public NJointControllerWithTripleBuffer<NJointJointSpaceDMPControllerControlData>,
45  {
46  public:
47  using ConfigPtrT = NJointJointSpaceDMPControllerConfigPtr;
48  NJointJointSpaceDMPController(RobotUnitPtr prov, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
49 
50  // NJointControllerInterface interface
51  std::string getClassName(const Ice::Current&) const override;
52 
53  // NJointController interface
54  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
55 
56  //
57  bool isFinished(const Ice::Current&) override
58  {
59  return finished;
60  }
61 
62  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
63  void setTemporalFactor(double tau, const Ice::Current&) override;
64 
65  void runDMP(const Ice::DoubleSeq& goals, double tau, const Ice::Current&) override;
66 
67  void showMessages(const Ice::Current&) override;
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 
76  struct DebugBufferData
77  {
78  StringFloatDictionary latestTargetVelocities;
79  StringFloatDictionary dmpTargetState;
80  double currentCanVal;
81  double mpcFactor;
82  };
83 
84  std::map<std::string, const SensorValue1DoFActuatorTorque*> torqueSensors;
85  std::map<std::string, const SensorValue1DoFGravityTorque*> gravityTorqueSensors;
86  std::map<std::string, const SensorValue1DoFActuatorPosition*> positionSensors;
87  std::map<std::string, const SensorValue1DoFActuatorVelocity*> velocitySensors;
88  std::map<std::string, ControlTarget1DoFActuatorVelocity*> targets;
89 
90 
91  TripleBuffer<DebugBufferData> debugOutputData;
92 
93 
94  std::vector<double> goals;
95  DMP::UMIDMPPtr dmpPtr;
96  bool DMPAsForwardControl;
97  double timeDuration;
98 
99  double canVal;
100 
101  double tau;
102  double finished;
103 
104  // phaseStop parameters
105  double phaseL;
106  double phaseK;
107  double phaseDist0;
108  double phaseDist1;
109  double phaseKp;
110 
111  double mpcFactor;
112 
113  bool isDisturbance;
114  std::vector<std::string> dimNames;
115  DMP::Vec<DMP::DMPState> currentState;
116  DMP::DVec targetState;
117 
118  };
119 
120 } // namespace armarx
121 
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointJointSpaceDMPController.cpp:226
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::setTemporalFactor
void setTemporalFactor(double tau, const Ice::Current &) override
Definition: NJointJointSpaceDMPController.cpp:208
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::NJointJointSpaceDMPController
NJointJointSpaceDMPController(RobotUnitPtr prov, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointJointSpaceDMPController.cpp:15
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData::isStart
bool isStart
Definition: NJointJointSpaceDMPController.h:26
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointJointSpaceDMPController.cpp:149
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController
The NJointJointSpaceDMPController class.
Definition: NJointJointSpaceDMPController.h:42
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData::tau
double tau
Definition: NJointJointSpaceDMPController.h:25
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData
Definition: NJointJointSpaceDMPController.h:22
armarx::NJointJointSpaceDMPControllerInterface::showMessages
void showMessages()
armarx::NJointJointSpaceDMPControllerInterface
Definition: ControllerInterface.ice:47
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:46
armarx::control::deprecated_njoint_mp_controller::joint_space
Definition: NJointJointSpaceDMPController.cpp:5
ControlTarget1DoFActuator.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
NJointController.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, double tau, const Ice::Current &) override
Definition: NJointJointSpaceDMPController.cpp:178
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: NJointJointSpaceDMPController.h:57
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointJointSpaceDMPController.cpp:10
armarx::control::deprecated_njoint_mp_controller::joint_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPController)
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointJointSpaceDMPController.cpp:221
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointJointSpaceDMPController.cpp:53
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointJointSpaceDMPController.cpp:217