-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigs.java
More file actions
62 lines (54 loc) · 3.01 KB
/
Configs.java
File metadata and controls
62 lines (54 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package frc.robot;
import com.revrobotics.spark.config.SparkMaxConfig;
import com.revrobotics.spark.FeedbackSensor;
import com.revrobotics.spark.config.AbsoluteEncoderConfig;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import frc.robot.Constants.ModuleConstants;
public final class Configs {
public static final class MAXSwerveModule {
public static final SparkMaxConfig drivingConfig = new SparkMaxConfig();
public static final SparkMaxConfig turningConfig = new SparkMaxConfig();
static {
// Use module constants to calculate conversion factors and feed forward gain.
double drivingFactor = ModuleConstants.kWheelDiameterMeters * Math.PI
/ ModuleConstants.kDrivingMotorReduction;
double turningFactor = 2 * Math.PI;
double nominalVoltage = 12.0;
double drivingVelocityFeedForward = nominalVoltage / ModuleConstants.kDriveWheelFreeSpeedRps;
drivingConfig
.idleMode(IdleMode.kBrake)
.smartCurrentLimit(50);
drivingConfig.encoder
.positionConversionFactor(drivingFactor) // meters
.velocityConversionFactor(drivingFactor / 60.0); // meters per second
drivingConfig.closedLoop
.feedbackSensor(FeedbackSensor.kPrimaryEncoder)
// These are example gains you may need to them for your own robot!
.pid(0.04, 0, 0)
.outputRange(-1, 1)
.feedForward.kV(drivingVelocityFeedForward);
turningConfig
.idleMode(IdleMode.kBrake)
.smartCurrentLimit(20);
turningConfig.absoluteEncoder
// Invert the turning encoder, since the output shaft rotates in the opposite
// direction of the steering motor in the MAXSwerve Module.
.inverted(true)
.positionConversionFactor(turningFactor) // radians
.velocityConversionFactor(turningFactor / 60.0) // radians per second
// This applies to REV Through Bore Encoder V2 (use REV_ThroughBoreEncoder for V1):
.apply(AbsoluteEncoderConfig.Presets.REV_ThroughBoreEncoderV2);
turningConfig.closedLoop
.feedbackSensor(FeedbackSensor.kAbsoluteEncoder)
// These are example gains you may need to them for your own robot!
.pid(1, 0, 0)
.outputRange(-1, 1)
// Enable PID wrap around for the turning motor. This will allow the PID
// controller to go through 0 to get to the setpoint i.e. going from 350 degrees
// to 10 degrees will go through 0 rather than the other direction which is a
// longer route.
.positionWrappingEnabled(true)
.positionWrappingInputRange(0, turningFactor);
}
}
}