48 wpi::math::TrapezoidProfile<wpi::units::meters> linearProfile;
49 wpi::math::TrapezoidProfile<wpi::units::radians> angularProfile;
54 wpi::math::TrapezoidProfile<wpi::units::meters>::State linearGoal{};
55 wpi::math::TrapezoidProfile<wpi::units::meters>::State linearStart{};
57 wpi::math::TrapezoidProfile<wpi::units::radians>::State angularGoal{};
58 wpi::math::TrapezoidProfile<wpi::units::radians>::State angularStart{};
67 static constexpr wpi::units::meters_per_second_t CalculateVelocityAtHeading(ChassisVelocities
const &velocity, Rotation2d
const &heading)
71 return velocity.vx * heading.Cos() + velocity.vy * heading.Sin();
80 constexpr void SetState(
State const ¤t, Pose2d
const &goal)
82 initialPose = current.pose;
86 auto const translation = goal.Translation() - initialPose.Translation();
88 auto const distance = translation.Norm();
89 heading = translation.Angle().value_or(Rotation2d{});
91 linearGoal = wpi::math::TrapezoidProfile<wpi::units::meters>::State{distance, 0_mps};
96 auto const vel = CalculateVelocityAtHeading(current.velocity, heading);
97 linearStart = wpi::math::TrapezoidProfile<wpi::units::meters>::State{0_m, vel};
100 angularStart = wpi::math::TrapezoidProfile<wpi::units::radians>::State{
101 current.pose.Rotation().Radians(),
102 current.velocity.omega
105 angularGoal = wpi::math::TrapezoidProfile<wpi::units::radians>::State{
106 current.pose.Rotation().Radians() +
107 (goal.Rotation() - current.pose.Rotation()).Radians(),
119 constexpr State Calculate(wpi::units::second_t t)
122 auto const linearState = linearProfile.Calculate(t, linearStart, linearGoal);
124 auto const angularState = angularProfile.Calculate(t, angularStart, angularGoal);
128 initialPose.X() + linearState.position * heading.Cos(),
129 initialPose.Y() + linearState.position * heading.Sin(),
130 {angularState.position}
132 ChassisVelocities velocity{
133 linearState.velocity * heading.Cos(),
134 linearState.velocity * heading.Sin(),
135 angularState.velocity
137 return {std::move(pose), std::move(velocity)};
148 wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints linear,
149 wpi::math::TrapezoidProfile<wpi::units::radians>::Constraints angular
151 linearProfile{std::move(linear)},
152 angularProfile{std::move(angular)}
166 SetState(current, goal);
177 return wpi::units::math::max(
178 linearProfile.Duration(),
179 angularProfile.Duration()
constexpr LinearPath(wpi::math::TrapezoidProfile< wpi::units::meters >::Constraints linear, wpi::math::TrapezoidProfile< wpi::units::radians >::Constraints angular)
Constructs a linear path.
Definition LinearPath.hpp:147
constexpr State Calculate(wpi::units::second_t t, State const ¤t, Pose2d const &goal)
Calculates the pose and velocity of the path at a time t where the current state is at t = 0.
Definition LinearPath.hpp:164