-
Notifications
You must be signed in to change notification settings - Fork 1
Merge pivot to develop (by dror) #2
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
orira22
wants to merge
3
commits into
develop
Choose a base branch
from
Pivot
base: develop
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package frc.robot.commands; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import frc.robot.subsystems.Pivot; | ||
|
|
||
| /* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ | ||
| public class PivotMoveToAngle extends Command { | ||
| private Pivot myPivot; | ||
| private double myAngle; | ||
|
|
||
| private PivotMoveToAngle(double myAngle) | ||
| { | ||
| this.myAngle = myAngle; | ||
| myPivot = Pivot.getInstance(); | ||
| addRequirements(myPivot); | ||
| } | ||
|
|
||
| // Called when the command is initially scheduled. | ||
| @Override | ||
| public void initialize() | ||
| { | ||
| myPivot.movePivotToAngle(myAngle); | ||
| } | ||
|
|
||
| // Called every time the scheduler runs while the command is scheduled. | ||
| @Override | ||
| public void execute() {} | ||
|
|
||
| // Called once the command ends or is interrupted. | ||
| @Override | ||
| public void end(boolean interrupted) | ||
| { | ||
| myPivot.stopMotor(); | ||
| } | ||
|
|
||
| // Returns true when the command should end. | ||
| @Override | ||
| public boolean isFinished() { | ||
| return myPivot.isAtAngle(myAngle); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/main/java/frc/robot/commands/PivotMoveWithJoystick.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,49 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package frc.robot.commands; | ||
|
|
||
| import java.util.function.DoubleSupplier; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import frc.robot.subsystems.Pivot; | ||
|
|
||
| /* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ | ||
| public class PivotMoveWithJoystick extends Command { | ||
| private Pivot myPivot; | ||
|
|
||
| private DoubleSupplier doubleSupplier; | ||
|
|
||
| private PivotMoveWithJoystick(DoubleSupplier myDoubleSupplier) | ||
| { | ||
| doubleSupplier = myDoubleSupplier; | ||
|
|
||
| myPivot = Pivot.getInstance(); | ||
| addRequirements(myPivot); | ||
| } | ||
|
|
||
| // Called when the command is initially scheduled. | ||
| @Override | ||
| public void initialize() {} | ||
|
|
||
| // Called every time the scheduler runs while the command is scheduled. | ||
| @Override | ||
| public void execute() | ||
| { | ||
| myPivot.setPower(doubleSupplier.getAsDouble()); | ||
| } | ||
|
|
||
| // Called once the command ends or is interrupted. | ||
| @Override | ||
| public void end(boolean interrupted) | ||
| { | ||
| myPivot.stopMotor(); | ||
| } | ||
|
|
||
| // Returns true when the command should end. | ||
| @Override | ||
| public boolean isFinished() { | ||
| return 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. | ||
|
|
||
| package frc.robot.subsystems; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import frc.robot.Constants; | ||
|
|
||
| import com.revrobotics.RelativeEncoder; | ||
| import com.revrobotics.spark.SparkLowLevel.MotorType; | ||
| import com.revrobotics.spark.SparkClosedLoopController; | ||
| import com.revrobotics.spark.SparkFlex; | ||
| import com.revrobotics.spark.SparkBase.ControlType; | ||
| import com.revrobotics.spark.SparkBase.PersistMode; | ||
| import com.revrobotics.spark.SparkBase.ResetMode; | ||
| import com.revrobotics.spark.ClosedLoopSlot; | ||
| import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor; | ||
| import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; | ||
| import com.revrobotics.spark.config.SparkFlexConfig; | ||
|
|
||
| public class Pivot extends SubsystemBase { | ||
| private SparkFlex motor; | ||
| private SparkFlexConfig motorConfig; | ||
| private SparkClosedLoopController closedLoopController; | ||
| private RelativeEncoder encoder; | ||
|
|
||
| private static Pivot instance = null; | ||
|
|
||
| private Pivot() | ||
| { | ||
| motor = new SparkFlex(Constants.pivotMotorID, MotorType.kBrushless); | ||
| closedLoopController = motor.getClosedLoopController(); | ||
| encoder = motor.getEncoder(); | ||
|
|
||
| motorConfig.encoder.positionConversionFactor(Constants.completeAngle); | ||
|
|
||
| motorConfig = new SparkFlexConfig(); | ||
|
|
||
| motorConfig.idleMode(IdleMode.kBrake); | ||
|
|
||
| motorConfig.closedLoop | ||
| .feedbackSensor(FeedbackSensor.kAlternateOrExternalEncoder) | ||
| .p(Constants.pivotP) | ||
| .i(Constants.pivotI) | ||
| .d(Constants.pivotD) | ||
| .outputRange(-1, 1); | ||
|
|
||
| motorConfig.closedLoop.maxMotion | ||
| .maxVelocity(Constants.pivotMaxVelocity) | ||
| .maxAcceleration(Constants.pivotMaxAccel) | ||
| .allowedClosedLoopError(1); | ||
|
|
||
| motor.configure(motorConfig, ResetMode.kResetSafeParameters, PersistMode.kNoPersistParameters); | ||
|
|
||
| encoder.setPosition(motor.getAbsoluteEncoder().getPosition()); | ||
| } | ||
|
|
||
| public static Pivot getInstance() | ||
| { | ||
| if (instance == null) | ||
| { | ||
| instance = new Pivot(); | ||
| } | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| /*** | ||
| * The function moves the pivot to the wanted angle | ||
| * | ||
| * @param angle - the angle to move the motor to | ||
| */ | ||
| public void movePivotToAngle(double angle) | ||
| { | ||
| closedLoopController.setReference(angle, ControlType.kMAXMotionPositionControl,ClosedLoopSlot.kSlot0); | ||
| } | ||
|
|
||
| public void setPower(double power) | ||
| { | ||
| motor.set(power); | ||
| } | ||
|
|
||
| public void stopMotor() | ||
| { | ||
| motor.stopMotor(); | ||
| } | ||
|
|
||
| /*** | ||
| * The function checks if the pivot has reached the wanted angle | ||
| * | ||
| * @param angle - The angle we want the motor to move to | ||
| * @return if the motor has reached the wanted angle | ||
| */ | ||
| public boolean isAtAngle(double angle) | ||
| { | ||
| return encoder.getPosition() <= angle + Constants.pivotTolerance && encoder.getPosition() >= angle - Constants.pivotTolerance; | ||
| } | ||
|
|
||
| @Override | ||
| public void periodic() { | ||
| // This method will be called once per scheduler run | ||
| } | ||
| } | ||
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,74 @@ | ||
| { | ||
| "fileName": "REVLib-2025.0.0.json", | ||
| "name": "REVLib", | ||
| "version": "2025.0.0", | ||
| "frcYear": "2025", | ||
| "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", | ||
| "mavenUrls": [ | ||
| "https://maven.revrobotics.com/" | ||
| ], | ||
| "jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2025.json", | ||
| "javaDependencies": [ | ||
| { | ||
| "groupId": "com.revrobotics.frc", | ||
| "artifactId": "REVLib-java", | ||
| "version": "2025.0.0" | ||
| } | ||
| ], | ||
| "jniDependencies": [ | ||
| { | ||
| "groupId": "com.revrobotics.frc", | ||
| "artifactId": "REVLib-driver", | ||
| "version": "2025.0.0", | ||
| "skipInvalidPlatforms": true, | ||
| "isJar": false, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "windowsx86", | ||
| "linuxarm64", | ||
| "linuxx86-64", | ||
| "linuxathena", | ||
| "linuxarm32", | ||
| "osxuniversal" | ||
| ] | ||
| } | ||
| ], | ||
| "cppDependencies": [ | ||
| { | ||
| "groupId": "com.revrobotics.frc", | ||
| "artifactId": "REVLib-cpp", | ||
| "version": "2025.0.0", | ||
| "libName": "REVLib", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": false, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "windowsx86", | ||
| "linuxarm64", | ||
| "linuxx86-64", | ||
| "linuxathena", | ||
| "linuxarm32", | ||
| "osxuniversal" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.revrobotics.frc", | ||
| "artifactId": "REVLib-driver", | ||
| "version": "2025.0.0", | ||
| "libName": "REVLibDriver", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": false, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "windowsx86", | ||
| "linuxarm64", | ||
| "linuxx86-64", | ||
| "linuxathena", | ||
| "linuxarm32", | ||
| "osxuniversal" | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.
Define closed loop values in constants file