-
Notifications
You must be signed in to change notification settings - Fork 1
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
Servo controller #85
Open
JYoung413
wants to merge
13
commits into
master
Choose a base branch
from
Servo-Controller
base: master
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
Servo controller #85
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5548b2d
Added ID function to flow operatiors
b0eacd1
Merge branch 'master' of https://github.com/FRC125/FRamework
3a736ac
??
ed36a47
Merge branch 'master' of https://github.com/FRC125/FRamework
86a343d
Merge branch 'master' of https://github.com/FRC125/FRamework
e13b529
Made RevServo controller events and functionality...
cd89660
Merge branch 'master' of https://github.com/FRC125/FRamework
9a7ad43
Merge branch 'master' into Servo-Controller
f554608
Merge branch 'master' of https://github.com/FRC125/FRamework
4bbdc7a
Merge branch 'master' into Servo-Controller
f184476
Fixed Changes
6984e87
Fixed Errors :C
1837abb
Fixed dumb style errors
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
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
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,44 @@ | ||
package com.nutrons.framework.controllers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JavaDoc |
||
|
||
import edu.wpi.first.wpilibj.Servo; | ||
|
||
/** | ||
* The RevServo controlle used for the programming and running of Rev Smart Servos. | ||
*/ | ||
public class RevServo extends ServoController { | ||
|
||
private final Servo servo; | ||
|
||
/** | ||
* Makes a RevServo object at the given port. | ||
* | ||
* @param port Port of RevServo | ||
*/ | ||
public RevServo(int port) { | ||
servo = new Servo(port); | ||
} | ||
|
||
@Override | ||
public void accept(ServoCommand servoCommand) { | ||
servoCommand.actOn(this); | ||
} | ||
|
||
/** | ||
* Sets the Servo to a given angle ranging from -90 to 90 left and right reflectively. | ||
* | ||
* @param angle given angle to turn to. | ||
*/ | ||
public void setAngle(double angle) { | ||
this.servo.setAngle(angle); | ||
} | ||
|
||
/** | ||
* Set the motor to a position given a value 0.0 is full left 1.0 is full right. | ||
* | ||
* @param value The value to turn the servo to. | ||
*/ | ||
public void set(double value) { | ||
this.servo.set(value); | ||
} | ||
|
||
} |
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,10 @@ | ||
package com.nutrons.framework.controllers; | ||
|
||
public interface ServoCommand { | ||
|
||
default void actOn(RevServo servo) { | ||
throw new EventUnimplementedException( | ||
servo.getClass().toString(), this.getClass().toString()); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/com/nutrons/framework/controllers/ServoController.java
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,17 @@ | ||
package com.nutrons.framework.controllers; | ||
|
||
import io.reactivex.functions.Consumer; | ||
|
||
public abstract class ServoController implements Consumer<ServoCommand> { | ||
|
||
@Override | ||
public abstract void accept(ServoCommand servoCommand); | ||
|
||
public void setAngle(double angle) { | ||
this.accept(ServoInstr.setAngle(angle)); | ||
} | ||
|
||
public void set(double value) { | ||
this.accept(ServoInstr.set(value)); | ||
} | ||
} |
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,13 @@ | ||
package com.nutrons.framework.controllers; | ||
|
||
public class ServoInstr { | ||
|
||
public static ServoCommand setAngle(double angle) { | ||
return new SetAngleCommand(angle); | ||
} | ||
|
||
public static ServoCommand set(double value) { | ||
return new SetCommand(value); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/com/nutrons/framework/controllers/SetAngleCommand.java
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,31 @@ | ||
package com.nutrons.framework.controllers; | ||
|
||
public class SetAngleCommand implements ServoCommand { | ||
|
||
private final double angle; | ||
|
||
/** | ||
* An event which sets the servo to turn to a certain angle. | ||
* | ||
* @param angle the angle to turn the servo to -90 (left) to 90 (right). | ||
*/ | ||
public SetAngleCommand(double angle) { | ||
this.angle = angle; | ||
} | ||
|
||
public double angle() { | ||
return this.angle; | ||
|
||
} | ||
|
||
@Override | ||
public void actOn(RevServo servo) { | ||
if (Math.abs(angle) > 90.0) { | ||
throw new IllegalArgumentException( | ||
"Angle greater than 90 degrees is not supported for Servos"); | ||
} | ||
servo.setAngle(angle); | ||
|
||
} | ||
|
||
} |
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,33 @@ | ||
package com.nutrons.framework.controllers; | ||
|
||
public class SetCommand implements ServoCommand { | ||
|
||
private final double value; | ||
|
||
/** | ||
* An event which sets the servo to turn to a certain angle. | ||
* | ||
* @param value the input value to give the servo -1 is full left 1 is full right. | ||
*/ | ||
public SetCommand(double value) { | ||
this.value = value; | ||
|
||
} | ||
|
||
public double value() { | ||
return this.value; | ||
|
||
} | ||
|
||
@Override | ||
public void actOn(RevServo servo) { | ||
if (Math.abs(value) > 1.0) { | ||
throw new IllegalArgumentException( | ||
"Value input greater than 1.0 is not supported for this servo"); | ||
|
||
} | ||
servo.set(value); | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.
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.
Make a new class called
ServoInstr