-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FRC5190/swerve-drivetrain
Swerve drivetrain
- Loading branch information
Showing
12 changed files
with
765 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Hardware | ||
|
||
This document details all of the hardware (motors, motor controllers, sensors, etc.) on the robot along with relevant information for programming. | ||
|
||
## Motors and Motor Controllers | ||
<!-- Change for 2024 --> | ||
(Key: F = Front, B = Back, R = Right, L = Left) | ||
| ID | Mechanism | Motor | Motor Controller | PDH Port | | ||
| --- | ------------------- | ---------- | ---------------- | -------- | | ||
| 1 | Drivetrain FL Drive | NEO | SPARK MAX | ? | | ||
| 2 | Drivetrain FL Steer | NEO | SPARK MAX | ? | | ||
| 3 | Drivetrain FR Drive | NEO | SPARK MAX | ? | | ||
| 4 | Drivetrain FR Steer | NEO | SPARK MAX | ? | | ||
| 5 | Drivetrain BL Drive | NEO | SPARK MAX | ? | | ||
| 6 | Drivetrain BL Steer | NEO | SPARK MAX | ? | | ||
| 7 | Drivetrain BR Drive | NEO | SPARK MAX | ? | | ||
| 8 | Drivetrain BR Steer | NEO | SPARK MAX | ? | | ||
|
||
|
||
|
||
## Sensors and Limelight | ||
| ID | Sensor | Type | PDH Port | | ||
| --- | ----------- | ---------- | -------- | | ||
| 11 | FL CANCoder | Absolute | ? | | ||
| 12 | FR CANCoder | Absolute | ? | | ||
| 13 | BL CANCoder | Absolute | ? | | ||
| 14 | BR CANCoder | Absolute | ? | |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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,92 @@ | ||
{ | ||
"keyboardJoysticks": [ | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 65, | ||
"incKey": 68 | ||
}, | ||
{ | ||
"decKey": 87, | ||
"incKey": 83 | ||
}, | ||
{ | ||
"decKey": 69, | ||
"decayRate": 0.0, | ||
"incKey": 82, | ||
"keyRate": 0.009999999776482582 | ||
} | ||
], | ||
"axisCount": 3, | ||
"buttonCount": 4, | ||
"buttonKeys": [ | ||
90, | ||
88, | ||
67, | ||
86 | ||
], | ||
"povConfig": [ | ||
{ | ||
"key0": 328, | ||
"key135": 323, | ||
"key180": 322, | ||
"key225": 321, | ||
"key270": 324, | ||
"key315": 327, | ||
"key45": 329, | ||
"key90": 326 | ||
} | ||
], | ||
"povCount": 1 | ||
}, | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 74, | ||
"incKey": 76 | ||
}, | ||
{ | ||
"decKey": 73, | ||
"incKey": 75 | ||
} | ||
], | ||
"axisCount": 2, | ||
"buttonCount": 4, | ||
"buttonKeys": [ | ||
77, | ||
44, | ||
46, | ||
47 | ||
], | ||
"povCount": 0 | ||
}, | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 263, | ||
"incKey": 262 | ||
}, | ||
{ | ||
"decKey": 265, | ||
"incKey": 264 | ||
} | ||
], | ||
"axisCount": 2, | ||
"buttonCount": 6, | ||
"buttonKeys": [ | ||
260, | ||
268, | ||
266, | ||
261, | ||
269, | ||
267 | ||
], | ||
"povCount": 0 | ||
}, | ||
{ | ||
"axisCount": 0, | ||
"buttonCount": 0, | ||
"povCount": 0 | ||
} | ||
] | ||
} |
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,17 @@ | ||
{ | ||
"NTProvider": { | ||
"types": { | ||
"/FMSInfo": "FMSInfo" | ||
} | ||
}, | ||
"NetworkTables": { | ||
"transitory": { | ||
"SmartDashboard": { | ||
"open": true | ||
} | ||
} | ||
}, | ||
"NetworkTables Info": { | ||
"visible": true | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/org/ghrobotics/frc2024/CANCoderSwerve.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,110 @@ | ||
package org.ghrobotics.frc2024; | ||
|
||
import com.ctre.phoenix6.StatusCode; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.CANcoderConfiguration; | ||
import com.ctre.phoenix6.configs.CANcoderConfigurator; | ||
import com.ctre.phoenix6.configs.MagnetSensorConfigs; | ||
import com.ctre.phoenix6.hardware.CANcoder; | ||
import com.ctre.phoenix6.signals.AbsoluteSensorRangeValue; | ||
import com.ctre.phoenix6.signals.SensorDirectionValue; | ||
|
||
/** | ||
* Swerve Absolute Encoder for CTRE CANCoders. | ||
*/ | ||
public class CANCoderSwerve { | ||
|
||
/** | ||
* CANCoder with WPILib sendable and support. | ||
*/ | ||
public CANcoder encoder; | ||
|
||
/** | ||
* Initialize the CANCoder on the standard CANBus. | ||
* | ||
* @param id CAN ID. | ||
*/ | ||
public CANCoderSwerve(int id) { | ||
// Empty string uses the default canbus for the system | ||
encoder = new CANcoder(id); | ||
} | ||
|
||
|
||
/** | ||
* Reset the encoder to factory defaults. | ||
*/ | ||
public void factoryDefault() { | ||
encoder.getConfigurator().apply(new CANcoderConfiguration()); | ||
} | ||
|
||
/** | ||
* Clear sticky faults on the encoder. | ||
*/ | ||
public void clearStickyFaults() { | ||
encoder.clearStickyFaults(); | ||
} | ||
|
||
/** | ||
* Configure the absolute encoder to read from [0, 360) per second. | ||
* | ||
* @param inverted Whether the encoder is inverted. | ||
*/ | ||
public void configure(boolean inverted) { | ||
CANcoderConfigurator cfg = encoder.getConfigurator(); | ||
MagnetSensorConfigs magnetSensorConfiguration = new MagnetSensorConfigs(); | ||
cfg.refresh(magnetSensorConfiguration); | ||
cfg.apply(magnetSensorConfiguration | ||
.withAbsoluteSensorRange(AbsoluteSensorRangeValue.Signed_PlusMinusHalf) | ||
.withSensorDirection(inverted ? SensorDirectionValue.Clockwise_Positive | ||
: SensorDirectionValue.CounterClockwise_Positive)); | ||
} | ||
|
||
/** | ||
* Get the absolute position of the encoder. Sets {@link SwerveAbsoluteEncoder#readingError} on erroneous readings. | ||
* | ||
* @return Absolute position in degrees from [0, 360). | ||
*/ | ||
|
||
public double getAbsolutePosition() { | ||
StatusSignal<Double> angle = encoder.getAbsolutePosition(); | ||
|
||
return angle.getValue() * 360; | ||
} | ||
|
||
/** | ||
* Get the instantiated absolute encoder Object. | ||
* | ||
* @return Absolute encoder object. | ||
*/ | ||
|
||
public Object getAbsoluteEncoder() { | ||
return encoder; | ||
} | ||
|
||
/** | ||
* Sets the Absolute Encoder Offset within the CANcoder's Memory. | ||
* | ||
* @param offset the offset the Absolute Encoder uses as the zero point in degrees. | ||
* @return if setting Absolute Encoder Offset was successful or not. | ||
*/ | ||
public boolean setAbsoluteEncoderOffset(double offset) { | ||
CANcoderConfigurator cfg = encoder.getConfigurator(); | ||
MagnetSensorConfigs magCfg = new MagnetSensorConfigs(); | ||
StatusCode error = cfg.refresh(magCfg); | ||
if (error != StatusCode.OK) | ||
{ | ||
return false; | ||
} | ||
error = cfg.apply(magCfg.withMagnetOffset(offset / 360)); | ||
return false; | ||
} | ||
|
||
/** | ||
* Get the velocity in degrees/sec. | ||
* | ||
* @return velocity in degrees/sec. | ||
*/ | ||
public double getVelocity() { | ||
return encoder.getVelocity().getValue() * 360; | ||
} | ||
} |
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.