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 
15 namespace armarx
16 {
17  class SensorValue1DoFActuatorTorque;
18  class SensorValue1DoFActuatorVelocity;
19  class SensorValue1DoFActuatorPosition;
20  class ControlTarget1DoFActuatorTorque;
21  class SensorValueForceTorque;
22 } // namespace armarx
23 
25 {
27 
28  TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingController);
29  TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingControllerControlData);
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,
49  const VirtualRobot::RobotPtr&);
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
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController
The NJointAdaptiveWipingController class.
Definition: NJointAdaptiveWipingController.h:41
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingControllerControlData
Definition: NJointAdaptiveWipingController.h:31
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::adaptive::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingController)
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointAdaptiveWipingController.cpp:832
NJointControllerWithTripleBuffer.h
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::PIDControllerPtr
std::shared_ptr< PIDController > PIDControllerPtr
Definition: PIDController.h:94
PeriodicTask.h
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::getCanVal
double getCanVal(const Ice::Current &)
Definition: NJointAdaptiveWipingController.h:76
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:666
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:68
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingControllerControlData::targetTSVel
Eigen::VectorXf targetTSVel
Definition: NJointAdaptiveWipingController.h:34
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::adaptive
Definition: NJointAdaptiveWipingController.cpp:21
armarx::NJointAdaptiveWipingControllerInterface
Definition: ControllerInterface.ice:150
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setAmplitude
void setAmplitude(Ice::Double amp, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:659
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointAdaptiveWipingController.cpp:274
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryBasePtr &trajectory, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:632
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointAdaptiveWipingController.cpp:699
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:645
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointAdaptiveWipingController.h:64
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::onInitNJointController
void onInitNJointController()
Definition: NJointAdaptiveWipingController.cpp:170
CycleUtil.h
PIDController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:31
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::NJointAdaptiveWipingController
NJointAdaptiveWipingController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointAdaptiveWipingController.cpp:26
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:652
armarx::NJointControllerWithTripleBuffer< NJointAdaptiveWipingControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceUtil::Handle< class RobotUnit >
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:622
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double tau, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:675
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointAdaptiveWipingController.cpp:207
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::controllerRun
void controllerRun()
Definition: NJointAdaptiveWipingController.cpp:213
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::TripleBuffer< DebugBufferData >