WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
TrapezoidProfileCommand.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8
10
14
15namespace frc2 {
16/**
17 * A command that runs a TrapezoidProfile. Useful for smoothly controlling
18 * mechanism motion.
19 *
20 * This class is provided by the NewCommands VendorDep
21 *
22 * @see TrapezoidProfile
23 */
24template <class Distance>
26 : public CommandHelper<Command, TrapezoidProfileCommand<Distance>> {
28 using Velocity =
31 using State = typename frc::TrapezoidProfile<Distance>::State;
32
33 public:
34 /**
35 * Creates a new TrapezoidProfileCommand that will execute the given
36 * TrapezoidalProfile. Output will be piped to the provided consumer function.
37 *
38 * @param profile The motion profile to execute.
39 * @param output The consumer for the profile output.
40 * @param goal The supplier for the desired state
41 * @param currentState The current state
42 * @param requirements The list of requirements.
43 * @deprecated Use a TrapezoidProfile instead
44 */
45 [[deprecated("Use a TrapezoidProfile instead")]]
47 std::function<void(State)> output,
48 std::function<State()> goal,
49 std::function<State()> currentState,
50 Requirements requirements = {})
51 : m_profile(profile),
52 m_output(output),
53 m_goal(goal),
54 m_currentState(currentState) {
55 this->AddRequirements(requirements);
56 }
57
58 void Initialize() override {}
59
60 void Execute() override {
61 m_output(m_profile.Calculate(20_ms, m_currentState(), m_goal()));
62 }
63
64 void End(bool interrupted) override {}
65
66 bool IsFinished() override { return m_profile.IsFinished(0_s); }
67
68 private:
70 std::function<void(State)> m_output;
71 std::function<State()> m_goal;
72 std::function<State()> m_currentState;
73};
74
75} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition CommandHelper.h:25
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition Requirements.h:20
A command that runs a TrapezoidProfile.
Definition TrapezoidProfileCommand.h:26
void Initialize() override
Definition TrapezoidProfileCommand.h:58
void Execute() override
Definition TrapezoidProfileCommand.h:60
void End(bool interrupted) override
Definition TrapezoidProfileCommand.h:64
TrapezoidProfileCommand(frc::TrapezoidProfile< Distance > profile, std::function< void(State)> output, std::function< State()> goal, std::function< State()> currentState, Requirements requirements={})
Creates a new TrapezoidProfileCommand that will execute the given TrapezoidalProfile.
Definition TrapezoidProfileCommand.h:46
bool IsFinished() override
Definition TrapezoidProfileCommand.h:66
Profile state.
Definition TrapezoidProfile.h:96
A trapezoid-shaped velocity profile.
Definition TrapezoidProfile.h:46
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438
Definition FunctionalCommand.h:13