48 frc::TrapezoidProfile<units::meters> linearProfile;
49 frc::TrapezoidProfile<units::radians> angularProfile;
54 frc::TrapezoidProfile<units::meters>::State linearGoal{};
55 frc::TrapezoidProfile<units::meters>::State linearStart{};
57 frc::TrapezoidProfile<units::radians>::State angularGoal{};
58 frc::TrapezoidProfile<units::radians>::State angularStart{};
67 static constexpr units::meters_per_second_t CalculateVelocityAtHeading(ChassisSpeeds
const &speeds, Rotation2d
const &heading)
71 return speeds.vx * heading.Cos() + speeds.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 = frc::TrapezoidProfile<units::meters>::State{distance, 0_mps};
100 auto const vel = CalculateVelocityAtHeading(current.speeds, heading);
101 linearStart = frc::TrapezoidProfile<units::meters>::State{0_m, vel};
104 angularStart = frc::TrapezoidProfile<units::radians>::State{
105 current.pose.Rotation().Radians(),
109 angularGoal = frc::TrapezoidProfile<units::radians>::State{
110 current.pose.Rotation().Radians() +
111 (goal.Rotation() - current.pose.Rotation()).Radians(),
123 constexpr State Calculate(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 ChassisSpeeds speeds{
137 linearState.velocity * heading.Cos(),
138 linearState.velocity * heading.Sin(),
139 angularState.velocity
141 return {std::move(pose), std::move(speeds)};
152 frc::TrapezoidProfile<units::meters>::Constraints linear,
153 frc::TrapezoidProfile<units::radians>::Constraints angular
155 linearProfile{std::move(linear)},
156 angularProfile{std::move(angular)}
170 SetState(current, goal);
181 return units::math::max(
182 linearProfile.TotalTime(),
183 angularProfile.TotalTime()
constexpr LinearPath(frc::TrapezoidProfile< units::meters >::Constraints linear, frc::TrapezoidProfile< units::radians >::Constraints angular)
Constructs a linear path.
Definition LinearPath.hpp:151
constexpr State Calculate(units::second_t t, State const ¤t, Pose2d const &goal)
Calculates the pose and speeds of the path at a time t where the current state is at t = 0.
Definition LinearPath.hpp:168