37 pid(torqueConfigData->pid_proportional_gain,
38 torqueConfigData->pid_integral_gain,
39 torqueConfigData->pid_derivative_gain),
40 pidTargetTorque(0, 1, 0),
41 torqueGaussianFilter(30, 30),
42 torqueMedianFilter(5),
43 actualVelocityFilter(5),
83 return std::make_shared<VelocityManipulatingTorqueControllerConfiguration>(configData);
94 double jointLimitProtection = 0;
95 if (!torqueConfigData->limitless)
97 double borderHigh = torqueConfigData->jointLimitHigh - torqueConfigData->pushbackMargin;
98 double borderLow = torqueConfigData->jointLimitLow + torqueConfigData->pushbackMargin;
99 double penetration = 0;
100 if (actualPosition > borderHigh)
102 penetration = actualPosition - borderHigh;
104 else if (actualPosition < borderLow)
106 penetration = actualPosition - borderLow;
108 jointLimitProtection =
109 penetration / torqueConfigData->pushbackMargin * torqueConfigData->pushBackTorque;
111 jointLimitProtection =
113 return jointLimitProtection;
125 return lastAcceleration;
134 float actualVelocity,
135 float actualPosition)
139 pid.
Kp = torqueConfigData->pid_proportional_gain;
140 pid.
Ki = torqueConfigData->pid_integral_gain;
141 pid.
Kd = torqueConfigData->pid_derivative_gain;
148 double decay = torqueConfigData->decay;
149 double accelerationGain = torqueConfigData->accelerationGain;
150 double maxAcceleration = torqueConfigData->maxAcceleration;
151 double maxJerk = torqueConfigData->maxJerk;
152 double deadZone = torqueConfigData->deadZone;
153 double maxVelocity = torqueConfigData->maxVelocity;
154 double torqueToCurrentFactor = torqueConfigData->torqueToCurrent;
158 double dt = timeSinceLastIteration.toSecondsDouble();
161 actualVelocity = actualVelocityFilter.
update(actualVelocity);
162 double gravityCompensatedTorque = -gravity + actualTorque;
167 gravityCompensatedTorque =
169 std::max<float>(0.0f, (
std::abs(gravityCompensatedTorque) - deadZone));
174 if (
std::abs(jointLimitProtectionTorque) > 0.0)
179 jointLimitProtectionTorque,
std::abs(targetTorque + gravityCompensatedTorque) * 1.00);
181 double acceleration =
182 (targetTorque + gravityCompensatedTorque - jointLimitProtectionTorque) *
189 lastAcceleration - maxJerk *
dt, lastAcceleration + maxJerk *
dt, acceleration);
196 currentTargetVelocity += acceleration *
dt;
197 lastJerk = (acceleration - lastAcceleration) /
dt;
198 lastAcceleration = acceleration;
204 gravityCompensatedTorque *
205 gravityCompensatedTorque));
208 currentTargetVelocity *=
211 currentTargetVelocity,
213 pid.
update(
dt, actualVelocity, currentTargetVelocity);
217 double directControlCurrent = 0.;
229 auto jointLimitProtectionCurrent =
231 (torqueToCurrentFactor == 0.0 ? 0.05 : torqueToCurrentFactor) * 1000;
234 return resultingTargetCurrent + directControlCurrent + jointLimitProtectionCurrent;
241 currentTargetVelocity = 0.0;
242 lastAcceleration = 0.0;
249 return currentTargetVelocity;
255 return *torqueConfigData;
268 torqueConfigData->decay = configData.
decay;
269 torqueConfigData->deadZone = configData.
deadZone;