NJointBimanualForceMPController.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
15namespace armarx
16{
17 class SensorValue1DoFActuatorTorque;
18 class SensorValue1DoFActuatorVelocity;
19 class SensorValue1DoFActuatorPosition;
20 class SensorValue1DoFActuatorAcceleration;
21 class ControlTarget1DoFActuatorVelocity;
23} // namespace armarx
24
26{
27 namespace tsvmp = armarx::control::deprecated_njoint_mp_controller::tsvmp;
28
31
32 using ViaPoint = std::pair<double, DMP::DVec>;
33 using ViaPointsSet = std::vector<ViaPoint>;
34
36 {
37 public:
38 Eigen::Matrix4f leftTargetPose = Eigen::Matrix4f::Identity();
39 Eigen::Matrix4f rightTargetPose = Eigen::Matrix4f::Identity();
40 };
41
42 /**
43 * @brief The NJointBimanualForceMPController class
44 * @ingroup Library-RobotUnit-NJointControllers
45 */
47 public NJointControllerWithTripleBuffer<NJointBimanualForceMPControllerControlData>,
49 {
50 public:
51 using ConfigPtrT = NJointBimanualForceMPControllerConfigPtr;
53 const NJointControllerConfigPtr& config,
55
56 // NJointControllerInterface interface
57 std::string getClassName(const Ice::Current&) const override;
58
59 // NJointController interface
60
61 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
62 const IceUtil::Time& timeSinceLastIteration) override;
63
64 // NJointBimanualForceMPControllerInterface interface
65 void learnDMPFromFiles(const std::string& whichMP,
66 const Ice::StringSeq& fileNames,
67 const Ice::Current&) override;
68
69 bool
70 isFinished(const Ice::Current&) override
71 {
72 return finished;
73 }
74
75 void runDMP(const Ice::DoubleSeq& leftGoals,
76 const Ice::DoubleSeq& rightGoals,
77 const Ice::Current&) override;
78
79 double
80 getCanVal(const Ice::Current&) override
81 {
82 return canVal;
83 }
84
85 void setViaPoints(const std::string& whichDMP,
86 double canVal,
87 const Ice::DoubleSeq& viaPoint,
88 const Ice::Current&) override;
89
90 protected:
91 virtual void onPublish(const SensorAndControl&,
93 const DebugObserverInterfacePrx&) override;
94
95 void onInitNJointController() override;
96 void onDisconnectNJointController() override;
97
98 void controllerRun();
99
100 private:
101 struct DebugBufferData
102 {
103 StringFloatDictionary dmpTargets;
104 StringFloatDictionary currentPose;
105 double canVal;
106 float forceOnHands;
107 };
108
109 TripleBuffer<DebugBufferData> debugOutputData;
110
111 struct NJointBimanualForceMPControllerSensorData
112 {
113 Eigen::Matrix4f leftPoseInRootFrame;
114 Eigen::Vector6f leftTwistInRootFrame;
115
116 Eigen::Matrix4f rightPoseInRootFrame;
117 Eigen::Vector6f rightTwistInRootFrame;
118
119 Eigen::Vector3f leftForceInRootFrame;
120 Eigen::Vector3f rightForceInRootFrame;
121 double deltaT;
122 };
123
125
126 struct NJointBimanualForceMPControllerInterfaceData
127 {
128 Eigen::Matrix4f leftTcpPoseInRootFrame;
129 Eigen::Matrix4f rightTcpPoseInRootFrame;
130 };
131
133
134 std::vector<ControlTarget1DoFActuatorVelocity*> leftTargets;
135 std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
136 std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
137
138 std::vector<ControlTarget1DoFActuatorVelocity*> rightTargets;
139 std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
140 std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
141
142 const SensorValueForceTorque* rightForceTorque;
143 const SensorValueForceTorque* leftForceTorque;
144
145 VirtualRobot::DifferentialIKPtr leftIK;
146 VirtualRobot::DifferentialIKPtr rightIK;
147
148
149 tsvmp::TaskSpaceDMPControllerPtr leftDMPController;
150 tsvmp::TaskSpaceDMPControllerPtr rightDMPController;
151
152 // velocity ik controller parameters
153 CartesianVelocityControllerPtr leftTCPController;
154 CartesianVelocityControllerPtr rightTCPController;
155
156 // dmp parameters
157 bool finished;
158 VirtualRobot::RobotNodePtr leftTCP;
159 VirtualRobot::RobotNodePtr rightTCP;
160
161
162 Eigen::VectorXf targetVels;
163 Eigen::Matrix4f targetPose;
164
165 NJointBimanualForceMPControllerConfigPtr cfg;
166 mutable MutexType controllerMutex;
168
169 // velocity control
170 float Kp_LinearVel;
171 float Kd_LinearVel;
172 float Kp_AngularVel;
173 float Kd_AngularVel;
174
175 // force control
176 float Kp_f;
177 float Kd_f;
178 float Ki_f;
179
180 double canVal;
181 double xvel;
182
183 float forceIterm;
184 bool leftLearned;
185 bool rightLearned;
186
187 Eigen::Vector3f leftFilteredValue;
188 Eigen::Vector3f rightFilteredValue;
189
190 Eigen::Vector3f leftForceOffset;
191 Eigen::Vector3f rightForceOffset;
192 float targetSupportForce;
193
194 double I_decay;
195
196 float forceSign;
197 };
198
199} // namespace armarx::control::deprecated_njoint_mp_controller::bimanual
#define TYPEDEF_PTRS_HANDLE(T)
NJointControllerWithTripleBuffer(const NJointBimanualForceMPControllerControlData &initialCommands=NJointBimanualForceMPControllerControlData())
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
A simple triple buffer for lockfree comunication between a single writer and a single reader.
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
void setViaPoints(const std::string &whichDMP, double canVal, const Ice::DoubleSeq &viaPoint, const Ice::Current &) override
void learnDMPFromFiles(const std::string &whichMP, const Ice::StringSeq &fileNames, const Ice::Current &) override
void runDMP(const Ice::DoubleSeq &leftGoals, const Ice::DoubleSeq &rightGoals, const Ice::Current &) override
NJointBimanualForceMPController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Matrix< float, 6, 1 > Vector6f
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::shared_ptr< CartesianVelocityController > CartesianVelocityControllerPtr
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl