-
Notifications
You must be signed in to change notification settings - Fork 0
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
Amp trap goto action #73
Open
themehdev
wants to merge
8
commits into
main
Choose a base branch
from
AmpTrapGotoAction
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
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9ea612
created action
themehdev 742f317
updated, realized that something was wrong cuz i wasnt using the subs…
themehdev 94c986b
updated to support params value settings as well
themehdev 2665dc1
created the no-go-zones for the wrist in the params, and the elevator…
themehdev 7769c7c
got arid of the wrist
themehdev d624f8d
Made so the goto action cant move through the no-go-zone
themehdev da608a0
Updated to meet butch's requirements, and made it faster supposedly
themehdev 9955523
hopefully that fixes the problem
themehdev 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
125 changes: 125 additions & 0 deletions
125
src/main/java/frc/robot/subsystems/amp_trap/AmpTrapGotoAction.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,125 @@ | ||
package frc.robot.subsystems.amp_trap; | ||
|
||
import org.xero1425.base.actions.Action; | ||
import org.xero1425.base.subsystems.motorsubsystem.MCMotionMagicAction; | ||
|
||
|
||
|
||
public class AmpTrapGotoAction extends Action { | ||
private MCMotionMagicAction elevatorThreshAction; | ||
private MCMotionMagicAction elevatorGotoAction; | ||
private MCMotionMagicAction armAction; | ||
private AmpTrapSubsystem subsystem; | ||
private double elevatorThreshold; | ||
private double armNoGoZoneLower; | ||
private double armNoGoZoneUpper; | ||
private double armTarget; | ||
private double elevatorTarget; | ||
private enum State { | ||
Goto, | ||
ThreshGoto, | ||
ArmGoto, | ||
Thresh | ||
}; | ||
|
||
private State state; | ||
|
||
public AmpTrapGotoAction(AmpTrapSubsystem subsystem, String elevatorTarget, String armTarget) throws Exception{ | ||
this(subsystem, subsystem.getSettingsValue(elevatorTarget).getDouble(), subsystem.getSettingsValue(armTarget).getDouble()); | ||
} | ||
public AmpTrapGotoAction(AmpTrapSubsystem subsystem, double elevatorTarget, double armTarget) throws Exception{ | ||
super(subsystem.getRobot().getMessageLogger()); | ||
this.subsystem = subsystem; | ||
|
||
// Get the elevator threshold and the no-go zone limits for the arm from the params file | ||
this.elevatorThreshold = subsystem.getElevator().getSettingsValue("threshold").getDouble(); | ||
this.armNoGoZoneLower = subsystem.getArm().getSettingsValue("no-go-zone:lower").getDouble(); | ||
this.armNoGoZoneUpper = subsystem.getArm().getSettingsValue("no-go-zone:upper").getDouble(); | ||
|
||
this.armTarget = armTarget; | ||
this.elevatorTarget = elevatorTarget; | ||
|
||
this.elevatorThreshAction = new MCMotionMagicAction(subsystem.getElevator(), "ElevatorThresh", elevatorThreshold, 0.01, 0.02); | ||
this.elevatorGotoAction = new MCMotionMagicAction(subsystem.getArm(), "ElevatorThresh", elevatorTarget, 0.01, 0.02); | ||
|
||
// Create the MCMotionMagicAction for the arm motor | ||
this.armAction = new MCMotionMagicAction(subsystem.getArm(), "ArmGoto", armTarget, 3, 10); | ||
|
||
state = State.Thresh; | ||
} | ||
|
||
@Override | ||
public void start() throws Exception{ | ||
super.start(); | ||
subsystem.getElevator().setAction(elevatorGotoAction); | ||
subsystem.getElevator().setAction(elevatorThreshAction); | ||
subsystem.getArm().setAction(armAction); | ||
|
||
// Start the MCMotionMagicActions | ||
// If arm target isn't in no-go-zone | ||
// and the arm target and arm actual aren't on opposite sides | ||
// then they can be run in paralell | ||
if(((armTarget < armNoGoZoneLower || armTarget > armNoGoZoneUpper) && (!(armTarget > armNoGoZoneUpper && subsystem.getArm().getPosition() < armNoGoZoneLower) || !(armTarget < armNoGoZoneLower && subsystem.getArm().getPosition() > armNoGoZoneUpper)))){ | ||
subsystem.getArm().setAction(armAction); | ||
subsystem.getElevator().setAction(elevatorGotoAction); | ||
state = State.Goto; | ||
}else if (elevatorTarget > elevatorThreshold){ | ||
// Otherwise, start the | ||
subsystem.getElevator().setAction(elevatorGotoAction); | ||
state = State.ThreshGoto; | ||
}else{ | ||
subsystem.getElevator().setAction(elevatorThreshAction); | ||
state = State.Thresh; | ||
} | ||
} | ||
|
||
@Override | ||
public void run() throws Exception{ | ||
super.run(); | ||
// Update the MCMotionMagicActions | ||
if(state == State.Goto || state == State.ThreshGoto){ | ||
elevatorGotoAction.run(); | ||
} | ||
if(state == State.Goto || state == State.ArmGoto){ | ||
armAction.run(); | ||
} | ||
if(state == State.Thresh){ | ||
elevatorThreshAction.run(); | ||
} | ||
|
||
if(state == State.ThreshGoto && subsystem.getElevator().getPosition() > elevatorThreshold){ | ||
subsystem.getArm().setAction(armAction); | ||
state = State.Goto; | ||
} | ||
// If the elevator has moved up past the elevator threshold, move the arm to its target position | ||
if (elevatorThreshAction.isDone() && state == State.Thresh){ | ||
subsystem.getArm().setAction(armAction); | ||
state = State.ArmGoto; | ||
} | ||
|
||
if(armAction.isDone()){ | ||
if(elevatorGotoAction.isDone() && state == State.Goto){ | ||
setDone(); | ||
return; | ||
} | ||
if(state == State.ArmGoto){ | ||
subsystem.getElevator().setAction(elevatorGotoAction); | ||
state = State.Goto; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
super.cancel(); | ||
// Cancel the MCMotionMagicActions | ||
elevatorGotoAction.cancel(); | ||
elevatorThreshAction.cancel(); | ||
armAction.cancel(); | ||
} | ||
|
||
@Override | ||
public String toString(int indent) { | ||
return prefix(indent) + "AmpTrapGotoAction"; | ||
} | ||
} |
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.
The armTarget cannot be in the no go zone, so the first part of this conditional will always be true and can be removed.
Also, I believe the conditions (ignoring the first part) is ...
if !crossesMaxToMin || !crossesMinToMax which is probably not what you want.
given the actions, you probably want this to be && because you want to go directly to the targets if you are not crossing.
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.
Why not? if the elevator target is always above the threshold when we move the arm to the no-go-zone, we can have the arm be wherever we want.
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.
That was to the first q, the second q, you are right.