-
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
Tail subsystem and commands #3
Open
Onkornix
wants to merge
6
commits into
main
Choose a base branch
from
tail
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
6 commits
Select commit
Hold shift + click to select a range
f29fcef
created tail subsystem and crated tail motor object and init
mads841 a69616d
finished tail subsystem I believe
mads841 20d5748
testing git config
Onkornix 03c0beb
changed position conversion factor to a constant in tail subsystem
Onkornix 03bc419
Attempted tail up and tail down commands w/ PID
Onkornix 5ce4902
Implemented suggested changes
Onkornix 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
4 changes: 0 additions & 4 deletions
4
src/main/java/org/sert2521/bunnybots2024/commands/EmptyCommand.kt
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/org/sert2521/bunnybots2024/commands/TailRaiseAndLowerCommand.kt
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,46 @@ | ||
package org.sert2521.bunnybots2024.commands | ||
|
||
|
||
import edu.wpi.first.math.controller.PIDController | ||
import edu.wpi.first.wpilibj2.command.Command | ||
import org.sert2521.bunnybots2024.TunedConstants | ||
import org.sert2521.bunnybots2024.subsystems.TailSubsystem | ||
|
||
|
||
class TailRaiseAndLowerCommand(private val setPoint: Double) : Command() { | ||
private val tailSubsystem = TailSubsystem | ||
private val tailPid = PIDController( | ||
TunedConstants.TAIL_P, | ||
TunedConstants.TAIL_I, | ||
TunedConstants.TAIL_D | ||
) | ||
|
||
init { | ||
addRequirements(tailSubsystem) | ||
} | ||
|
||
override fun initialize() { | ||
tailPid.setpoint = setPoint | ||
|
||
if (setPoint > tailSubsystem.getAngleRads()) { | ||
tailSubsystem.setInversion(false) | ||
} | ||
else if (setPoint < tailSubsystem.getAngleRads()) { | ||
tailSubsystem.setInversion(true) | ||
} | ||
} | ||
|
||
override fun execute() { | ||
val nextVoltage = tailPid.calculate(tailSubsystem.getAngleRads()) | ||
tailSubsystem.setVoltage(nextVoltage) | ||
} | ||
|
||
override fun isFinished(): Boolean { | ||
return tailPid.atSetpoint() | ||
} | ||
|
||
override fun end(interrupted: Boolean) { | ||
// not stopping motor because TailStayStillCommand() should hold the motor in place | ||
// when the tail is not being raised or lowered. | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sert2521/bunnybots2024/commands/TailStayStillCommand.kt
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,29 @@ | ||
package org.sert2521.bunnybots2024.commands | ||
|
||
import edu.wpi.first.wpilibj2.command.Command | ||
import org.sert2521.bunnybots2024.subsystems.TailSubsystem | ||
|
||
class TailStayStillCommand : Command() { | ||
private val tailSubsystem = TailSubsystem | ||
|
||
|
||
init { | ||
addRequirements(tailSubsystem) | ||
} | ||
|
||
override fun initialize() { | ||
tailSubsystem.setVoltage(0.0) | ||
} | ||
|
||
override fun execute() {} | ||
|
||
override fun isFinished(): Boolean { | ||
return false | ||
} | ||
|
||
override fun end(interrupted: Boolean) { | ||
if (!interrupted) { // | ||
tailSubsystem.stopMotor() | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/sert2521/bunnybots2024/subsystems/TailSubsystem.kt
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,54 @@ | ||
package org.sert2521.bunnybots2024.subsystems | ||
|
||
import com.revrobotics.CANSparkBase | ||
import com.revrobotics.CANSparkLowLevel | ||
import com.revrobotics.CANSparkMax | ||
import edu.wpi.first.wpilibj2.command.Command | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.sert2521.bunnybots2024.ElectricIDs | ||
import org.sert2521.bunnybots2024.commands.TailStayStillCommand | ||
|
||
object TailSubsystem : SubsystemBase() { | ||
private val tailMotor = CANSparkMax(ElectricIDs.TAIL_ID, CANSparkLowLevel.MotorType.kBrushless) | ||
private val tailEncoder = tailMotor.encoder | ||
|
||
init { | ||
tailMotor.setSmartCurrentLimit(40) | ||
tailMotor.idleMode = CANSparkBase.IdleMode.kBrake | ||
|
||
tailEncoder.setPositionConversionFactor(Math.PI/24) | ||
|
||
// if inversion is false that means the tail was lowered when the motor was powered off | ||
if (!tailEncoder.inverted) { | ||
tailEncoder.setPosition(Math.PI/2) | ||
} | ||
|
||
} | ||
|
||
override fun setDefaultCommand(defaultCommand: Command?) { | ||
super.setDefaultCommand(TailStayStillCommand()) | ||
} | ||
|
||
fun setVoltage(voltage: Double) { | ||
tailMotor.setVoltage(voltage) | ||
} | ||
|
||
fun setInversion(inverted: Boolean) { | ||
tailMotor.inverted = inverted | ||
} | ||
|
||
fun stopMotor() { | ||
tailMotor.stopMotor() | ||
|
||
} | ||
|
||
fun getAngleRads(): Double { | ||
return tailEncoder.position | ||
} | ||
|
||
|
||
|
||
// fun getVelocity(): Double { | ||
// return tailEncoder.velocity | ||
// } | ||
} |
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.
Since we are using a relative encoder instead of an absolute encoder, we should probably have a function that resets the encoder to a certain value. Since we don't have a feedforward here the literal value isn't needed, so I would just set it to zero.