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