7#include <frc/trajectory/TrapezoidProfile.h>
29 units::millisecond_t resolution = 20_ms);
32 const Polygon& avoidancePolygon,
33 units::millisecond_t resolution = 20_ms);
37 template <
typename SegmentIt,
typename PathIt>
39 SegmentIt segmentLengthsBegin,
40 SegmentIt segmentLengthsEnd,
44 auto totalPathLength = std::accumulate(
45 segmentLengthsBegin, segmentLengthsEnd, 0_in, [](units::inch_t sum,
const units::inch_t& segmentLength) {
46 return sum + segmentLength;
50 auto minPathTime = units::math::sqrt(2 * totalPathLength / constraints.
maxAcceleration);
53 std::vector<frc::TrapezoidProfile<units::inch>> segmentProfiles;
54 segmentProfiles.reserve(std::distance(segmentLengthsBegin, segmentLengthsEnd));
55 auto lastVelocity = 0_ips;
57 size_t segmentIndex = 0;
58 while (segmentLengthsBegin != segmentLengthsEnd) {
60 auto transitionSpeed = std::min(
61 maxVel, constraints.
maxVelocity * std::max(0.25, ((-units::math::cos(cuspAngle) + 1) / 2).to<
double>()));
62 segmentProfiles.emplace_back(
64 frc::TrapezoidProfile<units::inch>::State{*segmentLengthsBegin, transitionSpeed},
65 frc::TrapezoidProfile<units::inch>::State{0_in, lastVelocity});
66 lastVelocity = segmentProfiles.back().Calculate(segmentProfiles.back().TotalTime()).velocity;
67 ++segmentLengthsBegin;
71 return segmentProfiles;
75 const std::vector<units::inch_t>& segmentLengths,
77 const PathDynamicsConstraints& constraints);
79 template <
typename PositionType,
typename VelocityType>
80 [[nodiscard]] std::vector<GenericMPPathPoint<PositionType, VelocityType>>
PadProfile(
82 units::millisecond_t paddingTime,
84 std::vector<GenericMPPathPoint<PositionType, VelocityType>> paddedProfile;
85 unsigned paddingElements = std::ceil((paddingTime / profile.front().time).template to<double>());
86 paddedProfile.reserve(profile.size() + paddingElements);
88 paddedProfile.insert(paddedProfile.end(), paddingElements, profile.front());
89 paddedProfile.insert(paddedProfile.end(), profile.begin(), profile.end());
91 paddedProfile.insert(paddedProfile.end(), profile.begin(), profile.end());
92 paddedProfile.insert(paddedProfile.end(), paddingElements, profile.back());
Definition lifter_subsystem.h:26
Definition convert_path.h:16
std::vector< ArmPathPoint > Polygon
Definition types.h:64
std::vector< frc::TrapezoidProfile< units::inch > > GenerateContinuousSegmentProfiles(const std::vector< units::inch_t > &segmentLengths, const path_planning::ArmPath &path, const PathDynamicsConstraints &constraints)
Definition convert_path.cpp:255
std::vector< BashGuardMPPathPoint > BashGuardMPPath
Definition types.h:77
units::degree_t CalculateCuspAngle(const ArmPath &path, const size_t segmentIndex)
Definition convert_path.cpp:20
units::inch_t BashGuardPoint
Definition types.h:62
std::vector< ArmPathPoint > ArmPath
Definition types.h:65
BashGuardMPPath GenerateProfiledBashGuard(const BashGuardPoint &startPoint, const BashGuardPoint &endPoint, const PathDynamicsConstraints &constraints, units::millisecond_t resolution=20_ms)
Definition convert_path.cpp:126
CompositeMPPath GenerateCompositeMPPath(ArmMPPath generalPath, const BashGuardMPPath &bashGuardPath, const ArmPathPoint &shoulderFulcrum, LifterSubsystem *lifter)
Definition convert_path.cpp:52
VelocityComponents DecomposeVelocity(const ArmMPPathPoint &pathPoint, const ArmPathPoint &armVector)
Definition convert_path.cpp:33
std::vector< GenericMPPathPoint< PositionType, VelocityType > > PadProfile(const std::vector< GenericMPPathPoint< PositionType, VelocityType > > &profile, units::millisecond_t paddingTime, bool padFront)
Definition convert_path.h:80
std::vector< units::inch_t > GenerateSegmentLengths(const path_planning::ArmPath &path)
Definition convert_path.cpp:242
std::vector< ArmMPPathPoint > ArmMPPath
Definition types.h:74
ArmMPPath GenerateProfiledPath(const ArmPath &initialPath, const PathDynamicsConstraints &constraints, const Polygon &avoidancePolygon, units::millisecond_t resolution=20_ms)
Definition convert_path.cpp:164
std::vector< frc::TrapezoidProfile< units::inch > > GenerateSegmentProfiles(SegmentIt segmentLengthsBegin, SegmentIt segmentLengthsEnd, PathIt pathBegin, PathIt pathEnd, const PathDynamicsConstraints &constraints)
Definition convert_path.h:38
units::velocity::inches_per_second_t maxVelocity
Definition types.h:87
units::acceleration::inches_per_second_squared_t maxAcceleration
Definition types.h:88