Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Franco Cipollone <[email protected]>
  • Loading branch information
francocipollone committed Sep 28, 2023
1 parent 3697f8c commit b180cac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
31 changes: 15 additions & 16 deletions src/systems/trajectory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,20 @@ std::vector<Eigen::MatrixXd> ToVectorOfMatrixXd(const std::vector<Eigen::Vector3

} // namespace

using drake::multibody::SpatialVelocity;
using drake::trajectories::PiecewisePolynomial;
using drake::trajectories::PiecewiseQuaternionSlerp;

PoseVelocity::PoseVelocity()
: PoseVelocity::PoseVelocity(Eigen::Quaternion<double>::Identity(), Eigen::Vector3d::Zero(),
SpatialVelocity<double>(drake::Vector6<double>::Zero())) {}
::drake::multibody::SpatialVelocity<double>(drake::Vector6<double>::Zero())) {}

PoseVelocity::PoseVelocity(const Eigen::Quaternion<double>& rotation, const Eigen::Vector3d& translation,
const drake::multibody::SpatialVelocity<double>& velocity)
const ::drake::multibody::SpatialVelocity<double>& velocity)
: rotation_(rotation), translation_(translation), velocity_(velocity) {}

PoseVelocity Trajectory::value(double time) const {
const Eigen::Quaternion<double> rotation(rotation_.orientation(time));
const Eigen::Vector3d translation(translation_.value(time));
const Eigen::Vector3d translation_dot(translation_dot_.value(time));
const Eigen::Vector3d rpy_dot(rotation_.angular_velocity(time));
const SpatialVelocity<double> velocity(rpy_dot, translation_dot);
const ::drake::multibody::SpatialVelocity<double> velocity(rpy_dot, translation_dot);
return PoseVelocity{rotation, translation, velocity};
}

Expand All @@ -75,18 +71,20 @@ Trajectory Trajectory::Make(const std::vector<double>& times,
const InterpolationType& interp_type) {
DRAKE_THROW_UNLESS(times.size() == knots_rotation.size());
DRAKE_THROW_UNLESS(times.size() == knots_translation.size());
const PiecewiseQuaternionSlerp<double> rotation(times, knots_rotation);
PiecewisePolynomial<double> translation;
const ::drake::trajectories::PiecewiseQuaternionSlerp<double> rotation(times, knots_rotation);
::drake::trajectories::PiecewisePolynomial<double> translation;
switch (interp_type) {
case InterpolationType::kFirstOrderHold:
translation = PiecewisePolynomial<double>::FirstOrderHold(times, ToVectorOfMatrixXd(knots_translation));
translation = ::drake::trajectories::PiecewisePolynomial<double>::FirstOrderHold(
times, ToVectorOfMatrixXd(knots_translation));
break;
case InterpolationType::kCubic:
translation = PiecewisePolynomial<double>::CubicWithContinuousSecondDerivatives(
translation = ::drake::trajectories::PiecewisePolynomial<double>::CubicWithContinuousSecondDerivatives(
times, ToVectorOfMatrixXd(knots_translation));
break;
case InterpolationType::kPchip:
translation = PiecewisePolynomial<double>::CubicShapePreserving(times, ToVectorOfMatrixXd(knots_translation));
translation = ::drake::trajectories::PiecewisePolynomial<double>::CubicShapePreserving(
times, ToVectorOfMatrixXd(knots_translation));
break;
default:
throw std::logic_error("The provided interp_type is not supported.");
Expand Down Expand Up @@ -114,7 +112,7 @@ Trajectory Trajectory::MakeCubicFromWaypoints(const std::vector<Eigen::Quaternio
const double delta_t = distance / average_speed;
times[i + 1] = delta_t + times[i];
}
const PiecewiseQuaternionSlerp<double> rotation(times, waypoints_rotation);
const ::drake::trajectories::PiecewiseQuaternionSlerp<double> rotation(times, waypoints_rotation);

// Starting with a piecewise-linear estimate of spline segment lengths, make
// a loop that refines the segment lengths based on the constructed spline,
Expand All @@ -125,8 +123,8 @@ Trajectory Trajectory::MakeCubicFromWaypoints(const std::vector<Eigen::Quaternio
// Represent forward speed in frame A as velocity in frame W.
linear_velocities[i] = rotation_matrix * Eigen::Vector3d{speeds[i], 0., 0.};
}
const PiecewisePolynomial<double> translation =
PiecewisePolynomial<double>::CubicHermite(times, translations, linear_velocities);
const ::drake::trajectories::PiecewisePolynomial<double> translation =
::drake::trajectories::PiecewisePolynomial<double>::CubicHermite(times, translations, linear_velocities);

return Trajectory(translation, rotation);
}
Expand All @@ -140,7 +138,8 @@ Trajectory Trajectory::MakeCubicFromWaypoints(const std::vector<Eigen::Quaternio
return MakeCubicFromWaypoints(waypoints_rotation, waypoints_translation, speeds);
}

Trajectory::Trajectory(const PiecewisePolynomial<double>& translation, const PiecewiseQuaternionSlerp<double>& rotation)
Trajectory::Trajectory(const ::drake::trajectories::PiecewisePolynomial<double>& translation,
const ::drake::trajectories::PiecewiseQuaternionSlerp<double>& rotation)
: translation_(translation), rotation_(rotation), translation_dot_(translation.derivative()) {}

} // namespace delphyne
12 changes: 6 additions & 6 deletions src/systems/trajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PoseVelocity final {
/// @param velocity the (rotational/translational) spatial velocity Xdot_WA of
/// the frame A with respect to frame W.
PoseVelocity(const Eigen::Quaternion<double>& rotation, const Eigen::Vector3d& translation,
const drake::multibody::SpatialVelocity<double>& velocity);
const ::drake::multibody::SpatialVelocity<double>& velocity);

/// Accesses p_WA, the translation component of the pose of A, expressed in
/// world-frame coordinates W.
Expand Down Expand Up @@ -190,12 +190,12 @@ class Trajectory final {
private:
// Constructs a Trajectory from a translation PiecewisePolynomial, @p
// translation, and a rotation PiecewiseQuaternionSlerp, @p rotation.
explicit Trajectory(const drake::trajectories::PiecewisePolynomial<double>& translation,
const drake::trajectories::PiecewiseQuaternionSlerp<double>& rotation);
explicit Trajectory(const ::drake::trajectories::PiecewisePolynomial<double>& translation,
const ::drake::trajectories::PiecewiseQuaternionSlerp<double>& rotation);

drake::trajectories::PiecewisePolynomial<double> translation_;
drake::trajectories::PiecewiseQuaternionSlerp<double> rotation_;
drake::trajectories::PiecewisePolynomial<double> translation_dot_;
::drake::trajectories::PiecewisePolynomial<double> translation_;
::drake::trajectories::PiecewiseQuaternionSlerp<double> rotation_;
::drake::trajectories::PiecewisePolynomial<double> translation_dot_;
};

} // namespace delphyne

0 comments on commit b180cac

Please sign in to comment.