64 pidPos(params.pidPos.Kp,
67 std::numeric_limits<double>::
max(),
68 std::numeric_limits<double>::
max(),
70 std::vector<bool>{
false,
false,
false}),
71 pidPosTarget(params.pidPos.Kp,
74 std::numeric_limits<double>::max(),
75 std::numeric_limits<double>::max(),
77 std::vector<bool>{false, false, false}),
78 pidOri(params.pidOri.Kp,
81 std::numeric_limits<double>::max(),
82 std::numeric_limits<double>::max(),
84 std::vector<bool>{true, true, true}),
85 pidOriTarget(params.pidOri.Kp,
88 std::numeric_limits<double>::max(),
89 std::numeric_limits<double>::max(),
91 std::vector<bool>{true, true, true})
94 <<
VAROUT(params.limits.linear) <<
", " <<
VAROUT(params.limits.angular);
100 if (params.limits.linear == 0 or params.limits.angular == 0)
102 return core::Twist{.linear = Eigen::Vector3f::Zero(),
103 .angular = Eigen::Vector3f::Zero()};
116 const float scalePos = twist.
linear.norm() / params.limits.linear;
117 const auto scaleOri = twist.
angular.cwiseAbs().cwiseQuotient(angularLimit.cwiseAbs());
122 const float scaleMax = std::max(scalePos, scaleOri.maxCoeff());
174 using simox::math::mat4f_to_pos;
175 using simox::math::mat4f_to_rpy;
178 const float currentOrientation = mat4f_to_rpy(currentPose.matrix()).z();
185 .dropPoint = {.waypoint = {.pose = core::Pose::Identity()}, .velocity = 0},
186 .isFinalSegment =
true,
187 .currentOrientation = currentOrientation,
188 .desiredOrientation = currentOrientation,
189 .orientationError = 0,
194 const auto projectedPose =
trajectory.getProjection(
198 pidPos.update(mat4f_to_pos(currentPose.matrix()),
199 mat4f_to_pos(projectedPose.projection.waypoint.pose.matrix()));
200 pidOri.update(mat4f_to_rpy(currentPose.matrix()),
201 mat4f_to_rpy(projectedPose.projection.waypoint.pose.matrix()));
203 const float desiredOrientation =
204 mat4f_to_rpy(projectedPose.projection.waypoint.pose.matrix()).z();
217 pidPosTarget.update(currentPose.translation(),
218 trajectory.points().back().waypoint.pose.translation());
221 mat4f_to_rpy(currentPose.matrix()),
222 mat4f_to_rpy(
trajectory.points().back().waypoint.pose.matrix()));
224 return core::Twist{.linear = pidPosTarget.getControlValue(),
225 .angular = pidOriTarget.getControlValue()};
230 pidPosTarget.reset();
233 const Eigen::Vector3f desiredMovementDirection =
234 (projectedPose.wayPointAfter.waypoint.pose.translation() -
235 projectedPose.wayPointBefore.waypoint.pose.translation())
238 const float ffVel = projectedPose.projection.velocity;
242 const auto feedforwardVelocity = desiredMovementDirection * ffVel;
245 << feedforwardVelocity.normalized();
249 return core::Twist{.linear = pidPos.getControlValue() + feedforwardVelocity,
250 .angular = pidOri.getControlValue()};
255 << twistLimited.linear.transpose();
257 << twistLimited.angular.transpose();
261 << twistScaled.linear.transpose();
263 << twistScaled.angular.transpose();
266 const auto& twistGlobal = twistScaled;
269 twistLocal.
linear = global_T_robot.linear().inverse() * twistGlobal.linear;
271 twistLocal.
angular = twistGlobal.angular;
278 .dropPoint = projectedPose.projection,
279 .isFinalSegment = isFinalSegment,
280 .currentOrientation = currentOrientation,
281 .desiredOrientation = desiredOrientation,
282 .orientationError = std::abs(currentOrientation - desiredOrientation),
283 .positionError = (global_T_robot.translation() -
284 trajectory.points().back().waypoint.pose.translation())