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 if (distance > 1e-6_m) {
90 heading = translation.Angle();
95 linearGoal = wpi::math::TrapezoidProfile<wpi::units::meters>::State{distance, 0_mps};
100 auto const vel = CalculateVelocityAtHeading(current.velocity, heading);
101 linearStart = wpi::math::TrapezoidProfile<wpi::units::meters>::State{0_m, vel};
104 angularStart = wpi::math::TrapezoidProfile<wpi::units::radians>::State{
105 current.pose.Rotation().Radians(),
106 current.velocity.omega
109 angularGoal = wpi::math::TrapezoidProfile<wpi::units::radians>::State{
110 current.pose.Rotation().Radians() +
111 (goal.Rotation() - current.pose.Rotation()).Radians(),
123 constexpr State Calculate(wpi::units::second_t t)
126 auto const linearState = linearProfile.Calculate(t, linearStart, linearGoal);
128 auto const angularState = angularProfile.Calculate(t, angularStart, angularGoal);
132 initialPose.X() + linearState.position * heading.Cos(),
133 initialPose.Y() + linearState.position * heading.Sin(),
134 {angularState.position}
136 ChassisVelocities velocity{
137 linearState.velocity * heading.Cos(),
138 linearState.velocity * heading.Sin(),
139 angularState.velocity
141 return {std::move(pose), std::move(velocity)};
152 wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints linear,
153 wpi::math::TrapezoidProfile<wpi::units::radians>::Constraints angular
155 linearProfile{std::move(linear)},
156 angularProfile{std::move(angular)}
170 SetState(current, goal);
181 return wpi::units::math::max(
182 linearProfile.TotalTime(),
183 angularProfile.TotalTime()
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:151
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:168