-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstants.py
More file actions
253 lines (190 loc) · 6.79 KB
/
constants.py
File metadata and controls
253 lines (190 loc) · 6.79 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# 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.
"""
The constants module is a convenience place for teams to hold robot-wide
numerical or boolean constants. Don't use this for any other purpose!
"""
import math
from wpimath import units
from wpimath.geometry import Translation2d
from wpimath.kinematics import SwerveDrive4Kinematics
from wpimath.trajectory import TrapezoidProfileRadians
# from rev import CANSparkMax
from rev import SparkMax, SparkBaseConfig
class NeoMotorConstants:
kFreeSpeedRpm = 5676
class DriveConstants:
# Driving Parameters - Note that these are not the maximum capable speeds of
# the robot, rather the allowed maximum speeds
kMaxSpeedMetersPerSecond = 15
# kMaxAngularSpeed = math.tau # radians per second
kMaxAngularSpeed = 20
kDirectionSlewRate = 1.2 # radians per second
kMagnitudeSlewRate = 1.8 # percent per second (1 = 100%)
kRotationalSlewRate = 2.0 # percent per second (1 = 100%)
# Chassis configuration
kTrackWidth = units.inchesToMeters(26.5)
# Distance between centers of right and left wheels on robot
kWheelBase = units.inchesToMeters(26.5)
# Distance between front and back wheels on robot
kModulePositions = [
Translation2d(kWheelBase / 2, kTrackWidth / 2),
Translation2d(kWheelBase / 2, -kTrackWidth / 2),
Translation2d(-kWheelBase / 2, kTrackWidth / 2),
Translation2d(-kWheelBase / 2, -kTrackWidth / 2),
]
kDriveKinematics = SwerveDrive4Kinematics(*kModulePositions)
# Offsets of the modules from the robot
kFrontLeftChassisAngularOffset = math.radians(-0.764892578125 * (360))
kFrontRightChassisAngularOffset = math.radians(0.75 * (360))
kBackLeftChassisAngularOffset = math.radians(0.079833984375 * (360))
kBackRightChassisAngularOffset = math.radians(0.367919921875 * (360))
# SPARK MAX CAN IDs
kFrontLeftDrivingCanId = 6
kRearLeftDrivingCanId = 21
kFrontRightDrivingCanId = 11
kRearRightDrivingCanId = 3
kFrontLeftTurningCanId = 22
kRearLeftTurningCanId = 14
kFrontRightTurningCanId = 13
kRearRightTurningCanId = 12
# Kraken IDs
kFrontLeftDrivingId = 5
kRearLeftDrivingId = 7
kFrontRightDrivingId = 4
kRearRightDrivingId = 1
kFrontLeftTurningId = 6
kRearLeftTurningId = 8
kFrontRightTurningId = 3
kRearRightTurningId = 2
kFrontLeftCANCoderId = 3
kRearLeftCANCoderId = 4
kFrontRightCANCoderId = 2
kRearRightCANCoderId = 1
kGyroReversed = True
class ModuleConstants:
# The MAXSwerve module can be configured with one of three pinion gears: 12T, 13T, or 14T.
# This changes the drive speed of the module (a pinion gear with more teeth will result in a
# robot that drives faster).
kDrivingMotorPinionTeeth = 14
# Invert the turning encoder, since the output shaft rotates in the opposite direction of
# the steering motor in the MAXSwerve Module.
kTurningEncoderInverted = True
# Calculations required for driving motor conversion factors and feed forward
kDrivingMotorFreeSpeedRps = NeoMotorConstants.kFreeSpeedRpm / 60
kWheelDiameterMeters = 0.0762
kWheelCircumferenceMeters = kWheelDiameterMeters * math.pi
# 45 teeth on the wheel's bevel gear, 22 teeth on the first-stage spur gear, 15 teeth on the bevel pinion
kDrivingMotorReduction = (45.0 * 22) / (kDrivingMotorPinionTeeth * 15)
kDriveWheelFreeSpeedRps = (
kDrivingMotorFreeSpeedRps * kWheelCircumferenceMeters
) / kDrivingMotorReduction
kDrivingEncoderPositionFactor = (
kWheelDiameterMeters * math.pi
) / kDrivingMotorReduction # meters
kDrivingEncoderVelocityFactor = (
(kWheelDiameterMeters * math.pi) / kDrivingMotorReduction
) / 60.0 # meters per second
kTurningEncoderPositionFactor = math.tau # radian
kTurningEncoderVelocityFactor = math.tau / 60.0 # radians per second
kTurningEncoderPositionPIDMinInput = 0 # radian
kTurningEncoderPositionPIDMaxInput = kTurningEncoderPositionFactor # radian
# kDriveRatio = 7.363636
# kDriveRatio = 8.6631011765
kDriveRatio = 17.326202353
kDrivingP = 0.8
kDrivingI = 0
kDrivingD = 0
kDrivingFF = 1
kDrivingV = 0.3
kDrivingA = 1.5
kDrivingMinOutput = -1
kDrivingMaxOutput = 1
kTurningP = 40
kTurningI = 0
kTurningD = 0
kTurningFF = 0
kTurningMinOutput = -1
kTurningMaxOutput = 1
kDrivingMotorIdleMode = SparkBaseConfig.IdleMode.kBrake
kTurningMotorIdleMode = SparkBaseConfig.IdleMode.kBrake
kDrivingMotorCurrentLimit = 50 # amp
kTurningMotorCurrentLimit = 20 # amp
class OIConstants:
kDriverControllerPort = 1
kDriveDeadband = 0.4
kLaunchButton = 1
kButtonBoardPort = 2
kButtonBoardPort2 = 0
kElevatorUpButton = 8
kElevatorDownButton = 10
kElevatorLvl0Button = 1
kElevatorLvl1Button = 1
kElevatorLvl2Button = 2
kElevatorLvl3Button = 3
kElevatorLvl4Button = 4
kIntakeButton = 6
kDeliveryButton = 9
kAlignLeftButton = 5
kAlignRightButton = 7
class AutoConstants:
kMaxSpeedMetersPerSecond = 10
kMaxAccelerationMetersPerSecondSquared = 10
kMaxAngularSpeedRadiansPerSecond = math.pi
kMaxAngularSpeedRadiansPerSecondSquared = math.pi
kPXController = 1
kPYController = 1
kPThetaController = 1
# Constraint for the motion profiled robot angle controller
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared
)
class ElevatorConstants:
kLeftMotorCanId = 4
kRightMotorCanId = 32
kUpperLimit = 1
kLowerLimit = 2
kEncoderPositionFactor = 1
kEncoderVelocityFactor = 1
kP = 0.02
kI = 0
kD = 0
kLvl0Height = 0
kLvl1Height = 0
kLvl2Height = 45
kLvl3Height = 72
kLvl4Height = 50
kForwardSoftLimit = 10000
kReverseSoftLimit = -100
kElevatorMaxSpeed = 1.5
kTimedSpeed = 0.6
kTimedTime = 4
class LEDConstants:
kLEDPort = 0
kLEDBuffer = 64
kSilverHue = 0
kSilverSat = 0
kSilverVal = 10
kBlueHue = 90
kBlueSat = 220
kBlueVal = 30
kGoodColor = [120, 255, 50]
kBadColor = [0, 100, 50]
class UltrasonicConstants:
kPingChannel = 1
kEchoChannel = 2
class LaunchConstants:
kLaunchMotor = 42
kLaunchSpeed = 0.6
class AlignConstants:
kMaxNormalizedSpeed = 1.0
kMaxTurningSpeed = 1.0
kDistToSlow = 0.3
kRotDistToSlow = math.radians(20)
kAlignDeadzone = 0.03
kAlignRotDeadzone = math.radians(5)
kLeftAlignXOffset = 0.1625
kLeftAlignYOffset = 0
kRightAlignXOffset = -0.1625
kRightAlignYOffset = 0