Skip to content

Commit

Permalink
Merge branch 'main' into armFeedForwardCalculateOverload
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Apr 28, 2024
2 parents 2fea7b7 + fd363fd commit 984fbf3
Show file tree
Hide file tree
Showing 30 changed files with 489 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/comment-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
distribution: 'zulu'
java-version: 17
- name: Install wpiformat
run: pip3 install wpiformat==2024.33
run: pip3 install wpiformat==2024.34
- name: Run wpiformat
run: wpiformat
- name: Run spotlessApply
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
python-version: '3.10'
- name: Install wpiformat
run: pip3 install wpiformat==2024.33
run: pip3 install wpiformat==2024.34
- name: Run
run: wpiformat
- name: Check output
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
with:
python-version: '3.10'
- name: Install wpiformat
run: pip3 install wpiformat
run: pip3 install wpiformat==2024.34
- name: Create compile_commands.json
run: |
./gradlew generateCompileCommands -Ptoolchain-optional-roboRio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public enum AprilTagFields {
*
* @return AprilTagFieldLayout of the field
* @throws UncheckedIOException If the layout does not exist
* @deprecated Use {@link AprilTagFieldLayout#loadField(AprilTagFields)} instead.
*/
@Deprecated(forRemoval = true, since = "2025")
public AprilTagFieldLayout loadAprilTagLayoutField() {
return AprilTagFieldLayout.loadField(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ void from_json(const wpi::json& json, AprilTagFieldLayout& layout);
*
* @param field The predefined field
* @return AprilTagFieldLayout of the field
* @deprecated Use AprilTagFieldLayout::LoadField() instead
*/
[[deprecated("Use AprilTagFieldLayout::LoadField() instead")]]
WPILIB_DLLEXPORT AprilTagFieldLayout
LoadAprilTagLayoutField(AprilTagField field);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,16 @@ public RepeatCommand repeatedly() {
}

/**
* Decorates this command to run "by proxy" by wrapping it in a {@link ProxyCommand}. This is
* useful for "forking off" from command compositions when the user does not wish to extend the
* command's requirements to the entire command composition.
* Decorates this command to run "by proxy" by wrapping it in a {@link ProxyCommand}. Use this for
* "forking off" from command compositions when the user does not wish to extend the command's
* requirements to the entire command composition. ProxyCommand has unique implications and
* semantics, see the WPILib docs for a full explanation.
*
* @return the decorated command
* @see ProxyCommand
* @see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">WPILib
* docs</a>
*/
public ProxyCommand asProxy() {
return new ProxyCommand(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import java.util.function.Supplier;

/**
* Defers Command construction to runtime. Runs the command returned by the supplier when this
* command is initialized, and ends when it ends. Useful for performing runtime tasks before
* creating a new command. If this command is interrupted, it will cancel the command.
* Defers Command construction to runtime. Runs the command returned by a supplier when this command
* is initialized, and ends when it ends. Useful for performing runtime tasks before creating a new
* command. If this command is interrupted, it will cancel the command.
*
* <p>Note that the supplier <i>must</i> create a new Command each call. For selecting one of a
* preallocated set of commands, use {@link SelectCommand}.
Expand All @@ -28,9 +28,10 @@ public class DeferredCommand extends Command {
private Command m_command = m_nullCommand;

/**
* Creates a new DeferredCommand that runs the supplied command when initialized, and ends when it
* ends. Useful for lazily creating commands at runtime. The {@link Supplier} will be called each
* time this command is initialized. The Supplier <i>must</i> create a new Command each call.
* Creates a new DeferredCommand that directly runs the supplied command when initialized, and
* ends when it ends. Useful for lazily creating commands when the DeferredCommand is initialized,
* such as if the supplied command depends on runtime state. The {@link Supplier} will be called
* each time this command is initialized. The Supplier <i>must</i> create a new Command each call.
*
* @param supplier The command supplier
* @param requirements The command requirements. This is a {@link Set} to prevent accidental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
import java.util.function.Supplier;

/**
* Schedules the given command when this command is initialized, and ends when it ends. Useful for
* forking off from CommandGroups. If this command is interrupted, it will cancel the command.
* Schedules a given command when this command is initialized and ends when it ends, but does not
* directly run it. Use this for including a command in a composition without adding its
* requirements, <strong>but only if you know what you are doing. If you are unsure, see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">the
* WPILib docs</a> for a complete explanation of proxy semantics.</strong> Do not proxy a command
* from a subsystem already required by the composition, or else the composition will cancel itself
* when the proxy is reached. If this command is interrupted, it will cancel the command.
*
* <p>This class is provided by the NewCommands VendorDep
*/
Expand All @@ -21,9 +26,12 @@ public class ProxyCommand extends Command {

/**
* Creates a new ProxyCommand that schedules the supplied command when initialized, and ends when
* it is no longer scheduled. Useful for lazily creating commands at runtime.
* it is no longer scheduled. Use this for lazily creating <strong>proxied</strong> commands at
* runtime. Proxying should only be done to escape from composition requirement semantics, so if
* only initialization time command construction is needed, use {@link DeferredCommand} instead.
*
* @param supplier the command supplier
* @see DeferredCommand
*/
public ProxyCommand(Supplier<Command> supplier) {
m_supplier = requireNonNullParam(supplier, "supplier", "ProxyCommand");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class TrapezoidProfileCommand extends Command {
private final Consumer<State> m_output;
private final Supplier<State> m_goal;
private final Supplier<State> m_currentState;
private final boolean m_newAPI; // TODO: Remove
private final Timer m_timer = new Timer();

/**
Expand All @@ -46,29 +45,6 @@ public TrapezoidProfileCommand(
m_output = requireNonNullParam(output, "output", "TrapezoidProfileCommand");
m_goal = goal;
m_currentState = currentState;
m_newAPI = true;
addRequirements(requirements);
}

/**
* Creates a new TrapezoidProfileCommand that will execute the given {@link TrapezoidProfile}.
* Output will be piped to the provided consumer function.
*
* @param profile The motion profile to execute.
* @param output The consumer for the profile output.
* @param requirements The subsystems required by this command.
* @deprecated The new constructor allows you to pass in a supplier for desired and current state.
* This allows you to change goals at runtime.
*/
@Deprecated(since = "2024", forRemoval = true)
@SuppressWarnings("this-escape")
public TrapezoidProfileCommand(
TrapezoidProfile profile, Consumer<State> output, Subsystem... requirements) {
m_profile = requireNonNullParam(profile, "profile", "TrapezoidProfileCommand");
m_output = requireNonNullParam(output, "output", "TrapezoidProfileCommand");
m_newAPI = false;
m_goal = null;
m_currentState = null;
addRequirements(requirements);
}

Expand All @@ -80,11 +56,7 @@ public void initialize() {
@Override
@SuppressWarnings("removal")
public void execute() {
if (m_newAPI) {
m_output.accept(m_profile.calculate(m_timer.get(), m_currentState.get(), m_goal.get()));
} else {
m_output.accept(m_profile.calculate(m_timer.get()));
}
m_output.accept(m_profile.calculate(m_timer.get(), m_currentState.get(), m_goal.get()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "frc2/command/ProxyCommand.h"

#include <fmt/core.h>
#include <wpi/sendable/SendableBuilder.h>

using namespace frc2;
Expand All @@ -20,11 +21,11 @@ ProxyCommand::ProxyCommand(wpi::unique_function<CommandPtr()> supplier)

ProxyCommand::ProxyCommand(Command* command)
: ProxyCommand([command] { return command; }) {
SetName(std::string{"Proxy("}.append(command->GetName()).append(")"));
SetName(fmt::format("Proxy({})", command->GetName()));
}

ProxyCommand::ProxyCommand(std::unique_ptr<Command> command) {
SetName(std::string{"Proxy("}.append(command->GetName()).append(")"));
SetName(fmt::format("Proxy({})", command->GetName()));
m_supplier = [command = std::move(command)] { return command.get(); };
}

Expand Down
11 changes: 7 additions & 4 deletions wpilibNewCommands/src/main/native/include/frc2/command/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@ class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
CommandPtr Repeatedly() &&;

/**
* Decorates this command to run "by proxy" by wrapping it in a
* ProxyCommand. This is useful for "forking off" from command groups
* when the user does not wish to extend the command's requirements to the
* entire command group.
* Decorates this command to run "by proxy" by wrapping it in a ProxyCommand.
* Use this for "forking off" from command compositions when the user does not
* wish to extend the command's requirements to the entire command
* composition. ProxyCommand has unique implications and semantics, see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">the
* WPILib docs</a> for a full explanation.
*
* <p>This overload transfers command ownership to the returned CommandPtr.
*
* @return the decorated command
* @see ProxyCommand
*/
[[nodiscard]]
CommandPtr AsProxy() &&;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <concepts>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -51,12 +50,15 @@ class CommandPtr final {
CommandPtr Repeatedly() &&;

/**
* Decorates this command to run "by proxy" by wrapping it in a
* ProxyCommand. This is useful for "forking off" from command groups
* when the user does not wish to extend the command's requirements to the
* entire command group.
* Decorates this command to run "by proxy" by wrapping it in a ProxyCommand.
* Use this for "forking off" from command compositions when the user does not
* wish to extend the command's requirements to the entire command
* composition. ProxyCommand has unique implications and semantics, see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">the
* WPILib docs</a> for a full explanation.
*
* @return the decorated command
* @see ProxyCommand
*/
[[nodiscard]]
CommandPtr AsProxy() &&;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace frc2 {
/**
* Defers Command construction to runtime. Runs the command returned by the
* Defers Command construction to runtime. Runs the command returned by a
* supplier when this command is initialized, and ends when it ends. Useful for
* performing runtime tasks before creating a new command. If this command is
* interrupted, it will cancel the command.
Expand All @@ -29,9 +29,10 @@ namespace frc2 {
class DeferredCommand : public CommandHelper<Command, DeferredCommand> {
public:
/**
* Creates a new DeferredCommand that runs the supplied command when
* initialized, and ends when it ends. Useful for lazily
* creating commands at runtime. The supplier will be called each time this
* Creates a new DeferredCommand that directly runs the supplied command when
* initialized, and ends when it ends. Useful for lazily creating commands
* when the DeferredCommand is initialized, such as if the supplied command
* depends on runtime state. The supplier will be called each time this
* command is initialized. The supplier <i>must</i> create a new Command each
* call.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma warning(disable : 4521)
#endif

#include <concepts>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma warning(disable : 4521)
#endif

#include <concepts>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,43 @@

namespace frc2 {
/**
* Schedules the given command when this command is initialized, and ends when
* it ends. Useful for forking off from CommandGroups. If this command is
* interrupted, it will cancel the command.
* Schedules a given command when this command is initialized and ends when it
* ends, but does not directly run it. Use this for including a command in a
* composition without adding its requirements, <strong>but only if you know
* what you are doing. If you are unsure, see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">the
* WPILib docs</a> for a complete explanation of proxy semantics.</strong> Do
* not proxy a command from a subsystem already required by the composition, or
* else the composition will cancel itself when the proxy is reached. If this
* command is interrupted, it will cancel the command.
*
* <p>This class is provided by the NewCommands VendorDep
*/
class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
public:
/**
* Creates a new ProxyCommand that schedules the supplied command when
* initialized, and ends when it is no longer scheduled. Useful for lazily
* creating commands at runtime.
* initialized, and ends when it is no longer scheduled. Use this for lazily
* creating <strong>proxied</strong> commands at runtime. Proxying should only
* be done to escape from composition requirement semantics, so if only
* initialization time command construction is needed, use {@link
* DeferredCommand} instead.
*
* @param supplier the command supplier
* @see DeferredCommand
*/
explicit ProxyCommand(wpi::unique_function<Command*()> supplier);

/**
* Creates a new ProxyCommand that schedules the supplied command when
* initialized, and ends when it is no longer scheduled. Useful for lazily
* creating commands at runtime.
* initialized, and ends when it is no longer scheduled. Use this for lazily
* creating <strong>proxied</strong> commands at runtime. Proxying should only
* be done to escape from composition requirement semantics, so if only
* initialization time command construction is needed, use {@link
* DeferredCommand} instead.
*
* @param supplier the command supplier
* @see DeferredCommand
*/
explicit ProxyCommand(wpi::unique_function<CommandPtr()> supplier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma warning(disable : 4521)
#endif

#include <concepts>
#include <limits>
#include <memory>
#include <type_traits>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,6 @@ class TrapezoidProfileCommand
m_goal(goal),
m_currentState(currentState) {
this->AddRequirements(requirements);
m_newAPI = true;
}

/**
* Creates a new TrapezoidProfileCommand that will execute the given
* TrapezoidalProfile. Output will be piped to the provided consumer function.
*
* @param profile The motion profile to execute.
* @param output The consumer for the profile output.
* @param requirements The list of requirements.
* @deprecated The new constructor allows you to pass in a supplier for
* desired and current state. This allows you to change goals at runtime.
*/
[[deprecated(
"The new constructor allows you to pass in a supplier for desired and "
"current state. This allows you to change goals at runtime.")]]
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
std::function<void(State)> output,
Requirements requirements = {})
: m_profile(profile), m_output(output) {
this->AddRequirements(requirements);
m_newAPI = false;
}

void Initialize() override { m_timer.Restart(); }
Expand All @@ -93,7 +71,6 @@ class TrapezoidProfileCommand
std::function<void(State)> m_output;
std::function<State()> m_goal;
std::function<State()> m_currentState;
bool m_newAPI; // TODO: Remove
frc::Timer m_timer;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
#include <frc/simulation/SimHooks.h>

#include "CommandTestBase.h"
#include "frc2/command/ConditionalCommand.h"
#include "frc2/command/FunctionalCommand.h"
#include "frc2/command/InstantCommand.h"
#include "frc2/command/ParallelRaceGroup.h"
#include "frc2/command/RunCommand.h"
#include "frc2/command/SequentialCommandGroup.h"

using namespace frc2;
class CommandDecoratorTest : public CommandTestBase {};
Expand Down
Loading

0 comments on commit 984fbf3

Please sign in to comment.