NJointJSDMPController.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <boost/shared_ptr.hpp>
5
6#include <Eigen/Dense>
7
8#include <VirtualRobot/VirtualRobot.h>
9
11
13
14#include <armarx/control/deprecated_njoint_mp_controller/joint_space/ControllerInterface.h>
15
16#include <dmp/general/vec.h>
17#include <dmp/representation/systemstatus.h>
18
19namespace armarx
20{
21 class SensorValue1DoFActuatorTorque;
22 class SensorValue1DoFActuatorVelocity;
23 class SensorValue1DoFActuatorPosition;
24 class ControlTarget1DoFActuatorTorque;
25 class ControlTarget1DoFActuatorVelocity;
26} // namespace armarx
27
28namespace DMP
29{
30 // using UMITSMPPtr = boost::shared_ptr<class UMITSMP>;
31 using UMIDMPPtr = ::boost::shared_ptr<class UMIDMP>;
32} // namespace DMP
33
35{
38
40 {
41 public:
42 Eigen::VectorXf targetJointVels;
43 };
44
45 /**
46 * @brief The NJointJSDMPController class
47 * @ingroup Library-RobotUnit-NJointControllers
48 */
50 public NJointControllerWithTripleBuffer<NJointJSDMPControllerControlData>,
52 {
53 public:
54 using ConfigPtrT = NJointJointSpaceDMPControllerConfigPtr;
55 NJointJSDMPController(const RobotUnitPtr& robotUnit,
56 const NJointControllerConfigPtr& config,
58
59 // NJointControllerInterface interface
60 std::string getClassName(const Ice::Current&) const override;
61
62 // NJointController interface
63 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
64 const IceUtil::Time& timeSinceLastIteration) override;
65
66 bool
67 isFinished(const Ice::Current&) override
68 {
69 return finished;
70 }
71
72 void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
73 void setSpeed(double times, const Ice::Current&) override;
74
75 void runDMP(const Ice::DoubleSeq& goals, double times, const Ice::Current&) override;
76
77 void showMessages(const Ice::Current&) override;
78 // std::string getDMPAsString(const Ice::Current&) override;
79 std::string getDMPAsString(const Ice::Current&) override;
80 std::vector<double> createDMPFromString(const std::string& dmpString,
81 const Ice::Current&) override;
82 void setViaPoints(Ice::Double u, double viapoint, const Ice::Current&) override;
83
84 void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&) override;
85 DoubleSeqSeq getMPWeights(const Ice::Current&) override;
86
87
88 protected:
89 void rtPreActivateController() override;
90 void rtPostDeactivateController() override;
91
92 virtual void onPublish(const SensorAndControl&,
94 const DebugObserverInterfacePrx&) override;
95
96 private:
97 NJointJointSpaceDMPControllerConfigPtr cfg;
98
99 struct DebugBufferData
100 {
101 StringFloatDictionary latestTargetVelocities;
102 StringFloatDictionary latestTargets;
103
104 double currentCanVal;
105 double mpcFactor;
106 };
107
108 TripleBuffer<DebugBufferData> debugOutputData;
109
110 struct NJointJSDMPControllerSensorData
111 {
112 double currentTime;
113 double deltaT;
114 DMP::Vec<DMP::DMPState> currentState;
115 };
116
118
119 struct RTToUserData
120 {
121 Eigen::VectorXf qpos;
122 Eigen::VectorXf qvel;
123 };
124
125 TripleBuffer<RTToUserData> rt2UserData;
126
127
128 std::map<std::string, const SensorValue1DoFActuatorPosition*> positionSensors;
129 std::map<std::string, const SensorValue1DoFActuatorVelocity*> velocitySensors;
130 std::map<std::string, ControlTarget1DoFActuatorVelocity*> targets;
131
132 IceUtil::Time last;
133
134 DMP::UMIDMPPtr dmpPtr;
135 double timeDuration;
136 DMP::Vec<DMP::DMPState> currentState;
137 DMP::Vec<DMP::DMPState> currentDMPState;
138
139 double canVal;
140 double deltaT;
141 double tau;
142
143 double finished;
144
145 // phaseStop parameters
146 double phaseL;
147 double phaseK;
148 double phaseDist0;
149 double phaseDist1;
150 double phaseKp;
151
152 bool isDisturbance;
153 bool started;
154 std::vector<std::string> dimNames;
155 DMP::DVec targetState;
156 Eigen::VectorXf targetVels;
157
158 mutable MutexType controllerMutex;
159
160 Eigen::VectorXf qpos;
161 Eigen::VectorXf qvel;
162 // ManagedIceObject interface
163 protected:
164 void controllerRun();
165 void onInitNJointController() override;
166 void onDisconnectNJointController() override;
167 };
168
169} // namespace armarx::control::deprecated_njoint_mp_controller::joint_space
#define TYPEDEF_PTRS_HANDLE(T)
NJointControllerWithTripleBuffer(const NJointJSDMPControllerControlData &initialCommands=NJointJSDMPControllerControlData())
A simple triple buffer for lockfree comunication between a single writer and a single reader.
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
void runDMP(const Ice::DoubleSeq &goals, double times, const Ice::Current &) override
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
NJointJSDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
std::vector< double > createDMPFromString(const std::string &dmpString, const Ice::Current &) override
void setViaPoints(Ice::Double u, double viapoint, const Ice::Current &) override
void rtPreActivateController() override
This function is called before the controller is activated.
Brief description of class targets.
Definition targets.h:39
boost::shared_ptr< class UMIDMP > UMIDMPPtr
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl