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

WIP: Scheduler command rewrite #1637

Closed
wants to merge 212 commits into from
Closed
Show file tree
Hide file tree
Changes from 187 commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
acc0e7d
Merge pull request #1 from wpilibsuite/master
Oblarg Feb 16, 2019
fcf0e2d
Merge pull request #2 from wpilibsuite/master
Oblarg Mar 8, 2019
faa5be0
add scheduler option to add actions to command start, execution, inte…
Oblarg Mar 8, 2019
617b20d
formatting and variable name style
Oblarg Mar 10, 2019
c9abdd3
more formatting
Oblarg Mar 10, 2019
ef0e6b5
suppress field/method warning
Oblarg Mar 11, 2019
2f175f5
start work on command framework refactor
Oblarg Mar 12, 2019
3b12ea0
first draft of commandrunner
Oblarg Mar 12, 2019
8c728bf
fix null checking
Oblarg Mar 12, 2019
2ca0fc9
spelling
Oblarg Mar 12, 2019
5c85d89
WIP continues
Oblarg Mar 12, 2019
d1b7e56
WIP continues
Oblarg Mar 12, 2019
c3309fd
WIP continues
Oblarg Mar 12, 2019
48e82d2
WIP continues
Oblarg Mar 12, 2019
319f06a
write parallelcommandgroup
Oblarg Mar 12, 2019
2022b1c
write sequentialcommandgroup
Oblarg Mar 12, 2019
79684f3
write sequentialcommandgroup
Oblarg Mar 12, 2019
9a70d0f
write sequentialcommandgroup
Oblarg Mar 12, 2019
dc8e334
fix for repeated execution
Oblarg Mar 12, 2019
8b4836e
fix for repeated execution
Oblarg Mar 12, 2019
f8b555a
continue work
Oblarg Mar 12, 2019
2b0ed0a
fix imports
Oblarg Mar 12, 2019
c54882f
handle empty array (behavior needs to be the same as ParallelCommandG…
Oblarg Mar 12, 2019
307e23a
migrate button stuff back to buttons
Oblarg Mar 12, 2019
730a552
migrate button stuff back to buttons
Oblarg Mar 12, 2019
e2dc281
continue work
Oblarg Mar 12, 2019
3b745b1
continue work
Oblarg Mar 12, 2019
0718aad
continue work
Oblarg Mar 12, 2019
ebd7a84
continue work
Oblarg Mar 13, 2019
45271f2
remove stuff from command and scheduler
Oblarg Mar 13, 2019
642a47f
change to java 11
Oblarg Mar 13, 2019
5b04c5f
fix style
Oblarg Mar 13, 2019
8acbf13
formatting nonsense
Oblarg Mar 13, 2019
ad4a14d
formatting nonsense
Oblarg Mar 13, 2019
237d842
formatting nonsense
Oblarg Mar 13, 2019
300d17f
Add replacement PIDController class and classes that use it
calcmogul Aug 31, 2018
47818cd
Add shims implementing MeasurementSource
calcmogul Nov 25, 2018
0723921
formatting and docs
Oblarg Mar 13, 2019
80ca092
formatting
Oblarg Mar 13, 2019
8df59ec
code style
Oblarg Mar 13, 2019
5ab0712
fix small error
Oblarg Mar 13, 2019
a19af6d
remove unused import
Oblarg Mar 13, 2019
d54ddf6
fix logic error
Oblarg Mar 13, 2019
c4d8fe6
ignore PMD crap
Oblarg Mar 13, 2019
401b1c5
write first unit test
Oblarg Mar 13, 2019
334e390
formatting
Oblarg Mar 13, 2019
dd6781a
continue writing unit tests
Oblarg Mar 14, 2019
17d019c
tests, tests, come get your tests
Oblarg Mar 14, 2019
56d631a
remove unused import
Oblarg Mar 14, 2019
b77491b
make subsystem an interface, move namespaces, rename everything
Oblarg Mar 15, 2019
7fcdaa1
separate buttons again now that namespace has been moved
Oblarg Mar 15, 2019
ef0f9e6
fix formatting, imports, etc
Oblarg Mar 15, 2019
78aff43
PMD can shut up now
Oblarg Mar 15, 2019
bce527b
formatting
Oblarg Mar 15, 2019
19fa39c
fix style
Oblarg Mar 15, 2019
87b7a63
change requirements to set to avoid repeats
Oblarg Mar 15, 2019
c8a28ca
avoid hash lookup in parallelcommandgroup
Oblarg Mar 15, 2019
1c581fe
rename for readability
Oblarg Mar 15, 2019
9fc3a8f
reduce needless allocation in commandgroups
Oblarg Mar 15, 2019
7a11bc2
simplify command group runwhendisabled
Oblarg Mar 15, 2019
b33af18
add addCommands method to commandgroups
Oblarg Mar 15, 2019
113b3ae
minor performance/code cleanliness improvement
Oblarg Mar 15, 2019
4dcd025
write button unit tests
Oblarg Mar 15, 2019
19ed8e3
add ParallelCommandRace
Oblarg Mar 15, 2019
799601d
remove inaccurate comment
Oblarg Mar 15, 2019
449c3f7
add unit tests for ParallelCommandRace
Oblarg Mar 15, 2019
fbf8d71
add WaitCommand and withTimeout method for commands
Oblarg Mar 15, 2019
09a65a1
rename methods to be consistent between scheduler and command
Oblarg Mar 15, 2019
b62d86a
make waitcommand run when disabled
Oblarg Mar 15, 2019
0761145
pull new PIDController, write SynchronousPIDCommand
Oblarg Mar 16, 2019
0de3808
add getcontroller
Oblarg Mar 16, 2019
91f7c4c
continue working on pidcommands
Oblarg Mar 16, 2019
9050b2c
continue working on pidcommands
Oblarg Mar 16, 2019
4412f60
write commands
Oblarg Mar 16, 2019
3547133
formatting
Oblarg Mar 16, 2019
08fda42
add isFinished to conditionalcommand
Oblarg Mar 16, 2019
6238f69
fix requirements
Oblarg Mar 16, 2019
4b64152
add a couple more commands, write docs
Oblarg Mar 16, 2019
2bb0edc
add subsystembase and selectcommands
Oblarg Mar 16, 2019
0a4603d
docs
Oblarg Mar 16, 2019
c36be5a
write PIDSubsystems
Oblarg Mar 16, 2019
9933c96
checkstyle
Oblarg Mar 16, 2019
b7ca765
remove redundant commands (can simply compose with ScheduleCommand)
Oblarg Mar 16, 2019
d5a6b97
add note about commandgroup requirements
Oblarg Mar 16, 2019
f46c8aa
make ScheduleCommand run when disabled
Oblarg Mar 16, 2019
c0cbe5a
error if parallel commands share requirements
Oblarg Mar 16, 2019
478a56f
decouple Command from Sendable, add abstract base class for Sendable …
Oblarg Mar 17, 2019
de88dd2
decouple Subsystem from Sendable, move Sendable impl into SubsystemBa…
Oblarg Mar 17, 2019
c3ae12f
add docs for Subsystem
Oblarg Mar 17, 2019
ffc42c2
update docs
Oblarg Mar 17, 2019
8cc9f76
update docs
Oblarg Mar 17, 2019
b314e25
update docs
Oblarg Mar 17, 2019
c0b60b7
add sensible names to WaitCommand and WaitUntilCommand
Oblarg Mar 17, 2019
39d7a96
formatting
Oblarg Mar 17, 2019
3c974c9
add appropriate comment
Oblarg Mar 17, 2019
b445122
change to vararg where appropriate, add vararg addRequirements() to C…
Oblarg Mar 17, 2019
326dbdd
minor doc change
Oblarg Mar 17, 2019
68e0250
formatting
Oblarg Mar 17, 2019
339117d
minor change to waitcommand
Oblarg Mar 17, 2019
7b46827
make ScheduleCommand vararg, write more tests
Oblarg Mar 17, 2019
f5056c3
add waitcommand tests
Oblarg Mar 17, 2019
b49ee06
remove unused import
Oblarg Mar 17, 2019
ef0349a
checkstyle
Oblarg Mar 17, 2019
fd6b51f
add requirement tests for SelectCommand and ConditionalCommand
Oblarg Mar 17, 2019
ffd2ef9
clean up testbase
Oblarg Mar 17, 2019
8af3b2f
add ParallelDictatorGroup
Oblarg Mar 18, 2019
a3f1275
docs
Oblarg Mar 18, 2019
5077506
docs
Oblarg Mar 18, 2019
0ac1560
add tests for ParallelDictatorGroup, rename ParallelCommandRace to Pa…
Oblarg Mar 18, 2019
0a7daed
deprecate old commands/subsystems
Oblarg Mar 18, 2019
753c280
add EndOnConditionCommand and new decorator
Oblarg Mar 18, 2019
72f5e1b
style/format
Oblarg Mar 18, 2019
cc75aa8
comment scheduler
Oblarg Mar 18, 2019
6c0e4a9
add runnable bindings to button and trigger, update docs
Oblarg Mar 19, 2019
9d0d83b
write unit tests, fix concurrentmodificationexception
Oblarg Mar 19, 2019
76fd8a8
make subsystem registration vararg
Oblarg Mar 19, 2019
faef357
replace toremove lists with direct use of iterator, write tests for s…
Oblarg Mar 19, 2019
03e6ad1
PMD
Oblarg Mar 19, 2019
9fd484b
add multiple command schedule test, make a bunch of things vararg
Oblarg Mar 19, 2019
2bcda5c
create tests for endonconditioncommand and withinterruptcondition
Oblarg Mar 19, 2019
654b210
add public methods for clearing grouped commands.
Oblarg Mar 19, 2019
0b443de
add test for decorator error throwing and clearing grouped command
Oblarg Mar 19, 2019
92ce6ca
rename test
Oblarg Mar 19, 2019
9a14ea0
improve docs
Oblarg Mar 19, 2019
28159e4
un-default getRequirements
Oblarg Mar 19, 2019
7f13218
refactor default commands, add a few more tests
Oblarg Mar 21, 2019
f3f7945
remove unused field
Oblarg Mar 21, 2019
7cb600f
add RunMotorCommand
Oblarg Mar 21, 2019
f35b5f4
clean up InstantCommand and RunMotorCommand, add RunRunnableCommand
Oblarg Mar 21, 2019
96355eb
add whenFinished
Oblarg Mar 21, 2019
cc08c87
rename variables for clarity
Oblarg Mar 21, 2019
37c53ee
update javadoc
Oblarg Mar 21, 2019
d1e57d2
add BlockingScheduleCommand
Oblarg Mar 21, 2019
e806d7b
fix naming
Oblarg Mar 21, 2019
b45cfd4
fix logic
Oblarg Mar 21, 2019
c888f16
add NotifierCommand
Oblarg Mar 21, 2019
59c5fd5
make trigger composeable
Oblarg Mar 21, 2019
fd7dd67
add button composition test
Oblarg Mar 21, 2019
ff9333d
add beforeStarting decorator
Oblarg Mar 21, 2019
2d36e22
Merge pull request #4 from calcmogul/new-pidcontroller
Oblarg Mar 21, 2019
3ab3e2b
various improvements
Oblarg Mar 21, 2019
7a70f3d
docs
Oblarg Mar 21, 2019
ead9108
thread safety
Oblarg Mar 21, 2019
69aa405
fix closures because java stinks
Oblarg Mar 21, 2019
e4f2631
remove ControllerOutput and MeasurementSource
Oblarg Mar 21, 2019
310f837
add andThen
Oblarg Mar 21, 2019
13f6de5
add alongWith
Oblarg Mar 21, 2019
427f9f8
change alongWith to dictatorgroup
Oblarg Mar 21, 2019
b848e47
add asWellAs and raceWith
Oblarg Mar 21, 2019
dfcdab7
refactor runMotor to runOutput
Oblarg Mar 21, 2019
bb213c9
rename RunRunnable to Run
Oblarg Mar 21, 2019
1374cfa
replace RunOutputCommand with StartEndCommand (much more general)
Oblarg Mar 21, 2019
c881a3b
make blockingschedulecommand interrupt commands if interrupted
Oblarg Mar 23, 2019
e7b2855
rename withInterruptCondition to interruptOn
Oblarg Mar 24, 2019
43b78a4
formatting nonsense
Oblarg Mar 25, 2019
80d17c8
remove interrupted(), change end to take an interrupted flag
Oblarg Mar 25, 2019
7141f31
absorb EndOnConditionCommand into WaitCommand
Oblarg Mar 25, 2019
eaf6ef2
misc. doc changes
Oblarg Mar 26, 2019
57480b3
change alongWith to dictating and asWellAs to alongWith
Oblarg Mar 26, 2019
c4600fe
add PerpetualCommand
Oblarg Mar 26, 2019
2213938
add perpetually() decorator
Oblarg Mar 26, 2019
3ece9c4
fix some of the decorators, add unit tests for all decorators
Oblarg Mar 26, 2019
799edea
minor cleanup
Oblarg Mar 26, 2019
08bf6b7
remove redundant overloaded constructors
Oblarg Mar 26, 2019
a8f8670
cleanup
Oblarg Mar 26, 2019
169959a
null check runnables w/ delayed execution
Oblarg Mar 26, 2019
3c58af3
rename "dictator" to "deadline"
Oblarg Mar 27, 2019
26475e7
prevent commands from being added to commandgroups while running
Oblarg Mar 28, 2019
86730d5
make button calls chainable, add getButton method to GenericHID
Oblarg Mar 28, 2019
bce42a9
null check controllers/sources, add reference setter that takes a dou…
Oblarg Mar 28, 2019
92f1448
Remake command-based template to use new library
Oblarg Mar 28, 2019
7629792
add explanatory command for scheduler call
Oblarg Mar 28, 2019
e1b0721
fix docs in robot.java
Oblarg Mar 28, 2019
5651ed9
cancel commands at start of test mode.
Oblarg Mar 28, 2019
21d5e95
create example 2019 hatch bot
Oblarg Mar 29, 2019
aa4e667
remove unused examplecommand
Oblarg Mar 29, 2019
a51964b
remove avoid star import style rule
Oblarg Mar 29, 2019
6625293
move ComplexAuto into its own file
Oblarg Mar 29, 2019
28682a2
fix encoder reversal
Oblarg Mar 29, 2019
e783f5f
remove unused import
Oblarg Mar 29, 2019
1dcd1a7
refactor constants class to be better
Oblarg Mar 29, 2019
05017b8
add FunctionalCommand, make constants final
Oblarg Mar 29, 2019
f7d2140
move magic values into constants
Oblarg Mar 29, 2019
a211291
add frisbeebot example
Oblarg Mar 29, 2019
cd1ff35
add TODOs
Oblarg Mar 29, 2019
7ee6b46
add repeat scheduling tests for commandgroups, fix import in example
Oblarg Mar 29, 2019
a6e0ecf
merge PR from pidcontroller rewrite to fix PIDCommands/subsystems
Oblarg Mar 30, 2019
fbca235
fix style
Oblarg Mar 30, 2019
f221b79
refactor setEnabled to enable and disable, fix small bug
Oblarg Mar 30, 2019
dd5bc40
add feedforward for shooter PID
Oblarg Mar 30, 2019
a0756ca
add gyro stabilization example
Oblarg Mar 30, 2019
789aa94
add turn to angle example
Oblarg Mar 30, 2019
999f191
fix units
Oblarg Mar 30, 2019
458fb10
change constructors to be more flexible
Oblarg Mar 30, 2019
f5b5bfb
fix small errors in gyro code
Oblarg Mar 30, 2019
5faa9fd
create "traditional" hatch bot example, rename previous to "inlined"
Oblarg Mar 30, 2019
cb782cd
add reverse gyro constant
Oblarg Mar 30, 2019
e6c2495
fix accidental refactoring tool overreach
Oblarg Mar 31, 2019
a1c187e
add SelectCommand example
Oblarg Mar 31, 2019
fbfdd6f
fix package name
Oblarg Mar 31, 2019
288f5b8
fix refactor tool snafu
Oblarg Apr 1, 2019
3e62890
add scheduler event logging example
Oblarg Apr 3, 2019
b6cebd3
make private
Oblarg Apr 3, 2019
eefd2ff
Make method names consistent
Oblarg Apr 3, 2019
d4df34e
add register() method to subsystem that wraps the scheduler call
Oblarg Apr 3, 2019
c05cd88
add static factories for command groups, for convenience
Oblarg Apr 5, 2019
86062ee
make static factories return correct type
Oblarg Apr 5, 2019
7092cb0
clean up requirement in example
Oblarg Apr 5, 2019
1d6a2f2
clean up requirement in example
Oblarg Apr 5, 2019
78a761c
formatting
Oblarg Apr 5, 2019
0f19fca
doc updates
Oblarg Apr 7, 2019
5e411bd
improve selectcommand with additional constructor that takes command …
Oblarg Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/build.gradle
Expand Up @@ -97,7 +97,7 @@ ext {
apply from: "${rootDir}/shared/opencv.gradle"

task generateJavaDocs(type: Javadoc) {
options.links("https://docs.oracle.com/javase/8/docs/api/")
options.links("https://docs.oracle.com/en/java/javase/11/docs/api/")
options.addStringOption "tag", "pre:a:Pre-Condition"
options.addStringOption('Xdoclint:accessibility,html,missing,reference,syntax')
options.addBooleanOption('html5', true)
Expand Down
4 changes: 0 additions & 4 deletions shared/java/javacommon.gradle
Expand Up @@ -100,10 +100,6 @@ sourceSets {
dev
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs = ['--release', '8']
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.2.0'
Expand Down
1 change: 0 additions & 1 deletion styleguide/checkstyle.xml
Expand Up @@ -70,7 +70,6 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
<property name="sortStaticImportsAlphabetically"
value="true"/>
</module>
<module name="AvoidStarImport" />
<module name="RedundantImport" />
<module name="UnusedImports" />
<module name="OneTopLevelClass" />
Expand Down
31 changes: 31 additions & 0 deletions wpilibc/src/main/native/cpp/experimental/AnalogAccelerometer.cpp
@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/experimental/AnalogAccelerometer.h"

using namespace frc::experimental;

AnalogAccelerometer::AnalogAccelerometer(int channel) : m_impl(channel) {}

AnalogAccelerometer::AnalogAccelerometer(AnalogInput& channel)
: m_impl(&channel) {}

double AnalogAccelerometer::GetAcceleration() const {
return m_impl.GetAcceleration();
}

void AnalogAccelerometer::SetSensitivity(double sensitivity) {
m_impl.SetSensitivity(sensitivity);
}

void AnalogAccelerometer::SetZero(double zero) { m_impl.SetZero(zero); }

double AnalogAccelerometer::GetMeasurement() const { return GetAcceleration(); }

void AnalogAccelerometer::InitSendable(SendableBuilder& builder) {
m_impl.InitSendable(builder);
}
98 changes: 98 additions & 0 deletions wpilibc/src/main/native/cpp/experimental/AnalogInput.cpp
@@ -0,0 +1,98 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/experimental/AnalogInput.h"

#include <utility>

#include <hal/AnalogAccumulator.h>
#include <hal/AnalogInput.h>
#include <hal/HAL.h>
#include <hal/Ports.h>

#include "frc/SensorUtil.h"
#include "frc/Timer.h"
#include "frc/WPIErrors.h"
#include "frc/smartdashboard/SendableBuilder.h"

using namespace frc::experimental;

AnalogInput::AnalogInput(int channel) : m_impl(channel) {}

int AnalogInput::GetValue() const { return m_impl.GetValue(); }

int AnalogInput::GetAverageValue() const { return m_impl.GetAverageValue(); }

double AnalogInput::GetVoltage() const { return m_impl.GetVoltage(); }

double AnalogInput::GetAverageVoltage() const {
return m_impl.GetAverageVoltage();
}

int AnalogInput::GetChannel() const { return m_impl.GetChannel(); }

void AnalogInput::SetAverageBits(int bits) { m_impl.SetAverageBits(bits); }

int AnalogInput::GetAverageBits() const { return m_impl.GetAverageBits(); }

void AnalogInput::SetOversampleBits(int bits) {
m_impl.SetOversampleBits(bits);
}

int AnalogInput::GetOversampleBits() const {
return m_impl.GetOversampleBits();
}

int AnalogInput::GetLSBWeight() const { return m_impl.GetLSBWeight(); }

int AnalogInput::GetOffset() const { return m_impl.GetOffset(); }

bool AnalogInput::IsAccumulatorChannel() const {
return m_impl.IsAccumulatorChannel();
}

void AnalogInput::InitAccumulator() { m_impl.InitAccumulator(); }

void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
m_impl.SetAccumulatorInitialValue(initialValue);
}

void AnalogInput::ResetAccumulator() { m_impl.ResetAccumulator(); }

void AnalogInput::SetAccumulatorCenter(int center) {
m_impl.SetAccumulatorCenter(center);
}

void AnalogInput::SetAccumulatorDeadband(int deadband) {
m_impl.SetAccumulatorDeadband(deadband);
}

int64_t AnalogInput::GetAccumulatorValue() const {
return m_impl.GetAccumulatorValue();
}

int64_t AnalogInput::GetAccumulatorCount() const {
return m_impl.GetAccumulatorCount();
}

void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
return m_impl.GetAccumulatorOutput(value, count);
}

void AnalogInput::SetSampleRate(double samplesPerSecond) {
frc::AnalogInput::SetSampleRate(samplesPerSecond);
}

double AnalogInput::GetSampleRate() {
return frc::AnalogInput::GetSampleRate();
}

double AnalogInput::GetMeasurement() const { return GetAverageVoltage(); }

void AnalogInput::InitSendable(SendableBuilder& builder) {
m_impl.InitSendable(builder);
}
97 changes: 97 additions & 0 deletions wpilibc/src/main/native/cpp/experimental/commands/PIDCommand.cpp
@@ -0,0 +1,97 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/experimental/commands/PIDCommand.h"

#include "frc/smartdashboard/SendableBuilder.h"

using namespace frc::experimental;

PIDCommand::PIDCommand(const wpi::Twine& name, double Kp, double Ki, double Kd)
: Command(name),
m_controller(Kp, Ki, Kd, *this),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(const wpi::Twine& name, double Kp, double Ki, double Kd,
double period)
: Command(name),
m_controller(Kp, Ki, Kd, *this, period),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd,
std::function<double()> feedforward, double period)
: m_controller(Kp, Ki, Kd, feedforward, *this, period),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd)
: m_controller(Kp, Ki, Kd, *this), m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd, double period)
: m_controller(Kp, Ki, Kd, *this, period), m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(const wpi::Twine& name, double Kp, double Ki, double Kd,
Subsystem& subsystem)
: Command(name, subsystem),
m_controller(Kp, Ki, Kd, *this),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(const wpi::Twine& name, double Kp, double Ki, double Kd,
double period, Subsystem& subsystem)
: Command(name, subsystem),
m_controller(Kp, Ki, Kd, *this, period),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(const wpi::Twine& name, double Kp, double Ki, double Kd,
std::function<double()> feedforward, double period,
Subsystem& subsystem)
: Command(name, subsystem),
m_controller(Kp, Ki, Kd, feedforward, *this, period),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd, Subsystem& subsystem)
: Command(subsystem),
m_controller(Kp, Ki, Kd, *this),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd, double period,
Subsystem& subsystem)
: Command(subsystem),
m_controller(Kp, Ki, Kd, *this, period),
m_runner(m_controller, *this) {}

PIDCommand::PIDCommand(double Kp, double Ki, double Kd,
std::function<double()> feedforward, double period,
Subsystem& subsystem)
: Command(subsystem),
m_controller(Kp, Ki, Kd, feedforward, *this, period),
m_runner(m_controller, *this) {}

void PIDCommand::InitSendable(SendableBuilder& builder) {
m_controller.InitSendable(builder);
Command::InitSendable(builder);
builder.SetSmartDashboardType("PIDCommand");
}

void PIDCommand::_Initialize() { m_runner.Enable(); }

void PIDCommand::_Interrupted() { _End(); }

void PIDCommand::_End() { m_runner.Disable(); }

void PIDCommand::SetReferenceRelative(double deltaReference) {
SetReference(GetReference() + deltaReference);
}

const PIDController& PIDCommand::GetPIDController() const {
return m_controller;
}

void PIDCommand::SetReference(double reference) {
m_controller.SetReference(reference);
}

double PIDCommand::GetReference() const { return m_controller.GetReference(); }
96 changes: 96 additions & 0 deletions wpilibc/src/main/native/cpp/experimental/commands/PIDSubsystem.cpp
@@ -0,0 +1,96 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/experimental/commands/PIDSubsystem.h"

using namespace frc::experimental;

PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double Kp, double Ki,
double Kd)
: Subsystem(name),
m_controller(Kp, Ki, Kd, *this),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double Kp, double Ki,
double Kd, std::function<double()> feedforward)
: Subsystem(name),
m_controller(Kp, Ki, Kd, feedforward, *this),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

PIDSubsystem::PIDSubsystem(const wpi::Twine& name, double Kp, double Ki,
double Kd, std::function<double()> feedforward,
double period)
: Subsystem(name),
m_controller(Kp, Ki, Kd, feedforward, *this, period),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

PIDSubsystem::PIDSubsystem(double Kp, double Ki, double Kd)
: Subsystem("PIDSubsystem"),
m_controller(Kp, Ki, Kd, *this),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

PIDSubsystem::PIDSubsystem(double Kp, double Ki, double Kd,
std::function<double()> feedforward)
: Subsystem("PIDSubsystem"),
m_controller(Kp, Ki, Kd, feedforward),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

PIDSubsystem::PIDSubsystem(double Kp, double Ki, double Kd,
std::function<double()> feedforward, double period)
: Subsystem("PIDSubsystem"),
m_controller(Kp, Ki, Kd, feedforward, period),
m_runner(m_controller, *this) {
AddChild("PIDController", m_controller);
}

void PIDSubsystem::Enable() { m_runner.Enable(); }

void PIDSubsystem::Disable() { m_runner.Disable(); }

void PIDSubsystem::SetReference(double reference) {
m_controller.SetReference(reference);
}

void PIDSubsystem::SetReferenceRelative(double deltaReference) {
SetReference(GetReference() + deltaReference);
}

void PIDSubsystem::SetInputRange(double minimumInput, double maximumInput) {
m_controller.SetInputRange(minimumInput, maximumInput);
}

void PIDSubsystem::SetOutputRange(double minimumOutput, double maximumOutput) {
m_controller.SetOutputRange(minimumOutput, maximumOutput);
}

double PIDSubsystem::GetReference() const {
return m_controller.GetReference();
}

void PIDSubsystem::SetAbsoluteTolerance(double tolerance,
double deltaTolerance) {
m_controller.SetAbsoluteTolerance(tolerance, deltaTolerance);
}

void PIDSubsystem::SetPercentTolerance(double tolerance,
double deltaTolerance) {
m_controller.SetPercentTolerance(tolerance, deltaTolerance);
}

bool PIDSubsystem::AtReference() const { return m_controller.AtReference(); }

PIDController& PIDSubsystem::GetPIDController() { return m_controller; }
14 changes: 14 additions & 0 deletions wpilibc/src/main/native/cpp/experimental/controller/Controller.cpp
@@ -0,0 +1,14 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/experimental/controller/Controller.h"

using namespace frc::experimental;

Controller::Controller(double period) : m_period(period) {}

double Controller::GetPeriod() const { return m_period; }