-
Notifications
You must be signed in to change notification settings - Fork 0
init commit #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
base: main
Are you sure you want to change the base?
init commit #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // 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 com.ctre.phoenix.sensors.AbsoluteSensorRange; | ||
| import com.ctre.phoenix.sensors.CANCoder; | ||
| import com.revrobotics.CANSparkMax; | ||
| import com.revrobotics.CANSparkMax.ControlType; | ||
| import com.revrobotics.CANSparkMaxLowLevel.MotorType; | ||
|
|
||
|
|
||
| /** Add your docs here. */ | ||
| public class SwerveModule { | ||
| CANSparkMax drivemotor; | ||
| CANSparkMax swervemotor; | ||
| public CANCoder steerencoder; | ||
|
|
||
| final double steerReduction = (14.0 / 50.0) * (27.0 / 17.0) * (15.0 / 45.0); | ||
| public SwerveModule(int dmotorid, int smoterid, double encoderoffset){ | ||
| drivemotor = new CANSparkMax(dmotorid, MotorType.kBrushless); | ||
| swervemotor = new CANSparkMax(smoterid, MotorType.kBrushless); | ||
| swervemotor.getEncoder().setPositionConversionFactor(2*Math.PI*steerReduction); | ||
| swervemotor.getPIDController().setP(1.0); | ||
| swervemotor.getPIDController().setD(0.1); | ||
| swervemotor.getPIDController().setI(0); | ||
| swervemotor.getEncoder().setPosition(0); | ||
| // setup swerve module encoder | ||
| steerencoder = new CANCoder(15); | ||
| steerencoder.configMagnetOffset(encoderoffset); | ||
| steerencoder.configAbsoluteSensorRange(AbsoluteSensorRange.Unsigned_0_to_360); | ||
| } | ||
|
|
||
| public void resetSteerPosition() { | ||
|
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. R should be capital |
||
| swervemotor.getEncoder().setPosition(Math.toRadians(steerencoder.getAbsolutePosition())); | ||
| } | ||
|
|
||
| public void move(double setSwerveMotorPosition, double drivemotorspeed){ | ||
|
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. M should be captial |
||
| resetSteerPosition(); | ||
| swervemotor.set(setSwerveMotorPosition); | ||
| drivemotor.set(drivemotorspeed); | ||
| } | ||
|
|
||
| public void SetToZero(){ | ||
| swervemotor.getEncoder().setPosition(0); | ||
| } | ||
|
|
||
| public void rotateto(double rotation){ | ||
|
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. camelCase should be used. |
||
| swervemotor.getPIDController().setReference(Math.toRadians(rotation), ControlType.kPosition); | ||
| } | ||
| } | ||
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.
Might want to configure statusFramePeriod and add timeouts. Sensor direction may also be a setting you want to configure.