Skip to content
Open
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions commandsv3/src/main/java/org/wpilib/command3/Trigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public Trigger(Scheduler scheduler, EventLoop loop, BooleanSupplier condition) {
m_loop.bind(m_eventLoopCallback);
}

/**
* Starts the command when the condition changes.
*
* @param command the command to start
* @return this trigger, so calls can be chained
*/
Comment on lines +118 to +123
public Trigger onChange(Command command) {
requireNonNullParam(command, "command", "onChange");
addBinding(BindingType.SCHEDULE_ON_RISING_EDGE, command);
addBinding(BindingType.SCHEDULE_ON_FALLING_EDGE, command);
Comment on lines +126 to +127

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip the initial sample in onChange

Because m_previousSignal is null until the trigger is first polled, poll() classifies the initial sample as either a rising or falling edge. Registering the command for both edge types therefore guarantees that onChange() schedules it on the first Scheduler.run() even when the supplier has never changed, contrary to the method contract and the existing V2 onChange() behavior. This needs a dedicated binding or baseline handling that ignores the initial sample.

Useful? React with 👍 / 👎.

return this;
}
Comment on lines +124 to +129

/**
* Starts the given command whenever the condition changes from `false` to `true`.
*
Expand Down
Loading