From 2d76d0ff0523cc4dfa4e7129f273bbd7ddfcb0bd Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:27:56 -0700 Subject: [PATCH 01/14] Updated (really old) comment Still referenced pipes. Good times. --- commands/motor/MotorSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/motor/MotorSet.java b/commands/motor/MotorSet.java index 04f9b1b1..5078c7eb 100644 --- a/commands/motor/MotorSet.java +++ b/commands/motor/MotorSet.java @@ -40,7 +40,7 @@ protected void initialize() { */ public void set(double speed) { this.speed = speed; - LogKitten.d("MotorSet writePipe set to " + speed); + LogKitten.d("MotorSet set to " + speed); } @Override From af4dec60c9759192e4415b880becfc57814e588c Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:28:19 -0700 Subject: [PATCH 02/14] Added offset parameter to MotorControl --- commands/motor/MotorControl.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/commands/motor/MotorControl.java b/commands/motor/MotorControl.java index 7f5c1d67..a973d8fb 100644 --- a/commands/motor/MotorControl.java +++ b/commands/motor/MotorControl.java @@ -17,6 +17,7 @@ public class MotorControl extends Command { protected final Controller controller; protected final int axis; protected final double scale; + protected final double offset; /** * This Command directly controls a Motor based on an axis of the Controller. @@ -26,18 +27,35 @@ public class MotorControl extends Command { * @param controller * @param axis * @param scale + * @param offset + * A constant to add to the motor's speed + * Useful for using a controller for fine-tuning a constant speed */ - public MotorControl(Motor motor, Controller controller, int axis, double scale) { + public MotorControl(Motor motor, Controller controller, int axis, double scale, double offset) { super("MotorControl"); this.motor = motor; this.controller = controller; this.axis = axis; this.scale = scale; + this.offset = offset; requires(motor); setInterruptible(true); LogKitten.d("MotorControl created for " + motor.getName()); } + /** + * This Command directly controls a Motor based on an axis of the Controller. + * This can allow an Operator to easily control a single Motor from an axis of the Controller. + * + * @param motor + * @param controller + * @param axis + * @param scale + */ + public MotorControl(Motor motor, Controller controller, int axis, double scale) { + this(motor, controller, axis, 1.0, 0.0); + } + /** * This Command directly controls a Motor based on an axis of the Controller. * This can allow an Operator to easily control a single Motor from an axis of the Controller. @@ -62,7 +80,7 @@ protected void initialize() { @Override protected void execute() { LogKitten.d("MotorControl executing: " + controller.getAxis(axis)); - motor.set(controller.getAxis(axis) * scale); + motor.set(controller.getAxis(axis) * scale + offset); } @Override From 6fffef233844c0c7c3cb708315695e3d661e1edd Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:35:18 -0700 Subject: [PATCH 03/14] Added basic MotorSuppliedConstant --- commands/motor/MotorSuppliedConstant.java | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 commands/motor/MotorSuppliedConstant.java diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java new file mode 100644 index 00000000..db02bda2 --- /dev/null +++ b/commands/motor/MotorSuppliedConstant.java @@ -0,0 +1,52 @@ +package org.usfirst.frc4904.standard.commands.motor; + + +import java.util.function.Supplier; +import org.usfirst.frc4904.standard.LogKitten; +import org.usfirst.frc4904.standard.subsystems.motor.Motor; +import edu.wpi.first.wpilibj.command.Command; + +/** + * + */ +public class MotorSuppliedConstant extends Command { + protected final Motor motor; + protected final Supplier speedSupply; + protected final double scale; + protected final double offset; + protected double speed; + + public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale, double offset) { + super(name); + this.motor = motor; + requires(motor); + this.speedSupply = speedSupply; + this.scale = scale; + this.offset = offset; + LogKitten.d("MotorSuppliedConstant created for " + motor.getName()); + } + + @Override + protected void initialize() { + speed = speedSupply.get(); + motor.set(speed); + } + + @Override + protected void execute() { + motor.set(speed); + } + + @Override + protected boolean isFinished() { + return false; + } + + @Override + protected void end() {} + + @Override + protected void interrupted() { + LogKitten.d("MotorSuppliedConstant interrupted"); + } +} From 5c65e7923c206c82723c7ffc1a6dbffdbc379f26 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:39:35 -0700 Subject: [PATCH 04/14] Added some constructors for some motor commands --- commands/motor/MotorControl.java | 20 +++++++++++++++++--- commands/motor/MotorSet.java | 8 ++++++-- commands/motor/MotorSuppliedConstant.java | 9 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/commands/motor/MotorControl.java b/commands/motor/MotorControl.java index a973d8fb..48d4af35 100644 --- a/commands/motor/MotorControl.java +++ b/commands/motor/MotorControl.java @@ -23,6 +23,7 @@ public class MotorControl extends Command { * This Command directly controls a Motor based on an axis of the Controller. * This can allow an Operator to easily control a single Motor from an axis of the Controller. * + * @param name * @param motor * @param controller * @param axis @@ -31,8 +32,8 @@ public class MotorControl extends Command { * A constant to add to the motor's speed * Useful for using a controller for fine-tuning a constant speed */ - public MotorControl(Motor motor, Controller controller, int axis, double scale, double offset) { - super("MotorControl"); + public MotorControl(String name, Motor motor, Controller controller, int axis, double scale, double offset) { + super(name); this.motor = motor; this.controller = controller; this.axis = axis; @@ -43,6 +44,19 @@ public MotorControl(Motor motor, Controller controller, int axis, double scale, LogKitten.d("MotorControl created for " + motor.getName()); } + /** + * This Command directly controls a Motor based on an axis of the Controller. + * This can allow an Operator to easily control a single Motor from an axis of the Controller. + * + * @param name + * @param motor + * @param controller + * @param axis + */ + public MotorControl(String name, Motor motor, Controller controller, int axis) { + this(name, motor, controller, axis, 1.0, 0.0); + } + /** * This Command directly controls a Motor based on an axis of the Controller. * This can allow an Operator to easily control a single Motor from an axis of the Controller. @@ -53,7 +67,7 @@ public MotorControl(Motor motor, Controller controller, int axis, double scale, * @param scale */ public MotorControl(Motor motor, Controller controller, int axis, double scale) { - this(motor, controller, axis, 1.0, 0.0); + this("MotorControl", motor, controller, axis, 1.0, 0.0); } /** diff --git a/commands/motor/MotorSet.java b/commands/motor/MotorSet.java index 5078c7eb..dcbc42be 100644 --- a/commands/motor/MotorSet.java +++ b/commands/motor/MotorSet.java @@ -21,8 +21,8 @@ public class MotorSet extends Command { protected final SpeedController motor; protected double speed; - public MotorSet(Motor motor) { - super("MotorSet"); + public MotorSet(String name, Motor motor) { + super(name); this.motor = motor; speed = 0; LogKitten.d("MotorSet created for " + motor.getName()); @@ -30,6 +30,10 @@ public MotorSet(Motor motor) { setInterruptible(true); } + public MotorSet(Motor motor) { + this("MotorSet", motor); + } + @Override protected void initialize() { LogKitten.d("MotorSet initialized"); diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index db02bda2..c38b8c85 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -23,9 +23,18 @@ public MotorSuppliedConstant(String name, Motor motor, Supplier speedSup this.speedSupply = speedSupply; this.scale = scale; this.offset = offset; + setInterruptible(true); LogKitten.d("MotorSuppliedConstant created for " + motor.getName()); } + public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale) { + this(name, motor, speedSupply, scale, 0.0); + } + + public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { + this("MotorSuppliedConstant", motor, speedSupply, 1.0); + } + @Override protected void initialize() { speed = speedSupply.get(); From 737367fb4a0e085b391ba2171b23494339e7eaea Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:43:22 -0700 Subject: [PATCH 05/14] Added non-anonymous class for turning a joystick axis into a double supplier --- .../controllers/ControllerDoubleSupplier.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 custom/controllers/ControllerDoubleSupplier.java diff --git a/custom/controllers/ControllerDoubleSupplier.java b/custom/controllers/ControllerDoubleSupplier.java new file mode 100644 index 00000000..2636498b --- /dev/null +++ b/custom/controllers/ControllerDoubleSupplier.java @@ -0,0 +1,19 @@ +package org.usfirst.frc4904.standard.custom.controllers; + + +import java.util.function.Supplier; + +public class ControllerDoubleSupplier implements Supplier { + protected final Controller controller; + protected final int axis; + + public ControllerDoubleSupplier(Controller controller, int axis) { + this.controller = controller; + this.axis = axis; + } + + @Override + public Double get() { + return controller.getAxis(axis); + } +} From da41f56985a5229dcf2c1d107abb520382192050 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:51:01 -0700 Subject: [PATCH 06/14] Motor control using double suppliers now --- commands/motor/MotorControl.java | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/commands/motor/MotorControl.java b/commands/motor/MotorControl.java index 48d4af35..e4f8c011 100644 --- a/commands/motor/MotorControl.java +++ b/commands/motor/MotorControl.java @@ -1,8 +1,8 @@ package org.usfirst.frc4904.standard.commands.motor; +import java.util.function.Supplier; import org.usfirst.frc4904.standard.LogKitten; -import org.usfirst.frc4904.standard.custom.controllers.Controller; import org.usfirst.frc4904.standard.subsystems.motor.Motor; import org.usfirst.frc4904.standard.subsystems.motor.PositionSensorMotor; import edu.wpi.first.wpilibj.command.Command; @@ -14,13 +14,12 @@ */ public class MotorControl extends Command { protected final Motor motor; - protected final Controller controller; - protected final int axis; + protected final Supplier speedSupplier; protected final double scale; protected final double offset; /** - * This Command directly controls a Motor based on an axis of the Controller. + * This Command directly controls a Motor based on a double supplier; * This can allow an Operator to easily control a single Motor from an axis of the Controller. * * @param name @@ -32,11 +31,10 @@ public class MotorControl extends Command { * A constant to add to the motor's speed * Useful for using a controller for fine-tuning a constant speed */ - public MotorControl(String name, Motor motor, Controller controller, int axis, double scale, double offset) { + public MotorControl(String name, Motor motor, Supplier speedSupplier, double scale, double offset) { super(name); this.motor = motor; - this.controller = controller; - this.axis = axis; + this.speedSupplier = speedSupplier; this.scale = scale; this.offset = offset; requires(motor); @@ -53,8 +51,8 @@ public MotorControl(String name, Motor motor, Controller controller, int axis, d * @param controller * @param axis */ - public MotorControl(String name, Motor motor, Controller controller, int axis) { - this(name, motor, controller, axis, 1.0, 0.0); + public MotorControl(String name, Motor motor, Supplier speedSupplier) { + this(name, motor, speedSupplier, 1.0, 0.0); } /** @@ -66,8 +64,8 @@ public MotorControl(String name, Motor motor, Controller controller, int axis) { * @param axis * @param scale */ - public MotorControl(Motor motor, Controller controller, int axis, double scale) { - this("MotorControl", motor, controller, axis, 1.0, 0.0); + public MotorControl(Motor motor, Supplier speedSupplier, double scale) { + this("MotorControl", motor, speedSupplier, 1.0, 0.0); } /** @@ -79,8 +77,8 @@ public MotorControl(Motor motor, Controller controller, int axis, double scale) * @param axis * @param scale */ - public MotorControl(Motor motor, Controller controller, int axis) { - this(motor, controller, axis, 1.0); + public MotorControl(Motor motor, Supplier speedSupplier) { + this(motor, speedSupplier, 1.0); } @Override @@ -93,8 +91,8 @@ protected void initialize() { @Override protected void execute() { - LogKitten.d("MotorControl executing: " + controller.getAxis(axis)); - motor.set(controller.getAxis(axis) * scale + offset); + LogKitten.d("MotorControl executing: " + speedSupplier.get()); + motor.set(speedSupplier.get() * scale + offset); } @Override From bbc3223c53f7920961554ba51e719a624c56a55c Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 21 Apr 2017 12:54:47 -0700 Subject: [PATCH 07/14] Fixed logging error and possible error from calling get twice --- commands/motor/MotorControl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/motor/MotorControl.java b/commands/motor/MotorControl.java index e4f8c011..95d64d3a 100644 --- a/commands/motor/MotorControl.java +++ b/commands/motor/MotorControl.java @@ -91,8 +91,9 @@ protected void initialize() { @Override protected void execute() { - LogKitten.d("MotorControl executing: " + speedSupplier.get()); - motor.set(speedSupplier.get() * scale + offset); + double speed = speedSupplier.get() + offset; + LogKitten.d("MotorControl executing: " + speed); + motor.set(speed); } @Override From 951518c6ed4606aa8837db06ace1c890f134e959 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 28 Apr 2017 21:06:13 -0700 Subject: [PATCH 08/14] Updated javadocs --- commands/motor/MotorSet.java | 22 +++++++++----- commands/motor/MotorSuppliedConstant.java | 30 ++++++++++++++++++- .../controllers/ControllerDoubleSupplier.java | 10 +++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/commands/motor/MotorSet.java b/commands/motor/MotorSet.java index dcbc42be..dab5f84f 100644 --- a/commands/motor/MotorSet.java +++ b/commands/motor/MotorSet.java @@ -8,12 +8,9 @@ /** * Sets a motor to a speed. - * The speed can change through - * use of the set command. - * This is better than setting - * the motor because it uses - * requires to avoid having - * multiple attempts to set a + * The speed can change through use of the set command. + * This is better than setting the motor because it uses + * requires to avoid having multiple attempts to set a * motor simultaneously. * */ @@ -21,6 +18,12 @@ public class MotorSet extends Command { protected final SpeedController motor; protected double speed; + /** + * Command that wraps the set function of a motor. + * + * @param name + * @param motor + */ public MotorSet(String name, Motor motor) { super(name); this.motor = motor; @@ -30,6 +33,11 @@ public MotorSet(String name, Motor motor) { setInterruptible(true); } + /** + * Command that wraps the set function of a motor. + * + * @param motor + */ public MotorSet(Motor motor) { this("MotorSet", motor); } @@ -40,7 +48,7 @@ protected void initialize() { } /** - * Set the speed of the motor + * Set the speed of the motor in this class */ public void set(double speed) { this.speed = speed; diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index c38b8c85..fc86ab0d 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -7,7 +7,8 @@ import edu.wpi.first.wpilibj.command.Command; /** - * + * Set the speed of a motor based on a speed supplied on initialize. + * This should be used when the speed might change between construction time and when the motor should start. */ public class MotorSuppliedConstant extends Command { protected final Motor motor; @@ -16,6 +17,16 @@ public class MotorSuppliedConstant extends Command { protected final double offset; protected double speed; + /** + * Set the speed of a motor based on a speed supplied on initialize. + * This should be used when the speed might change between construction time and when the motor should start. + * + * @param name + * @param motor + * @param speedSupply + * @param scale + * @param offset + */ public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale, double offset) { super(name); this.motor = motor; @@ -27,10 +38,27 @@ public MotorSuppliedConstant(String name, Motor motor, Supplier speedSup LogKitten.d("MotorSuppliedConstant created for " + motor.getName()); } + /** + * Set the speed of a motor based on a speed supplied on initialize. + * This should be used when the speed might change between construction time and when the motor should start. + * + * @param name + * @param motor + * @param speedSupply + * @param scale + */ public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale) { this(name, motor, speedSupply, scale, 0.0); } + /** + * Set the speed of a motor based on a speed supplied on initialize. + * This should be used when the speed might change between construction time and when the motor should start. + * + * @param name + * @param motor + * @param speedSupply + */ public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { this("MotorSuppliedConstant", motor, speedSupply, 1.0); } diff --git a/custom/controllers/ControllerDoubleSupplier.java b/custom/controllers/ControllerDoubleSupplier.java index 2636498b..05d482b8 100644 --- a/custom/controllers/ControllerDoubleSupplier.java +++ b/custom/controllers/ControllerDoubleSupplier.java @@ -7,11 +7,21 @@ public class ControllerDoubleSupplier implements Supplier { protected final Controller controller; protected final int axis; + /** + * Wrapper for a controller that allows it to act as a double supplier + * for a specific axis. + * + * @param controller + * @param axis + */ public ControllerDoubleSupplier(Controller controller, int axis) { this.controller = controller; this.axis = axis; } + /** + * Returns a double for the value of the axis. + */ @Override public Double get() { return controller.getAxis(axis); From 36491c329370691c928013fe2329088f0d42601c Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 28 Apr 2017 21:06:21 -0700 Subject: [PATCH 09/14] Added scaling and offset --- commands/motor/MotorSuppliedConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index fc86ab0d..d205dab3 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -65,7 +65,7 @@ public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { @Override protected void initialize() { - speed = speedSupply.get(); + speed = speedSupply.get() * scale + offset; motor.set(speed); } From 84548609e2e991d89fa280e71950abdfa9799b66 Mon Sep 17 00:00:00 2001 From: billwpierce Date: Sat, 21 Oct 2017 20:59:28 -0700 Subject: [PATCH 10/14] Removed scale; refactored @params --- commands/motor/MotorControl.java | 51 +++++++++++--------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/commands/motor/MotorControl.java b/commands/motor/MotorControl.java index 95d64d3a..5d0458bf 100644 --- a/commands/motor/MotorControl.java +++ b/commands/motor/MotorControl.java @@ -15,27 +15,24 @@ public class MotorControl extends Command { protected final Motor motor; protected final Supplier speedSupplier; - protected final double scale; protected final double offset; /** - * This Command directly controls a Motor based on a double supplier; - * This can allow an Operator to easily control a single Motor from an axis of the Controller. + * This Command directly controls a Motor based on a double supplier; This + * can allow an Operator to easily control a single Motor from an axis of + * the Controller. * * @param name * @param motor - * @param controller - * @param axis - * @param scale + * @param speedSupplier * @param offset - * A constant to add to the motor's speed - * Useful for using a controller for fine-tuning a constant speed + * A constant to add to the motor's speed Useful for using a + * controller for fine-tuning a constant speed */ - public MotorControl(String name, Motor motor, Supplier speedSupplier, double scale, double offset) { + public MotorControl(String name, Motor motor, Supplier speedSupplier, double offset) { super(name); this.motor = motor; this.speedSupplier = speedSupplier; - this.scale = scale; this.offset = offset; requires(motor); setInterruptible(true); @@ -43,42 +40,28 @@ public MotorControl(String name, Motor motor, Supplier speedSupplier, do } /** - * This Command directly controls a Motor based on an axis of the Controller. - * This can allow an Operator to easily control a single Motor from an axis of the Controller. + * This Command directly controls a Motor based on an axis of the + * Controller. This can allow an Operator to easily control a single Motor + * from an axis of the Controller. * * @param name * @param motor - * @param controller - * @param axis + * @param speedSupplier */ public MotorControl(String name, Motor motor, Supplier speedSupplier) { - this(name, motor, speedSupplier, 1.0, 0.0); + this(name, motor, speedSupplier, 0.0); } /** - * This Command directly controls a Motor based on an axis of the Controller. - * This can allow an Operator to easily control a single Motor from an axis of the Controller. + * This Command directly controls a Motor based on an axis of the + * Controller. This can allow an Operator to easily control a single Motor + * from an axis of the Controller. * * @param motor - * @param controller - * @param axis - * @param scale - */ - public MotorControl(Motor motor, Supplier speedSupplier, double scale) { - this("MotorControl", motor, speedSupplier, 1.0, 0.0); - } - - /** - * This Command directly controls a Motor based on an axis of the Controller. - * This can allow an Operator to easily control a single Motor from an axis of the Controller. - * - * @param motor - * @param controller - * @param axis - * @param scale + * @param speedSupplier */ public MotorControl(Motor motor, Supplier speedSupplier) { - this(motor, speedSupplier, 1.0); + this("MotorControl", motor, speedSupplier, 0.0); } @Override From d70a3526ffabd030c679bacd8b9bef8309b52655 Mon Sep 17 00:00:00 2001 From: billwpierce Date: Sat, 21 Oct 2017 21:15:39 -0700 Subject: [PATCH 11/14] Added scale directly into ControllerDoubleSupplier to reduce repetition --- .../controllers/ControllerDoubleSupplier.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/custom/controllers/ControllerDoubleSupplier.java b/custom/controllers/ControllerDoubleSupplier.java index 05d482b8..21030885 100644 --- a/custom/controllers/ControllerDoubleSupplier.java +++ b/custom/controllers/ControllerDoubleSupplier.java @@ -1,22 +1,35 @@ package org.usfirst.frc4904.standard.custom.controllers; - import java.util.function.Supplier; public class ControllerDoubleSupplier implements Supplier { protected final Controller controller; protected final int axis; + protected final double scale; /** - * Wrapper for a controller that allows it to act as a double supplier - * for a specific axis. + * Wrapper for a controller that allows it to act as a double supplier for a + * specific axis set to a certain scale. * * @param controller * @param axis + * @param scale */ - public ControllerDoubleSupplier(Controller controller, int axis) { + public ControllerDoubleSupplier(Controller controller, int axis, double scale) { this.controller = controller; this.axis = axis; + this.scale = scale; + } + + /** + * Wrapper for a controller that allows it to act as a double supplier for a + * specific axis. Scale assumed as 1. + * + * @param controller + * @param axis + */ + public ControllerDoubleSupplier(Controller controller, int axis) { + this(controller, axis, 1.0); } /** @@ -24,6 +37,6 @@ public ControllerDoubleSupplier(Controller controller, int axis) { */ @Override public Double get() { - return controller.getAxis(axis); + return controller.getAxis(axis) * scale; } } From f73982219ce7a92807a9137cd3513559e76ded8a Mon Sep 17 00:00:00 2001 From: billwpierce Date: Sat, 21 Oct 2017 21:17:05 -0700 Subject: [PATCH 12/14] Removed unnecesary scale --- commands/motor/MotorSuppliedConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index d205dab3..2132b4c8 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -65,7 +65,7 @@ public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { @Override protected void initialize() { - speed = speedSupply.get() * scale + offset; + speed = speedSupply.get() + offset; motor.set(speed); } From b023f4eadfd85dbc8e09a650fdf767facda16567 Mon Sep 17 00:00:00 2001 From: billwpierce Date: Sat, 21 Oct 2017 21:25:06 -0700 Subject: [PATCH 13/14] readded scale to motorsuppliedconstant --- commands/motor/MotorSuppliedConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index 2132b4c8..d205dab3 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -65,7 +65,7 @@ public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { @Override protected void initialize() { - speed = speedSupply.get() + offset; + speed = speedSupply.get() * scale + offset; motor.set(speed); } From b414db260d926cf324257614a6586149137066b6 Mon Sep 17 00:00:00 2001 From: billwpierce Date: Sat, 21 Oct 2017 21:32:40 -0700 Subject: [PATCH 14/14] moved scaling and offset into the supplier itself --- commands/motor/MotorSuppliedConstant.java | 25 +++---------------- .../controllers/ControllerDoubleSupplier.java | 23 ++++++++++++++--- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/commands/motor/MotorSuppliedConstant.java b/commands/motor/MotorSuppliedConstant.java index d205dab3..43dce65e 100644 --- a/commands/motor/MotorSuppliedConstant.java +++ b/commands/motor/MotorSuppliedConstant.java @@ -13,8 +13,6 @@ public class MotorSuppliedConstant extends Command { protected final Motor motor; protected final Supplier speedSupply; - protected final double scale; - protected final double offset; protected double speed; /** @@ -24,33 +22,16 @@ public class MotorSuppliedConstant extends Command { * @param name * @param motor * @param speedSupply - * @param scale - * @param offset */ - public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale, double offset) { + public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply) { super(name); this.motor = motor; requires(motor); this.speedSupply = speedSupply; - this.scale = scale; - this.offset = offset; setInterruptible(true); LogKitten.d("MotorSuppliedConstant created for " + motor.getName()); } - /** - * Set the speed of a motor based on a speed supplied on initialize. - * This should be used when the speed might change between construction time and when the motor should start. - * - * @param name - * @param motor - * @param speedSupply - * @param scale - */ - public MotorSuppliedConstant(String name, Motor motor, Supplier speedSupply, double scale) { - this(name, motor, speedSupply, scale, 0.0); - } - /** * Set the speed of a motor based on a speed supplied on initialize. * This should be used when the speed might change between construction time and when the motor should start. @@ -60,12 +41,12 @@ public MotorSuppliedConstant(String name, Motor motor, Supplier speedSup * @param speedSupply */ public MotorSuppliedConstant(Motor motor, Supplier speedSupply) { - this("MotorSuppliedConstant", motor, speedSupply, 1.0); + this("MotorSuppliedConstant", motor, speedSupply); } @Override protected void initialize() { - speed = speedSupply.get() * scale + offset; + speed = speedSupply.get(); motor.set(speed); } diff --git a/custom/controllers/ControllerDoubleSupplier.java b/custom/controllers/ControllerDoubleSupplier.java index 21030885..7bdbc714 100644 --- a/custom/controllers/ControllerDoubleSupplier.java +++ b/custom/controllers/ControllerDoubleSupplier.java @@ -1,11 +1,13 @@ package org.usfirst.frc4904.standard.custom.controllers; + import java.util.function.Supplier; public class ControllerDoubleSupplier implements Supplier { protected final Controller controller; protected final int axis; protected final double scale; + protected final double offset; /** * Wrapper for a controller that allows it to act as a double supplier for a @@ -15,21 +17,34 @@ public class ControllerDoubleSupplier implements Supplier { * @param axis * @param scale */ - public ControllerDoubleSupplier(Controller controller, int axis, double scale) { + public ControllerDoubleSupplier(Controller controller, int axis, double scale, double offset) { this.controller = controller; this.axis = axis; this.scale = scale; + this.offset = offset; + } + + /** + * Wrapper for a controller that allows it to act as a double supplier for a + * specific axis. Offset assumed as 0. + * + * @param controller + * @param axis + * @param scale + */ + public ControllerDoubleSupplier(Controller controller, int axis, double scale) { + this(controller, axis, scale, 0.0); } /** * Wrapper for a controller that allows it to act as a double supplier for a - * specific axis. Scale assumed as 1. + * specific axis. Scale assumed as 1, offset as 0. * * @param controller * @param axis */ public ControllerDoubleSupplier(Controller controller, int axis) { - this(controller, axis, 1.0); + this(controller, axis, 1.0, 0.0); } /** @@ -37,6 +52,6 @@ public ControllerDoubleSupplier(Controller controller, int axis) { */ @Override public Double get() { - return controller.getAxis(axis) * scale; + return controller.getAxis(axis) * scale + offset; } }