-
Notifications
You must be signed in to change notification settings - Fork 3
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
More Motor Commands #203
Open
carturn
wants to merge
15
commits into
main
Choose a base branch
from
motor-offset-commands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
More Motor Commands #203
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2d76d0f
Updated (really old) comment
carturn af4dec6
Added offset parameter to MotorControl
carturn 6fffef2
Added basic MotorSuppliedConstant
carturn 5c65e79
Added some constructors for some motor commands
carturn 737367f
Added non-anonymous class for turning a joystick axis into a double s…
carturn da41f56
Motor control using double suppliers now
carturn bbc3223
Fixed logging error and possible error from calling get twice
carturn 951518c
Updated javadocs
carturn 36491c3
Added scaling and offset
carturn 6039c0a
Merge branch 'master' into motor-offset-commands
oldgalileo 8454860
Removed scale; refactored @params
billwpierce d70a352
Added scale directly into ControllerDoubleSupplier to reduce repetition
billwpierce f739822
Removed unnecesary scale
billwpierce b023f4e
readded scale to
billwpierce b414db2
moved scaling and offset into the supplier itself
billwpierce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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; | ||
|
||
/** | ||
* 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; | ||
protected final Supplier<Double> speedSupply; | ||
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 | ||
*/ | ||
public MotorSuppliedConstant(String name, Motor motor, Supplier<Double> speedSupply) { | ||
super(name); | ||
this.motor = motor; | ||
requires(motor); | ||
this.speedSupply = speedSupply; | ||
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 | ||
*/ | ||
public MotorSuppliedConstant(Motor motor, Supplier<Double> speedSupply) { | ||
this("MotorSuppliedConstant", motor, speedSupply); | ||
} | ||
|
||
@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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.usfirst.frc4904.standard.custom.controllers; | ||
|
||
|
||
import java.util.function.Supplier; | ||
|
||
public class ControllerDoubleSupplier implements Supplier<Double> { | ||
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 | ||
* specific axis set to a certain scale. | ||
* | ||
* @param controller | ||
* @param axis | ||
* @param 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, offset as 0. | ||
* | ||
* @param controller | ||
* @param axis | ||
*/ | ||
public ControllerDoubleSupplier(Controller controller, int axis) { | ||
this(controller, axis, 1.0, 0.0); | ||
} | ||
|
||
/** | ||
* Returns a double for the value of the axis. | ||
*/ | ||
@Override | ||
public Double get() { | ||
return controller.getAxis(axis) * scale + offset; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool, however, we may run into compatibility problems with older versions. 10/10 would recommend for 2018-code, and maybe for 2017 if we take the time to do some refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compatibility is something we rarely consider as we are not supporting a huge number of people on historical versions. If older software relies on something, a branch can be created to support it, or the older software can adapt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok my B.