Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Add Scheduled command decorator #7083

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6b45ec5
first draft
narmstro2020 Sep 14, 2024
0c5fa51
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Sep 15, 2024
1fb92f0
Formatting fixes
github-actions[bot] Sep 15, 2024
2952b47
fix Java argument requirements
narmstro2020 Sep 15, 2024
8927cc2
Merge branch 'ScheduledCommand-decorator' of https://github.com/narms…
narmstro2020 Sep 15, 2024
0ed013f
Formatting fixes
github-actions[bot] Sep 15, 2024
883c761
missing period
narmstro2020 Sep 15, 2024
dc8e576
Merge branch 'ScheduledCommand-decorator' of https://github.com/narms…
narmstro2020 Sep 15, 2024
c863eb5
removed C++ for now
narmstro2020 Sep 15, 2024
256dc21
fully remove c++ for now.
narmstro2020 Sep 15, 2024
9a684d6
Formatting fixes
github-actions[bot] Sep 15, 2024
cfd03b9
param rename
narmstro2020 Sep 15, 2024
3540205
Formatting fixes
github-actions[bot] Sep 15, 2024
8b170f4
fixed loop copy of array
narmstro2020 Sep 15, 2024
3e58989
formatting fixes
narmstro2020 Sep 15, 2024
6e7f396
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Sep 21, 2024
8f390e5
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Sep 29, 2024
21d7f33
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Oct 1, 2024
bc3595b
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Oct 10, 2024
8c15f99
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Oct 11, 2024
fcfcb55
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Oct 11, 2024
1191215
attempt
narmstro2020 Oct 11, 2024
feaedf6
Merge branch 'wpilibsuite:main' into ScheduledCommand-decorator
narmstro2020 Oct 23, 2024
1b64ab2
pointer updates
narmstro2020 Oct 23, 2024
5172e87
fix thanks space-sooty
narmstro2020 Oct 23, 2024
4793d6c
Formatting fixes
github-actions[bot] Oct 23, 2024
e4d268d
varargs added?
narmstro2020 Oct 23, 2024
fd9ae09
Merge branch 'ScheduledCommand-decorator' of https://github.com/narms…
narmstro2020 Oct 23, 2024
8420248
revert
narmstro2020 Oct 23, 2024
7f05e7d
varargs attempt 2
narmstro2020 Oct 23, 2024
f9abc95
another attempt using std::vector
narmstro2020 Oct 23, 2024
13313f3
revert again
narmstro2020 Oct 23, 2024
49c52c0
Formatting fixes
github-actions[bot] Oct 23, 2024
71a038c
separate overload
narmstro2020 Oct 23, 2024
69b8809
Merge branch 'ScheduledCommand-decorator' of https://github.com/narms…
narmstro2020 Oct 23, 2024
d1b111d
possible fix
narmstro2020 Oct 23, 2024
47abdc8
Formatting fixes
github-actions[bot] Oct 23, 2024
44f542e
Update wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp
narmstro2020 Oct 23, 2024
e208fa9
revert
narmstro2020 Oct 23, 2024
b667e18
requested changes
narmstro2020 Oct 24, 2024
d2ff9c3
Merge branch 'ScheduledCommand-decorator' of https://github.com/narms…
narmstro2020 Oct 24, 2024
5124914
formatting fixes
narmstro2020 Oct 24, 2024
e2ff78a
formatting fixes
narmstro2020 Oct 24, 2024
9c6c77f
updates
narmstro2020 Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,23 @@ public ProxyCommand asProxy() {
return new ProxyCommand(this);
}

/**
* Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. 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. Note that if run from a composition, the
* composition will not know about the status of the scheduled commands, and will treat this
* command as finishing instantly.
*
* @return the decorated command
* @see ScheduleCommand
* @see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">WPILib
* docs</a>
*/
public ScheduleCommand fork() {
return new ScheduleCommand(this);
}

/**
* Decorates this command to only run if this condition is not met. If the command is already
* running and the condition changes to true, the command will not stop running. The requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ public static Command deferredProxy(Supplier<Command> supplier) {
return new ProxyCommand(supplier);
}

/**
* Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. 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. Note that if run from a composition, the
* composition will not know about the status of the scheduled commands, and will treat this
* command as finishing instantly. Multiple commands can be added to this and will be scheduled in
* order.
*
* @param commands the commands to schedule in order
* @return the command
* @see ScheduleCommand
* @see <a
* href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">WPILib
* docs</a>
*/
public static Command fork(Command... commands) {
return new ScheduleCommand(commands);
}

// Command Groups

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "frc2/command/ParallelRaceGroup.h"
#include "frc2/command/ProxyCommand.h"
#include "frc2/command/RepeatCommand.h"
#include "frc2/command/ScheduleCommand.h"
#include "frc2/command/SequentialCommandGroup.h"
#include "frc2/command/WaitCommand.h"
#include "frc2/command/WaitUntilCommand.h"
Expand Down Expand Up @@ -56,6 +57,13 @@ CommandPtr CommandPtr::AsProxy() && {
return std::move(*this);
}

CommandPtr CommandPtr::Fork() && {
AssertValid();
std::vector<Command*> vec{m_ptr.get()};
m_ptr = make_unique<ScheduleCommand>(std::span<Command*>(vec));
return std::move(*this);
}

class RunsWhenDisabledCommand : public WrapperCommand {
public:
RunsWhenDisabledCommand(std::unique_ptr<Command>&& command,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <utility>
#include <vector>

#include <memory>
#include <wpi/deprecated.h>

#include "frc2/command/ConditionalCommand.h"
Expand Down Expand Up @@ -83,6 +83,21 @@ CommandPtr cmd::DeferredProxy(wpi::unique_function<CommandPtr()> supplier) {
}
WPI_UNIGNORE_DEPRECATED

CommandPtr cmd::Fork(CommandPtr&& other) {
std::vector<Command*> vec{other.get()};
auto m_ptr = make_unique<ScheduleCommand>(std::span<Command*>(vec));
return ScheduleCommand(std::move(*m_ptr)).ToPtr();
}

CommandPtr cmd::Fork(std::vector<CommandPtr>&& commands) {
std::vector<Command*> vec{};
for (auto&& ptr : commands) {
vec.emplace_back(std::move(ptr).Unwrap().get());
}
auto m_ptr = make_unique<ScheduleCommand>(std::span<Command*>(vec));
return ScheduleCommand(std::move(*m_ptr)).ToPtr();
}

CommandPtr cmd::Wait(units::second_t duration) {
return WaitCommand(duration).ToPtr();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ class CommandPtr final {
[[nodiscard]]
CommandPtr AsProxy() &&;

/**
* Decorates this command to run "forked" by wrapping it in a {@link
* ScheduleCommand}. 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. Note that if run from a composition, the composition
* will not know about the status of the scheduled commands, and will treat
* this command as finishing instantly.
*
* @return the decorated command
* @see ScheduleCommand
*/
[[nodiscard]]
CommandPtr Fork() &&;

/**
* Decorates this command to run or stop when disabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "frc2/command/CommandPtr.h"
#include "frc2/command/Requirements.h"
#include "frc2/command/ScheduleCommand.h"
#include "frc2/command/SelectCommand.h"

namespace frc2 {
Expand Down Expand Up @@ -192,6 +193,36 @@ CommandPtr DeferredProxy(wpi::unique_function<Command*()> supplier);
"Defer(supplier).AsProxy() instead.")]]
CommandPtr DeferredProxy(wpi::unique_function<CommandPtr()> supplier);
WPI_UNIGNORE_DEPRECATED

/**
* Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. 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. Note that if run from a composition, the
* composition will not know about the status of the scheduled commands, and will treat this
* command as finishing instantly. Multiple commands can be added to this and will be scheduled in order.
*
* @param commands the commands to schedule in order
* @return the command
* @see ScheduleCommand
*/
[[nodiscard]]
CommandPtr Fork(CommandPtr&& commands);

/**
* Constructs a command by wrapping the provided commands in a {@link ScheduleCommand}. 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. Note that if run from a composition, the
* composition will not know about the status of the scheduled commands, and will treat this
* command as finishing instantly. Multiple commands can be added to this and will be scheduled in order.
*
* @param commands the commands to schedule in order
* @return the command
* @see ScheduleCommand
*/
[[nodiscard]]
CommandPtr Fork(std::vector<CommandPtr>&& commands);


// Command Groups

namespace impl {
Expand Down
Loading