19 #ifndef GRAVITY_THREAD
20 #define GRAVITY_THREAD
22 #include <yarp/os/BufferedPort.h>
23 #include <yarp/os/RFModule.h>
24 #include <yarp/os/Time.h>
25 #include <yarp/os/Network.h>
26 #include <yarp/os/PeriodicThread.h>
27 #include <yarp/os/Stamp.h>
28 #include <yarp/sig/Vector.h>
29 #include <yarp/dev/PolyDriver.h>
30 #include <yarp/dev/ControlBoardInterfaces.h>
35 using namespace yarp::os;
36 using namespace yarp::sig;
49 std::string wholeBodyName;
50 BufferedPort<Vector> *port_inertial;
51 BufferedPort<Vector> *la_additional_offset;
52 BufferedPort<Vector> *ra_additional_offset;
53 BufferedPort<Vector> *ll_additional_offset;
54 BufferedPort<Vector> *rl_additional_offset;
55 BufferedPort<Vector> *to_additional_offset;
57 BufferedPort<Vector> *left_arm_exec_torques;
58 BufferedPort<Vector> *right_arm_exec_torques;
59 BufferedPort<Vector> *left_leg_exec_torques;
60 BufferedPort<Vector> *right_leg_exec_torques;
61 BufferedPort<Vector> *torso_exec_torques;
63 BufferedPort<Vector> *left_arm_gravity_torques;
64 BufferedPort<Vector> *right_arm_gravity_torques;
65 BufferedPort<Vector> *left_leg_gravity_torques;
66 BufferedPort<Vector> *right_leg_gravity_torques;
67 BufferedPort<Vector> *torso_gravity_torques;
72 IEncoders *iencs_arm_left;
73 IEncoders *iencs_arm_right;
74 IEncoders *iencs_head;
75 IControlMode *iCtrlMode_arm_left;
76 IControlMode *iCtrlMode_arm_right;
77 IControlMode *iCtrlMode_torso;
78 IInteractionMode *iIntMode_arm_left;
79 IInteractionMode *iIntMode_arm_right;
80 IInteractionMode *iIntMode_torso;
81 IImpedanceControl *iImp_arm_left;
82 ITorqueControl *iTqs_arm_left;
83 IImpedanceControl *iImp_arm_right;
84 ITorqueControl *iTqs_arm_right;
85 IImpedanceControl *iImp_torso;
86 ITorqueControl *iTqs_torso;
92 IEncoders *iencs_leg_left;
93 IEncoders *iencs_leg_right;
94 IEncoders *iencs_torso;
95 IControlMode *iCtrlMode_leg_left;
96 IControlMode *iCtrlMode_leg_right;
97 IInteractionMode *iIntMode_leg_left;
98 IInteractionMode *iIntMode_leg_right;
99 IImpedanceControl *iImp_leg_left;
100 ITorqueControl *iTqs_leg_left;
101 IImpedanceControl *iImp_leg_right;
102 ITorqueControl *iTqs_leg_right;
104 Vector encoders_arm_left;
105 Vector encoders_arm_right;
106 Vector encoders_head;
108 Vector encoders_leg_left;
109 Vector encoders_leg_right;
110 Vector encoders_torso;
119 int left_arm_ctrlJnt{};
120 int right_arm_ctrlJnt{};
121 int left_leg_ctrlJnt{};
122 int right_leg_ctrlJnt{};
128 Vector q_head, dq_head, d2q_head;
129 Vector q_larm, dq_larm, d2q_larm;
130 Vector q_rarm, dq_rarm, d2q_rarm;
131 Vector all_q_up, all_dq_up, all_d2q_up;
133 Vector q_torso, dq_torso, d2q_torso;
134 Vector q_lleg, dq_lleg, d2q_lleg;
135 Vector q_rleg, dq_rleg, d2q_rleg;
136 Vector all_q_low, all_dq_low, all_d2q_low;
138 Vector w0,dw0,d2p0,Fend,Muend;
139 Vector F_LArm, F_RArm, F_iDyn_LArm, F_iDyn_RArm, Offset_LArm, Offset_RArm;
140 Vector F_LLeg, F_RLeg, F_iDyn_LLeg, F_iDyn_RLeg, Offset_LLeg, Offset_RLeg;
141 Matrix F_ext_up, F_ext_low;
142 Vector inertial_measurements;
147 Vector exec_torques_LA,exec_torques_RA,exec_torques_LL,exec_torques_RL,exec_torques_TO;
148 Vector gravity_torques_LA,gravity_torques_RA,gravity_torques_LL,gravity_torques_RL,gravity_torques_TO;
149 Vector externalcmd_torques_LA,externalcmd_torques_RA,externalcmd_torques_LL,externalcmd_torques_RL, externalcmd_torques_TO;
150 Vector ampli_LA, ampli_RA, ampli_LL, ampli_RL, ampli_TO;
152 bool inertial_enabled;
154 Vector evalVelUp(
const Vector &
x);
155 Vector evalVelLow(
const Vector &
x);
156 Vector evalAccUp(
const Vector &
x);
157 Vector evalAccLow(
const Vector &
x);
161 void setLowerMeasure();
162 void setUpperMeasure();
169 gravityCompensatorThread(std::string _wholeBodyName,
int _rate, PolyDriver *_ddLA, PolyDriver *_ddRA, PolyDriver *_ddH, PolyDriver *_ddLL, PolyDriver *_ddRL, PolyDriver *_ddT,
version_tag icub_type,
bool _inertial_enabled);
171 void setZeroJntAngVelAcc();
172 bool readAndUpdate(
bool waitMeasure=
false);
173 bool getLowerEncodersSpeedAndAcceleration();
174 bool getUpperEncodersSpeedAndAcceleration();
175 bool threadInit()
override;
176 void feedFwdGravityControl(
int part_ctrlJnt,
const std::string& s_part, IControlMode *iCtrlMode, ITorqueControl *iTqs, IImpedanceControl *iImp, IInteractionMode *iIntMode,
const Vector &command,
bool releasing=
false);
178 void threadRelease()
override;
182 return thread_status;
thread_status_enum getThreadStatus()
Adaptive window linear fitting to estimate the first derivative.
Adaptive window quadratic fitting to estimate the second derivative.
A class for connecting UpperTorso and LowerTorso of the iCub, then getting the WholeBody in the dynam...
@ GRAVITY_COMPENSATION_ON
@ GRAVITY_COMPENSATION_OFF