NJointBimanualForceController.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include <VirtualRobot/VirtualRobot.h>
5 
7 
11 
13 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ForceMPControllerInterface.h>
14 
15 namespace armarx
16 {
17  class SensorValue1DoFActuatorTorque;
18  class SensorValue1DoFActuatorVelocity;
19  class SensorValue1DoFActuatorPosition;
20  class SensorValue1DoFActuatorAcceleration;
21  class ControlTarget1DoFActuatorTorque;
22  class SensorValueForceTorque;
23 } // namespace armarx
24 
26 {
28 
29  TYPEDEF_PTRS_HANDLE(NJointBimanualForceController);
30  TYPEDEF_PTRS_HANDLE(NJointBimanualForceControlData);
31 
33  {
34  public:
35  // from dmp
37  Eigen::VectorXf boxTwist;
38  // Eigen::VectorXf leftTargetTwist;
39  // Eigen::VectorXf rightTargetTwist;
40 
41  // Eigen::Matrix4f leftTargetPose;
42  // Eigen::Matrix4f rightTargetPose;
43 
44  // std::vector<float> nullspaceJointVelocities;
45  // double virtualTime;
46  };
47 
49  public NJointControllerWithTripleBuffer<NJointBimanualForceControlData>,
51  {
52  public:
53  // using ConfigPtrT = BimanualForceControllerConfigPtr;
55  const NJointControllerConfigPtr& config,
56  const VirtualRobot::RobotPtr&);
57 
58  // NJointControllerInterface interface
59  std::string getClassName(const Ice::Current&) const;
60 
61  // NJointController interface
62 
63  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
64  const IceUtil::Time& timeSinceLastIteration);
65 
66  // NJointCCDMPControllerInterface interface
67  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
68 
69  bool
70  isFinished(const Ice::Current&)
71  {
72  return finished;
73  }
74 
75  // void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
76  void runDMP(const Ice::DoubleSeq& goals, const Ice::Current&);
77  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
78  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
79 
80  double
81  getVirtualTime(const Ice::Current&)
82  {
83  return virtualtimer;
84  }
85 
86  protected:
87  virtual void onPublish(const SensorAndControl&,
90 
93  void controllerRun();
94 
95  private:
96  Eigen::VectorXf targetWrench;
97 
98  struct DebugBufferData
99  {
100  StringFloatDictionary desired_torques;
101 
102  float modifiedPoseRight_x;
103  float modifiedPoseRight_y;
104  float modifiedPoseRight_z;
105  float currentPoseLeft_x;
106  float currentPoseLeft_y;
107  float currentPoseLeft_z;
108 
109  float modifiedPoseLeft_x;
110  float modifiedPoseLeft_y;
111  float modifiedPoseLeft_z;
112  float currentPoseRight_x;
113  float currentPoseRight_y;
114  float currentPoseRight_z;
115 
116  float dmpBoxPose_x;
117  float dmpBoxPose_y;
118  float dmpBoxPose_z;
119 
120  float dmpTwist_x;
121  float dmpTwist_y;
122  float dmpTwist_z;
123 
124  float modifiedTwist_lx;
125  float modifiedTwist_ly;
126  float modifiedTwist_lz;
127  float modifiedTwist_rx;
128  float modifiedTwist_ry;
129  float modifiedTwist_rz;
130 
131  float rx;
132  float ry;
133  float rz;
134 
135  Eigen::VectorXf wrenchDMP;
136  Eigen::VectorXf computedBoxWrench;
137 
138  Eigen::VectorXf forceImpedance;
139  Eigen::VectorXf forcePID;
140  Eigen::VectorXf forcePIDControlValue;
141  Eigen::VectorXf poseError;
142  Eigen::VectorXf wrenchesConstrained;
143  Eigen::VectorXf wrenchesMeasuredInRoot;
144  };
145 
146  TripleBuffer<DebugBufferData> debugOutputData;
147 
148  struct NJointBimanualForceControllerSensorData
149  {
150  double currentTime;
151  double deltaT;
152  Eigen::Matrix4f currentPose;
153  Eigen::VectorXf currentTwist;
154  };
155 
157 
158  struct NJointBimanualForceControllerInterfaceData
159  {
160  Eigen::Matrix4f currentLeftPose;
161  Eigen::Matrix4f currentRightPose;
162  };
163 
165 
166  std::vector<ControlTarget1DoFActuatorTorque*> leftTargets;
167  std::vector<const SensorValue1DoFActuatorAcceleration*> leftAccelerationSensors;
168  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
169  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
170 
171  std::vector<ControlTarget1DoFActuatorTorque*> rightTargets;
172  std::vector<const SensorValue1DoFActuatorAcceleration*> rightAccelerationSensors;
173  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
174  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
175 
176  const SensorValueForceTorque* rightForceTorque;
177  const SensorValueForceTorque* leftForceTorque;
178 
179  NJointBimanualForceControllerConfigPtr cfg;
180  VirtualRobot::DifferentialIKPtr leftIK;
181  VirtualRobot::DifferentialIKPtr rightIK;
182 
184 
185 
186  double virtualtimer;
187 
188  mutable MutexType controllerMutex;
189  Eigen::VectorXf leftDesiredJointValues;
190  Eigen::VectorXf rightDesiredJointValues;
191 
192  Eigen::Matrix4f leftInitialPose;
193  Eigen::Matrix4f rightInitialPose;
194  Eigen::Matrix4f boxInitialPose;
195 
196  Eigen::VectorXf KpImpedance;
197  Eigen::VectorXf KdImpedance;
198  Eigen::VectorXf KpAdmittance;
199  Eigen::VectorXf KdAdmittance;
200  Eigen::VectorXf KmAdmittance;
201  Eigen::VectorXf KmPID;
202 
203  Eigen::VectorXf modifiedAcc;
204  Eigen::VectorXf modifiedTwist;
205  Eigen::Matrix4f modifiedLeftPose;
206  Eigen::Matrix4f modifiedRightPose;
207 
208  Eigen::Matrix4f sensorFrame2TcpFrameLeft;
209  Eigen::Matrix4f sensorFrame2TcpFrameRight;
210 
211  //static compensation
212  float massLeft;
213  Eigen::Vector3f CoMVecLeft;
214  Eigen::Vector3f forceOffsetLeft;
215  Eigen::Vector3f torqueOffsetLeft;
216 
217  float massRight;
218  Eigen::Vector3f CoMVecRight;
219  Eigen::Vector3f forceOffsetRight;
220  Eigen::Vector3f torqueOffsetRight;
221 
222 
223  // float knull;
224  // float dnull;
225 
226  std::vector<std::string> leftJointNames;
227  std::vector<std::string> rightJointNames;
228 
229  // float torqueLimit;
230  VirtualRobot::RobotNodeSetPtr leftRNS;
231  VirtualRobot::RobotNodeSetPtr rightRNS;
232  VirtualRobot::RobotNodePtr tcpLeft;
233  VirtualRobot::RobotNodePtr tcpRight;
234 
235  std::vector<PIDControllerPtr> forcePIDControllers;
236 
237  // filter parameters
238  float filterCoeff;
239  Eigen::VectorXf filteredOldValue;
240  bool finished;
241  bool dmpStarted;
242 
243  protected:
244  // void rtPreActivateController();
245  bool firstLoop;
246  };
247 
248 } // namespace armarx::control::deprecated_njoint_mp_controller::bimanual
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::NJointBimanualForceController
NJointBimanualForceController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualForceController.cpp:28
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceControlData::boxTwist
Eigen::VectorXf boxTwist
Definition: NJointBimanualForceController.h:37
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceControlData::boxPose
Eigen::Matrix4f boxPose
Definition: NJointBimanualForceController.h:36
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::controllerRun
void controllerRun()
Definition: NJointBimanualForceController.cpp:306
NJointControllerWithTripleBuffer.h
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceControlData
Definition: NJointBimanualForceController.h:32
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointBimanualForceController.cpp:983
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointBimanualForceController.cpp:768
PeriodicTask.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::firstLoop
bool firstLoop
Definition: NJointBimanualForceController.h:245
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointBimanualForceController.cpp:824
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointBimanualForceController.cpp:287
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointBimanualForceController.cpp:814
armarx::NJointBimanualForceControllerInterface
Definition: ForceMPControllerInterface.ice:98
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
CartesianVelocityController.h
PIDController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:31
armarx::NJointControllerWithTripleBuffer< NJointBimanualForceControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceUtil::Handle< class RobotUnit >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointBimanualForceController.h:70
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointBimanualForceController.cpp:775
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::onInitNJointController
void onInitNJointController()
Definition: NJointBimanualForceController.cpp:963
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController
Definition: NJointBimanualForceController.h:48
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:32
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointBimanualForceController.cpp:331
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::getVirtualTime
double getVirtualTime(const Ice::Current &)
Definition: NJointBimanualForceController.h:81
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualForceController::runDMP
void runDMP(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointBimanualForceController.cpp:782
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::bimanual
Definition: NJointBimanualCartesianAdmittanceController.cpp:30
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::bimanual::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointBimanualCartesianAdmittanceController)