NJointAdaptiveWipingController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 #include <VirtualRobot/Robot.h>
6 #include <VirtualRobot/IK/DifferentialIK.h>
7 
9 #include <VirtualRobot/Robot.h>
17 
18 // control
19 #include <armarx/control/deprecated_njoint_mp_controller/adaptive/ControllerInterface.h>
21 
22 
24 {
26 
27  TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingController);
28  TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingControllerControlData);
29 
31  {
32  public:
33  Eigen::VectorXf targetTSVel;
34  };
35 
36  /**
37  * @brief The NJointAdaptiveWipingController class
38  * @ingroup Library-RobotUnit-NJointControllers
39  */
41  public NJointControllerWithTripleBuffer<NJointAdaptiveWipingControllerControlData>,
43  {
44  public:
45  using ConfigPtrT = NJointAdaptiveWipingControllerConfigPtr;
46  NJointAdaptiveWipingController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
47 
48  // NJointControllerInterface interface
49  std::string getClassName(const Ice::Current&) const;
50 
51  // NJointController interface
52 
53  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration);
54 
55  // NJointAdaptiveWipingControllerInterface interface
56  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
57  void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory, const Ice::Current&);
58  bool isFinished(const Ice::Current&)
59  {
60  return false;
61  }
62 
63  void setSpeed(Ice::Double times, const Ice::Current&);
64  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
65  void setAmplitude(Ice::Double amp, const Ice::Current&);
66  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
67  void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&);
68  double getCanVal(const Ice::Current&)
69  {
70  return dmpCtrl->canVal;
71  }
72 
73  protected:
75 
78  void controllerRun();
79 
80  private:
81  struct DebugBufferData
82  {
83  StringFloatDictionary latestTargetVelocities;
84  StringFloatDictionary currentPose;
85  double currentCanVal;
86  double mpcFactor;
87  double error;
88  double phaseStop;
89  double posError;
90  double oriError;
91  double deltaT;
92  };
93 
94  TripleBuffer<DebugBufferData> debugOutputData;
95 
96 
97  struct DebugRTData
98  {
99  Eigen::Matrix4f targetPose;
100  Eigen::Vector3f filteredForce;
101  Eigen::Vector3f filteredForceInRoot;
102  Eigen::Vector3f filteredTorque;
103 
104  Eigen::Vector3f rotationAxis;
105 
106  Eigen::Vector3f reactForce;
107  Eigen::Vector3f adaptK;
108  Eigen::VectorXf targetVel;
109  Eigen::Matrix4f currentPose;
110  bool isPhaseStop;
111 
112  Eigen::Matrix4f globalPose;
113  Eigen::Vector3f globalFilteredForce;
114  Eigen::Vector3f currentToolDir;
115  Eigen::VectorXf currentTwist;
116 
117  float rotAngle;
118  };
120 
121 
122 
123 
124  struct RTToControllerData
125  {
126  double currentTime;
127  double deltaT;
128  Eigen::Matrix4f currentPose;
129  Eigen::VectorXf currentTwist;
130  bool isPhaseStop;
131  };
133 
134  struct RTToUserData
135  {
136  Eigen::Matrix4f currentTcpPose;
137  float waitTimeForCalibration;
138  };
139  TripleBuffer<RTToUserData> rt2UserData;
140 
141  struct UserToRTData
142  {
143  float targetForce;
144  };
145  TripleBuffer<UserToRTData> user2rtData;
146 
147 
149 
150  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
151  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
152  std::vector<ControlTarget1DoFActuatorTorque*> targets;
153 
154  // velocity ik controller parameters
155  std::string nodeSetName;
156 
157  bool started;
158  bool firstRun;
159  bool dmpRunning;
160 
161  VirtualRobot::DifferentialIKPtr ik;
162  VirtualRobot::RobotNodePtr tcp;
163 
164  NJointAdaptiveWipingControllerConfigPtr cfg;
165  mutable MutexType controllerMutex;
167  Eigen::Matrix4f targetPose;
168 
169  Eigen::Vector3f kpos;
170  Eigen::Vector3f dpos;
171  Eigen::Vector3f kori;
172  Eigen::Vector3f dori;
173  Eigen::VectorXf knull;
174  Eigen::VectorXf dnull;
175  float kpf;
176 
177  Eigen::VectorXf nullSpaceJointsVec;
178  const SensorValueForceTorque* forceSensor;
179 
180  PIDControllerPtr forcePID;
181 
182  Eigen::Vector3f filteredForce;
183  Eigen::Vector3f filteredTorque;
184  Eigen::Vector3f forceOffset;
185  Eigen::Vector3f currentForceOffset;
186 
187  Eigen::Vector3f torqueOffset;
188  Eigen::Vector3f currentTorqueOffset;
189  float handMass;
190  Eigen::Vector3f handCOM;
191  Eigen::Vector3f gravityInRoot;
192 
193  Eigen::Vector3f filteredForceInRoot;
194  Eigen::Vector3f filteredTorqueInRoot;
195 
196  Eigen::Matrix3f toolTransform;
197  Eigen::Vector3f oriToolDir;
198  Eigen::Matrix3f origHandOri;
199  Eigen::VectorXf qvel_filtered;
200 
201  Eigen::Vector3f adaptK;
202  float lastDiff;
203  Eigen::Vector2f lastPosition;
204  double changeTimer;
205 
206  };
207 
208 } // namespace armarx
209 
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController
The NJointAdaptiveWipingController class.
Definition: NJointAdaptiveWipingController.h:40
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingControllerControlData
Definition: NJointAdaptiveWipingController.h:30
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
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:761
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::PIDControllerPtr
std::shared_ptr< PIDController > PIDControllerPtr
Definition: PIDController.h:92
SensorValueForceTorque.h
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::getCanVal
double getCanVal(const Ice::Current &)
Definition: NJointAdaptiveWipingController.h:68
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:612
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingControllerControlData::targetTSVel
Eigen::VectorXf targetTSVel
Definition: NJointAdaptiveWipingController.h:33
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::adaptive
Definition: NJointAdaptiveWipingController.cpp:5
armarx::NJointAdaptiveWipingControllerInterface
Definition: ControllerInterface.ice:152
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setAmplitude
void setAmplitude(Ice::Double amp, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:606
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:248
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryBasePtr &trajectory, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:581
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointAdaptiveWipingController.cpp:640
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:593
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:58
CartesianVelocityController.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::onInitNJointController
void onInitNJointController()
Definition: NJointAdaptiveWipingController.cpp:147
CycleUtil.h
PIDController.h
NJointController.h
Trajectory.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::NJointAdaptiveWipingController
NJointAdaptiveWipingController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointAdaptiveWipingController.cpp:9
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:600
armarx::NJointControllerWithTripleBuffer< NJointAdaptiveWipingControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointAdaptiveWipingController.cpp:572
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:619
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointAdaptiveWipingController.cpp:183
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointAdaptiveWipingController::controllerRun
void controllerRun()
Definition: NJointAdaptiveWipingController.cpp:188
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< DebugBufferData >