NJointAdaptiveWipingController.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <VirtualRobot/VirtualRobot.h>
5
8
11
13#include <armarx/control/deprecated_njoint_mp_controller/adaptive/ControllerInterface.h>
14
15namespace armarx
16{
17 class SensorValue1DoFActuatorTorque;
18 class SensorValue1DoFActuatorVelocity;
19 class SensorValue1DoFActuatorPosition;
20 class ControlTarget1DoFActuatorTorque;
22} // namespace armarx
23
25{
26 namespace tsvmp = armarx::control::deprecated_njoint_mp_controller::tsvmp;
27
30
32 {
33 public:
34 Eigen::VectorXf targetTSVel;
35 };
36
37 /**
38 * @brief The NJointAdaptiveWipingController class
39 * @ingroup Library-RobotUnit-NJointControllers
40 */
42 public NJointControllerWithTripleBuffer<NJointAdaptiveWipingControllerControlData>,
44 {
45 public:
46 using ConfigPtrT = NJointAdaptiveWipingControllerConfigPtr;
48 const NJointControllerConfigPtr& config,
50
51 // NJointControllerInterface interface
52 std::string getClassName(const Ice::Current&) const;
53
54 // NJointController interface
55
56 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
57 const IceUtil::Time& timeSinceLastIteration);
58
59 // NJointAdaptiveWipingControllerInterface interface
60 void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
61 void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory, const Ice::Current&);
62
63 bool
64 isFinished(const Ice::Current&)
65 {
66 return false;
67 }
68
69 void setSpeed(Ice::Double times, const Ice::Current&);
70 void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
71 void setAmplitude(Ice::Double amp, const Ice::Current&);
72 void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
73 void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&);
74
75 double
76 getCanVal(const Ice::Current&)
77 {
78 return dmpCtrl->canVal;
79 }
80
81 protected:
82 virtual void onPublish(const SensorAndControl&,
85
88 void controllerRun();
89
90 private:
91 struct DebugBufferData
92 {
93 StringFloatDictionary latestTargetVelocities;
94 StringFloatDictionary currentPose;
95 double currentCanVal;
96 double mpcFactor;
97 double error;
98 double phaseStop;
99 double posError;
100 double oriError;
101 double deltaT;
102 };
103
104 TripleBuffer<DebugBufferData> debugOutputData;
105
106 struct DebugRTData
107 {
108 Eigen::Matrix4f targetPose;
109 Eigen::Vector3f filteredForce;
110 Eigen::Vector3f filteredForceInRoot;
111 Eigen::Vector3f filteredTorque;
112
113 Eigen::Vector3f rotationAxis;
114
115 Eigen::Vector3f reactForce;
116 Eigen::Vector3f adaptK;
117 Eigen::VectorXf targetVel;
118 Eigen::Matrix4f currentPose;
119 bool isPhaseStop;
120
121 Eigen::Matrix4f globalPose;
122 Eigen::Vector3f globalFilteredForce;
123 Eigen::Vector3f currentToolDir;
124 Eigen::VectorXf currentTwist;
125
126 float rotAngle;
127 };
128
130
131 struct RTToControllerData
132 {
133 double currentTime;
134 double deltaT;
135 Eigen::Matrix4f currentPose;
136 Eigen::VectorXf currentTwist;
137 bool isPhaseStop;
138 };
139
141
142 struct RTToUserData
143 {
144 Eigen::Matrix4f currentTcpPose;
145 float waitTimeForCalibration;
146 };
147
148 TripleBuffer<RTToUserData> rt2UserData;
149
150 struct UserToRTData
151 {
152 float targetForce;
153 };
154
155 TripleBuffer<UserToRTData> user2rtData;
156
157
159
160 std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
161 std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
162 std::vector<ControlTarget1DoFActuatorTorque*> targets;
163
164 // velocity ik controller parameters
165 std::string nodeSetName;
166
167 bool started;
168 bool firstRun;
169 bool dmpRunning;
170
171 VirtualRobot::DifferentialIKPtr ik;
172 VirtualRobot::RobotNodePtr tcp;
173
174 NJointAdaptiveWipingControllerConfigPtr cfg;
175 mutable MutexType controllerMutex;
177 Eigen::Matrix4f targetPose;
178
179 Eigen::Vector3f kpos;
180 Eigen::Vector3f dpos;
181 Eigen::Vector3f kori;
182 Eigen::Vector3f dori;
183 Eigen::VectorXf knull;
184 Eigen::VectorXf dnull;
185 float kpf;
186
187 Eigen::VectorXf nullSpaceJointsVec;
188 const SensorValueForceTorque* forceSensor;
189
190 PIDControllerPtr forcePID;
191
192 Eigen::Vector3f filteredForce;
193 Eigen::Vector3f filteredTorque;
194 Eigen::Vector3f forceOffset;
195 Eigen::Vector3f currentForceOffset;
196
197 Eigen::Vector3f torqueOffset;
198 Eigen::Vector3f currentTorqueOffset;
199 float handMass;
200 Eigen::Vector3f handCOM;
201 Eigen::Vector3f gravityInRoot;
202
203 Eigen::Vector3f filteredForceInRoot;
204 Eigen::Vector3f filteredTorqueInRoot;
205
206 Eigen::Matrix3f toolTransform;
207 Eigen::Vector3f oriToolDir;
208 Eigen::Matrix3f origHandOri;
209 Eigen::VectorXf qvel_filtered;
210
211 Eigen::Vector3f adaptK;
212 float lastDiff;
213 Eigen::Vector2f lastPosition;
214 double changeTimer;
215 };
216
217} // namespace armarx::control::deprecated_njoint_mp_controller::adaptive
#define TYPEDEF_PTRS_HANDLE(T)
NJointControllerWithTripleBuffer(const NJointAdaptiveWipingControllerControlData &initialCommands=NJointAdaptiveWipingControllerControlData())
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
A simple triple buffer for lockfree comunication between a single writer and a single reader.
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
NJointAdaptiveWipingController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
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
std::shared_ptr< PIDController > PIDControllerPtr
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl