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 26 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,28 @@ 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. Commands can be added to this and will be scheduled in order
* with this command scheduled first.
*
* @param other other commands to schedule along with this one. This command is scheduled first.
* @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(Command... other) {
Command[] commands = new Command[1 + other.length];
commands[0] = this;
System.arraycopy(other, 0, commands, 1, other.length);
return new ScheduleCommand(commands);
}

/**
* 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 @@ -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(CommandPtr&& other) && {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an overload for Fork(CommandPtr&&... other)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this error right as I add the overload
declaration is incompatible with "frc2::CommandPtr frc2::CommandPtr::Fork(frc2::CommandPtr &&other) &&" (declared at line 60)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I guess this makes sense, an overload with a std::span and maybe std::vector works as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That definitely will not work. It would need to be a seperate overload if varargs can work here but I'm not sure they can

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I've added a separate overload with no major code mods (just a copy).
I'm getting this error after other

expected a ')'C/C++(18)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is weird because the parentheses match up. Is there something i'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I guess this makes sense, an overload with a std::span and maybe std::vector works as well

Sorry I missed this, I'll use std vector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I'm floudering on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just leave out the overload?

AssertValid();
std::vector<Command*> vec{m_ptr.get(), other.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 @@ -63,6 +63,23 @@ 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. Commands can be added to this and will
* be scheduled in order with this command scheduled first.
*
* @param other other commands to schedule along with this one. This command
* is scheduled first.
* @return the decorated command
* @see ScheduleCommand
*/
[[nodiscard]]
CommandPtr Fork(CommandPtr&& other) &&;

/**
* Decorates this command to run or stop when disabled.
*
Expand Down
Loading