-
Notifications
You must be signed in to change notification settings - Fork 0
Ankle Subsystem #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
Open
recepsirin0
wants to merge
17
commits into
main
Choose a base branch
from
recep/ankle
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 all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1bdae46
Swerve All Code
recepsirin0 2b14208
Typo Correction
recepsirin0 89c578f
Added Ankle Subsystem - It includes basic level functions ( setAngle …
recepsirin0 d3b1295
Added PID Debugger
recepsirin0 2789628
PID Debugger has been improved.
recepsirin0 9d97695
The code file has been cleaned.
recepsirin0 ad0fc0a
todo's
recepsirin0 311a48a
Current Angle Trackment
recepsirin0 d523177
Fixed, where is encoder value set
recepsirin0 1d25a11
Fixed Conflicts. These will add on next update.
recepsirin0 8fdf9e1
Fixed conflicts.
recepsirin0 3f285cc
Merge branch 'main' into recep/ankle
recepsirin0 7a05b68
Reapply "Added Arm Subsystem"
recepsirin0 586f807
Fixed Angle Multiplier
recepsirin0 f651b5d
Added Arm Subsystem and fixed errors after reviews
recepsirin0 d0cd935
Merge branch 'recep/ankle' of https://github.com/KelRot/reefscape-cod…
recepsirin0 7c59202
-
recepsirin0 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| { | ||
| "drive": { | ||
| "p": 0.0020645, | ||
| "p": 0.04, | ||
| "i": 0, | ||
| "d": 0, | ||
| "f": 0, | ||
| "d": 0.000125, | ||
| "f": 0.01, | ||
| "iz": 0 | ||
| }, | ||
| "angle": { | ||
| "p": 0.0020645, | ||
| "p": 0, | ||
| "i": 0, | ||
| "d": 0, | ||
| "f": 0, | ||
| "iz": 0 | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "imu": { | ||
| "type": "pigeon2", | ||
| "id": 51, | ||
| "id": 31, | ||
| "canbus": "rio" | ||
| }, | ||
| "invertedIMU": false, | ||
|
|
||
This file contains hidden or 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 hidden or 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,22 @@ | ||
| package frc.robot; | ||
|
|
||
|
|
||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
|
||
| public class PIDDebugger { | ||
|
|
||
| public PIDDebugger() { | ||
|
|
||
| } | ||
|
|
||
| public void setSparkPIDControllerToDashboard(String prefix, double kP, double kI, double kD, double kMinOutput, | ||
| double kIz, double kMaxOutput) { | ||
| SmartDashboard.putNumber(prefix + "P", kP); | ||
| SmartDashboard.putNumber(prefix + "I", kI); | ||
| SmartDashboard.putNumber(prefix + "D", kD); | ||
| SmartDashboard.putNumber(prefix + "MinOutput", kMinOutput); | ||
| SmartDashboard.putNumber(prefix + "MaxOutput", kMaxOutput); | ||
| SmartDashboard.putNumber(prefix + "Iz", kIz); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
src/main/java/frc/robot/subsystems/AnkleSubsystem/AnkleConstants.java
This file contains hidden or 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,15 @@ | ||
| package frc.robot.subsystems.AnkleSubsystem; | ||
|
|
||
| public class AnkleConstants { | ||
| public final static int RedlineID = 1; | ||
| public final static int SparkID = 1; | ||
| public final static double maxAngle = 0/360; | ||
| public final static double minAngle = 0/360; | ||
| public static final double MaxOutput = 0; | ||
| public static final double MinOutput = 0; | ||
| public static double kP = 0.04; | ||
| public static double kI = 0; | ||
| public static double kD = 0; | ||
| public static double gearRatio = 4; | ||
|
|
||
| } |
111 changes: 111 additions & 0 deletions
111
src/main/java/frc/robot/subsystems/AnkleSubsystem/AnkleSubsystem.java
recepsirin0 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,111 @@ | ||
| package frc.robot.subsystems.AnkleSubsystem; | ||
recepsirin0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX; | ||
| import com.revrobotics.RelativeEncoder; | ||
| import com.revrobotics.spark.ClosedLoopSlot; | ||
| import com.revrobotics.spark.SparkBase.ControlType; | ||
| import com.revrobotics.spark.SparkBase.PersistMode; | ||
| import com.revrobotics.spark.SparkBase.ResetMode; | ||
| import com.revrobotics.spark.SparkClosedLoopController; | ||
| import com.revrobotics.spark.SparkMax; | ||
| import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor; | ||
| import com.revrobotics.spark.config.SparkMaxConfig; | ||
| import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
| import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
|
||
| public class AnkleSubsystem extends SubsystemBase { | ||
| private SparkMax m_motor; | ||
| private WPI_VictorSPX m_wheelMotor; | ||
| private SparkClosedLoopController closedLoopController; | ||
| private SparkMaxConfig motorConfig; | ||
| private RelativeEncoder encoder; | ||
| private double currentAngleSetpoint; | ||
| private double kP, kI, kD, kIz, kMaxOutput, kMinOutput; | ||
|
|
||
| public AnkleSubsystem() { | ||
| m_motor = new SparkMax(AnkleConstants.SparkID, MotorType.kBrushless); | ||
| m_wheelMotor = new WPI_VictorSPX(AnkleConstants.RedlineID); | ||
| encoder = m_motor.getEncoder(); | ||
| closedLoopController = m_motor.getClosedLoopController(); | ||
| motorConfig = new SparkMaxConfig(); | ||
| m_motor.configure(configCreator(motorConfig), ResetMode.kResetSafeParameters, PersistMode.kNoPersistParameters); | ||
| encoder.setPosition(0); | ||
| } | ||
|
|
||
| private void setAngle(double angle) { | ||
| if (isAngleInRange(angle)) { | ||
| currentAngleSetpoint = angle; | ||
| closedLoopController.setReference(angle * AnkleConstants.gearRatio, ControlType.kMAXMotionPositionControl, | ||
| ClosedLoopSlot.kSlot0); | ||
recepsirin0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| setDefault(); | ||
| } | ||
| } | ||
|
|
||
| private void setAngleTest() { | ||
| double angle = SmartDashboard.getNumber("testAngleAnkle", 0); | ||
| if (isAngleInRange(angle)) { | ||
| closedLoopController.setReference(angle * AnkleConstants.gearRatio, ControlType.kMAXMotionPositionControl, | ||
| ClosedLoopSlot.kSlot0); | ||
| } else { | ||
| setDefault(); | ||
| } | ||
| } | ||
|
|
||
| private void setDefault() { | ||
| closedLoopController.setReference(0, ControlType.kMAXMotionPositionControl, | ||
| ClosedLoopSlot.kSlot0); | ||
| currentAngleSetpoint = 0; | ||
| if (encoder.getPosition() == 0) { | ||
| stopAngleMotor(); | ||
| } | ||
| } | ||
|
|
||
| private boolean isAngleInRange(double angle) { | ||
| return angle <= AnkleConstants.maxAngle && angle >= AnkleConstants.minAngle; | ||
| } | ||
|
|
||
| private void stopAngleMotor() { | ||
| m_motor.set(0); | ||
| } | ||
|
|
||
| private void setWheelMotor(double velocity) { | ||
| m_wheelMotor.set(velocity); | ||
recepsirin0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public void periodic() { | ||
| SmartDashboard.putNumber("Current Angle (Ankle)", currentAngleSetpoint); | ||
| // This method will be called once per scheduler run | ||
| } | ||
|
|
||
| @Override | ||
| public void simulationPeriodic() { | ||
| // This method will be called once per scheduler run during simulation | ||
| } | ||
|
|
||
| private SparkMaxConfig configCreator(SparkMaxConfig motorConfig) { | ||
| String prefix = "ankle"; | ||
| double kP = SmartDashboard.getNumber(prefix + "P", AnkleConstants.kP); | ||
| double kI = SmartDashboard.getNumber(prefix + "I", AnkleConstants.kI); | ||
| double kD = SmartDashboard.getNumber(prefix + "D", AnkleConstants.kD); | ||
| double kMinOutput = SmartDashboard.getNumber(prefix + "MinOutput", AnkleConstants.MinOutput); | ||
| double kMaxOutput = SmartDashboard.getNumber(prefix + "MaxOutput", AnkleConstants.MaxOutput); | ||
| motorConfig.closedLoop | ||
| .feedbackSensor(FeedbackSensor.kPrimaryEncoder) | ||
| .p(kP) | ||
| .i(kI) | ||
| .d(kD) | ||
| .outputRange(kMinOutput, kMaxOutput); | ||
|
|
||
| motorConfig.closedLoop.maxMotion | ||
| .maxVelocity(1000) | ||
| .maxAcceleration(1000) | ||
| .allowedClosedLoopError(1); | ||
| motorConfig.smartCurrentLimit(50); | ||
|
|
||
| return motorConfig; | ||
| } | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
do we really need a class for this? how about we set up a smart dashboard handler class that has all the set/get methods regarding all subsystems
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.
could you more clarify? we didnt understand ( w/mychecksdead)