NJointBimanualObjLevelVelController.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 // armarx
17 
18 // control
19 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ObjLevelControllerInterface.h>
21 
22 
24 {
26 
27  TYPEDEF_PTRS_HANDLE(NJointBimanualObjLevelVelController);
28  TYPEDEF_PTRS_HANDLE(NJointBimanualObjLevelVelControlData);
29 
31  {
32  public:
33  // control target from Movement Primitives
35  };
36 
37 
39  public NJointControllerWithTripleBuffer<NJointBimanualObjLevelVelControlData>,
41  {
42  public:
43  // using ConfigPtrT = BimanualForceControllerConfigPtr;
44  NJointBimanualObjLevelVelController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
45 
46  // NJointControllerInterface interface
47  std::string getClassName(const Ice::Current&) const;
48 
49  // NJointController interface
50 
51  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration);
52 
53  // NJointCCDMPControllerInterface interface
54  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
55  bool isFinished(const Ice::Current&)
56  {
57  return finished;
58  }
59  Eigen::Matrix3f skew(Eigen::Vector3f vec)
60  {
61  Eigen::Matrix3f mat = Eigen::MatrixXf::Zero(3, 3);
62  mat(1, 2) = -vec(0);
63  mat(0, 2) = vec(1);
64  mat(0, 1) = -vec(2);
65  mat(2, 1) = vec(0);
66  mat(2, 0) = -vec(1);
67  mat(1, 0) = vec(2);
68  return mat;
69  }
70 
71  // void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
72  void runDMP(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
73  void runDMPWithVirtualStart(const Ice::DoubleSeq& starts, const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
74 
75  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
76  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
77  void removeAllViaPoints(const Ice::Current&);
78 
79  double getVirtualTime(const Ice::Current&)
80  {
81  return virtualtimer;
82  }
83 
84  void setKpImpedance(const Ice::FloatSeq& value, const Ice::Current&);
85  void setKdImpedance(const Ice::FloatSeq& value, const Ice::Current&);
86 
87  std::vector<float> getCurrentObjVel(const Ice::Current&);
88 
89  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&);
90  DoubleSeqSeq getMPWeights(const Ice::Current&);
91 
92  void setMPRotWeights(const DoubleSeqSeq& weights, const Ice::Current&);
93  DoubleSeqSeq getMPRotWeights(const Ice::Current&);
94  Eigen::VectorXf calcIK(VirtualRobot::DifferentialIKPtr ik, const Eigen::MatrixXf& jacobi, const Eigen::VectorXf& cartesianVel, const Eigen::VectorXf& nullspaceVel);
95  protected:
97 
100  void controllerRun();
101 
102  private:
103  Eigen::VectorXf targetWrench;
104  struct DebugBufferData
105  {
106  StringFloatDictionary desired_vels;
107 
108  float virtualPose_x;
109  float virtualPose_y;
110  float virtualPose_z;
111 
112  float currentPoseLeft_x;
113  float currentPoseLeft_y;
114  float currentPoseLeft_z;
115  float leftQuat_w;
116  float leftQuat_x;
117  float leftQuat_y;
118  float leftQuat_z;
119 
120  float currentPoseRight_x;
121  float currentPoseRight_y;
122  float currentPoseRight_z;
123  float rightQuat_w;
124  float rightQuat_x;
125  float rightQuat_y;
126  float rightQuat_z;
127 
128 
129  float dmpBoxPose_x;
130  float dmpBoxPose_y;
131  float dmpBoxPose_z;
132 
133  float dmpBoxPose_qx;
134  float dmpBoxPose_qy;
135  float dmpBoxPose_qz;
136  float dmpBoxPose_qw;
137 
138  };
139  TripleBuffer<DebugBufferData> debugOutputData;
140 
141  struct rt2ControlData
142  {
143  double currentTime;
144  double deltaT;
145  Eigen::Matrix4f currentPose;
146  Eigen::VectorXf currentTwist;
147  };
148  TripleBuffer<rt2ControlData> rt2ControlBuffer;
149 
150  struct ControlInterfaceData
151  {
152  Eigen::Matrix4f currentLeftPose;
153  Eigen::Matrix4f currentRightPose;
154  Eigen::Matrix4f currentObjPose;
155  Eigen::Vector3f currentObjVel;
156  };
157 
158  TripleBuffer<ControlInterfaceData> controlInterfaceBuffer;
159 
160  struct Inferface2rtData
161  {
162  Eigen::VectorXf KpImpedance;
163  Eigen::VectorXf KdImpedance;
164  };
165  TripleBuffer<Inferface2rtData> interface2rtBuffer;
166 
167  std::vector<ControlTarget1DoFActuatorVelocity*> leftTargets;
168  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
169  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
170 
171  std::vector<ControlTarget1DoFActuatorVelocity*> rightTargets;
172  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
173  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
174 
175  NJointBimanualObjLevelVelControllerConfigPtr cfg;
176  VirtualRobot::DifferentialIKPtr leftIK;
177  VirtualRobot::DifferentialIKPtr rightIK;
178 
180 
181  double virtualtimer;
182 
183  mutable MutexType controllerMutex;
184  mutable MutexType interfaceDataMutex;
185  Eigen::VectorXf leftDesiredJointValues;
186  Eigen::VectorXf rightDesiredJointValues;
187 
188  Eigen::Matrix4f leftInitialPose;
189  Eigen::Matrix4f rightInitialPose;
190  Eigen::Matrix4f boxInitialPose;
191 
192  Eigen::VectorXf KpImpedance;
193  Eigen::VectorXf KdImpedance;
194  Eigen::VectorXf KpAdmittance;
195  Eigen::VectorXf KdAdmittance;
196  Eigen::VectorXf KmAdmittance;
197  Eigen::VectorXf KmPID;
198 
199  Eigen::VectorXf virtualAcc;
200  Eigen::VectorXf virtualVel;
201  Eigen::Matrix4f virtualPose;
202 
203  Eigen::Matrix4f sensorFrame2TcpFrameLeft;
204  Eigen::Matrix4f sensorFrame2TcpFrameRight;
205 
206  //static compensation
207  float massLeft;
208  Eigen::Vector3f CoMVecLeft;
209  Eigen::Vector3f forceOffsetLeft;
210  Eigen::Vector3f torqueOffsetLeft;
211 
212  float massRight;
213  Eigen::Vector3f CoMVecRight;
214  Eigen::Vector3f forceOffsetRight;
215  Eigen::Vector3f torqueOffsetRight;
216 
217  // float knull;
218  // float dnull;
219 
220  std::vector<std::string> leftJointNames;
221  std::vector<std::string> rightJointNames;
222 
223  // float torqueLimit;
224  VirtualRobot::RobotNodeSetPtr leftRNS;
225  VirtualRobot::RobotNodeSetPtr rightRNS;
226  VirtualRobot::RobotNodePtr tcpLeft;
227  VirtualRobot::RobotNodePtr tcpRight;
228 
229  CartesianVelocityControllerPtr leftTCPController;
230  CartesianVelocityControllerPtr rightTCPController;
231 
232  std::vector<PIDControllerPtr> forcePIDControllers;
233 
234  // filter parameters
235  float filterCoeff;
236  Eigen::VectorXf filteredOldValue;
237  bool finished;
238  bool dmpStarted;
239  Eigen::VectorXf ftOffset;
240  Eigen::Matrix4f dmpGoal;
241 
242  Eigen::Matrix3f fixedLeftRightRotOffset;
243  Eigen::Vector3f objCom2TCPLeftInObjFrame, objCom2TCPRightInObjFrame;
244 
245  protected:
247  bool firstLoop;
248  };
249 
250 } // namespace armarx
251 
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setMPRotWeights
void setMPRotWeights(const DoubleSeqSeq &weights, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:244
MathUtils.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:584
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::skew
Eigen::Matrix3f skew(Eigen::Vector3f vec)
Definition: NJointBimanualObjLevelVelController.h:59
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:674
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::NJointBimanualObjLevelVelControllerInterface::getMPRotWeights
DoubleSeqSeq getMPRotWeights()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:592
SensorValueForceTorque.h
armarx::CartesianVelocityControllerPtr
std::shared_ptr< CartesianVelocityController > CartesianVelocityControllerPtr
Definition: CartesianVelocityController.h:34
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::getVirtualTime
double getVirtualTime(const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.h:79
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::runDMPWithVirtualStart
void runDMPWithVirtualStart(const Ice::DoubleSeq &starts, const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:647
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::controllerRun
void controllerRun()
Definition: NJointBimanualObjLevelVelController.cpp:292
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointBimanualObjLevelVelController.cpp:827
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:605
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::firstLoop
bool firstLoop
Definition: NJointBimanualObjLevelVelController.h:247
armarx::NJointBimanualObjLevelVelControllerInterface::removeAllViaPoints
void removeAllViaPoints()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointBimanualObjLevelVelController.cpp:350
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::calcIK
Eigen::VectorXf calcIK(VirtualRobot::DifferentialIKPtr ik, const Eigen::MatrixXf &jacobi, const Eigen::VectorXf &cartesianVel, const Eigen::VectorXf &nullspaceVel)
Definition: NJointBimanualObjLevelVelController.cpp:323
armarx::NJointBimanualObjLevelVelControllerInterface::getCurrentObjVel
Ice::FloatSeq getCurrentObjVel()
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setKpImpedance
void setKpImpedance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:690
armarx::NJointBimanualObjLevelVelControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
CartesianVelocityController.h
PIDController.h
NJointController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointBimanualObjLevelVelController.cpp:269
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setKdImpedance
void setKdImpedance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:709
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::bimanual::NJointBimanualObjLevelVelControlData
Definition: NJointBimanualObjLevelVelController.h:30
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointBimanualObjLevelVelController.cpp:737
armarx::NJointControllerWithTripleBuffer< NJointBimanualObjLevelVelControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.cpp:219
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController
Definition: NJointBimanualObjLevelVelController.h:38
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelControlData::boxPose
Eigen::Matrix4f boxPose
Definition: NJointBimanualObjLevelVelController.h:34
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::NJointBimanualObjLevelVelControllerInterface
Definition: ObjLevelControllerInterface.ice:153
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::NJointBimanualObjLevelVelController
NJointBimanualObjLevelVelController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualObjLevelVelController.cpp:16
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointBimanualObjLevelVelController.cpp:286
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::onInitNJointController
void onInitNJointController()
Definition: NJointBimanualObjLevelVelController.cpp:805
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelVelController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointBimanualObjLevelVelController.h:55
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)