NJointJointSpaceDMPController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/VirtualRobot.h>
5 
7 
8 #include <armarx/control/deprecated_njoint_mp_controller/joint_space/ControllerInterface.h>
9 
10 #include <dmp/representation/systemstatus.h>
11 
12 namespace armarx
13 {
14  class SensorValue1DoFActuatorTorque;
15  class SensorValue1DoFActuatorVelocity;
16  class SensorValue1DoFActuatorPosition;
17  class SensorValue1DoFGravityTorque;
18  class ControlTarget1DoFActuatorTorque;
19  class ControlTarget1DoFActuatorVelocity;
20 } // namespace armarx
21 
22 namespace DMP
23 {
24  // using UMITSMPPtr = boost::shared_ptr<class UMITSMP>;
26 } // namespace DMP
27 
29 {
30 
31  TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPController);
32 
33  TYPEDEF_PTRS_HANDLE(NJointJointSpaceDMPControllerControlData);
34 
36  {
37  public:
38  double tau;
39  bool isStart;
40  };
41 
42  // class SimplePID
43  // {
44  // public:
45  // float Kp = 0, Kd = 0;
46  // float lastError = 0;
47  // float update(float dt, float error);
48  // };
49 
50  /**
51  * @brief The NJointJointSpaceDMPController class
52  * @ingroup Library-RobotUnit-NJointControllers
53  */
55  public NJointControllerWithTripleBuffer<NJointJointSpaceDMPControllerControlData>,
57  {
58  public:
59  using ConfigPtrT = NJointJointSpaceDMPControllerConfigPtr;
61  const NJointControllerConfigPtr& config,
62  const VirtualRobot::RobotPtr&);
63 
64  // NJointControllerInterface interface
65  std::string getClassName(const Ice::Current&) const override;
66 
67  // NJointController interface
68  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
69  const IceUtil::Time& timeSinceLastIteration) override;
70 
71  //
72  bool
73  isFinished(const Ice::Current&) override
74  {
75  return finished;
76  }
77 
78  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
79  void setTemporalFactor(double tau, const Ice::Current&) override;
80 
81  void runDMP(const Ice::DoubleSeq& goals, double tau, const Ice::Current&) override;
82 
83  void showMessages(const Ice::Current&) override;
84 
85  protected:
86  void rtPreActivateController() override;
87  void rtPostDeactivateController() override;
88 
89  virtual void onPublish(const SensorAndControl&,
91  const DebugObserverInterfacePrx&) override;
92 
93  private:
94  struct DebugBufferData
95  {
96  StringFloatDictionary latestTargetVelocities;
97  StringFloatDictionary dmpTargetState;
98  double currentCanVal;
99  double mpcFactor;
100  };
101 
102  std::map<std::string, const SensorValue1DoFActuatorTorque*> torqueSensors;
103  std::map<std::string, const SensorValue1DoFGravityTorque*> gravityTorqueSensors;
104  std::map<std::string, const SensorValue1DoFActuatorPosition*> positionSensors;
105  std::map<std::string, const SensorValue1DoFActuatorVelocity*> velocitySensors;
106  std::map<std::string, ControlTarget1DoFActuatorVelocity*> targets;
107 
108 
109  TripleBuffer<DebugBufferData> debugOutputData;
110 
111 
112  std::vector<double> goals;
113  DMP::UMIDMPPtr dmpPtr;
114  bool DMPAsForwardControl;
115  double timeDuration;
116 
117  double canVal;
118 
119  double tau;
120  double finished;
121 
122  // phaseStop parameters
123  double phaseL;
124  double phaseK;
125  double phaseDist0;
126  double phaseDist1;
127  double phaseKp;
128 
129  double mpcFactor;
130 
131  bool isDisturbance;
132  std::vector<std::string> dimNames;
133  DMP::Vec<DMP::DMPState> currentState;
134  DMP::DVec targetState;
135  };
136 
137 } // namespace armarx::control::deprecated_njoint_mp_controller::joint_space
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointJointSpaceDMPController.cpp:264
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::setTemporalFactor
void setTemporalFactor(double tau, const Ice::Current &) override
Definition: NJointJointSpaceDMPController.cpp:244
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::NJointJointSpaceDMPController
NJointJointSpaceDMPController(RobotUnitPtr prov, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointJointSpaceDMPController.cpp:27
boost::shared_ptr< class UMIDMP >
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData::isStart
bool isStart
Definition: NJointJointSpaceDMPController.h:39
DMP
Definition: NJointTaskSpaceAdaptiveDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointJointSpaceDMPController.cpp:176
DMP::UMIDMPPtr
boost::shared_ptr< class UMIDMP > UMIDMPPtr
Definition: NJointTaskSpaceAdaptiveDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController
The NJointJointSpaceDMPController class.
Definition: NJointJointSpaceDMPController.h:54
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData::tau
double tau
Definition: NJointJointSpaceDMPController.h:38
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPControllerControlData
Definition: NJointJointSpaceDMPController.h:35
armarx::NJointJointSpaceDMPControllerInterface::showMessages
void showMessages()
armarx::NJointJointSpaceDMPControllerInterface
Definition: ControllerInterface.ice:47
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:47
armarx::control::deprecated_njoint_mp_controller::joint_space
Definition: NJointJointSpaceDMPController.cpp:15
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
IceUtil::Handle< class RobotUnit >
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:207
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: NJointJointSpaceDMPController.h:73
armarx::control::deprecated_njoint_mp_controller::joint_space::NJointJointSpaceDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointJointSpaceDMPController.cpp:22
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:259
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::joint_space::NJointJointSpaceDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointJointSpaceDMPController.cpp:74
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:254