generated from Choate-Robotics/7407-DriveCode-Template-v2
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
402 lines (359 loc) · 10.7 KB
/
config.py
File metadata and controls
402 lines (359 loc) · 10.7 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
from dataclasses import dataclass
from wpilib import AnalogEncoder
from toolkit.motors.ctre_motors import TalonConfig
import math
from pathplannerlib.config import PIDConstants
from units.SI import degrees, radians, meters, inches_to_meters
import constants
DEBUG_MODE: bool = False
# MAKE SURE TO MAKE THIS FALSE FOR COMPETITION
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
foc_active = False # foc for TalonFX requires paid subscription
trigger_threshold = 0.4
# DEBUGGING NETWORK TABLES
NT_INTAKE: bool = True
NT_ELEVATOR: bool = True
NT_WRIST: bool = True
NT_DRIVETRAIN: bool = True
NT_CLIMBER: bool = True
# Cameras
left_cam_name = "left_cam"
right_cam_name = "right_cam"
# Drivetrain
gyro_id: int = 20
front_left_move_id: int = 1
front_left_turn_id: int = 2
front_left_encoder_port: AnalogEncoder = AnalogEncoder(2)
front_left_encoder_zeroed_pos: float = 0.945
front_left_turn_inverted = False
front_left_move_inverted = False
front_right_move_id: int = 3
front_right_turn_id: int = 4
front_right_encoder_port: AnalogEncoder = AnalogEncoder(3)
front_right_encoder_zeroed_pos: float = 0.074
front_right_turn_inverted = False
front_right_move_inverted = False
back_left_move_id: int = 7
back_left_turn_id: int = 8
back_left_encoder_port: AnalogEncoder = AnalogEncoder(1)
back_left_encoder_zeroed_pos: float = 0.227
back_left_turn_inverted = False
back_left_move_inverted = False
back_right_move_id: int = 5
back_right_turn_id: int = 6
back_right_encoder_port: AnalogEncoder = AnalogEncoder(0)
back_right_encoder_zeroed_pos: float = 0.597
back_right_turn_inverted = False
back_right_move_inverted = False
driver_centric: bool = True
drivetrain_deadzone: float = 0.1
drivetrain_curve: float = 2.0000
drivetrain_zero: radians = math.radians(0)
drivetrain_rotation_kp: float = 5
drivetrain_rotation_ki: float = 0.0
drivetrain_rotation_kd: float = 0.0
drivetrain_rotation_tolerance: degrees = 1 # degrees
drivetrain_x_kp: float = 4.0
drivetrain_x_ki: float = 0.0
drivetrain_x_kd: float = 0.0
drivetrain_x_tolerance: float = 0.001
drivetrain_y_kp: float = 4.0
drivetrain_y_ki: float = 0.0
drivetrain_y_kd: float = 0.0
drivetrain_y_tolerance: float = 0.001
auto_translation_pid = PIDConstants(4, 0.0, 0)
auto_rotation_pid = PIDConstants(5.0, 0.0, 0.0)
TURN_CONFIG = TalonConfig(7, 0, 0.02, 0, 0, brake_mode=True)
MOVE_CONFIG = TalonConfig(
0.11,
0,
0,
kF=0.25,
kA=0.15,
kV=0.12,
brake_mode=True,
current_limit=50,
)
climber_motor_id = 16
climber_config = TalonConfig(0, 0, 0, 0, 0, brake_mode=True)
deploy_climber_speed = 1
climb_speed = 1
manual_climber_speed = 0.2
deploy_position = 285
manual_lower_bound = -50
climb_initial_out = 45
# odometry
odometry_tag_distance_threshold: meters = 2.5
# Wrist
wrist_feed_id = 15
WRIST_FEED_CONFIG = TalonConfig(1, 0, 0, 0, 0, current_limit=60)
wrist_algae_id = 17
WRIST_ALGAE_CONFIG = TalonConfig(1, 0, 0, 0, 0, current_limit=40)
wrist_id = 14
WRIST_CONFIG = TalonConfig(
48, 0, 0, 0.06, 0, motion_magic_cruise_velocity=97.75, motion_magic_acceleration=350
) # 97.75
wrist_cancoder_id = 22
wrist_encoder_zero = 0.781
wrist_intake_speed = 0.5
wrist_extake_speed_teleop = -0.25
wrist_extake_speed_auto = -0.9
wrist_algae_speed = 1
wrist_algae_extake_speed = -0.5
wrist_algae_hold_volts = 1
algae_moving_hold_volts = 10
wrist_max_angle: radians = math.radians(75)
wrist_min_angle: radians = math.radians(-117)
angle_threshold: radians = math.radians(1) # radians
out_current_threshold: float = 13 # amps PLACEHOLDER
back_current_threshold: float = 50
current_time_threshold: float = 0.375
wrist_algae_time_threshold: float = 3 # seconds PLACEHOLDER
algae_current_threshold: float = 20
wrist_max_ff = 0.17
wrist_ff_offset = math.radians(30)
# intake
horizontal_id = 13
intake_cancoder_id = 21
intake_pivot_id = 11
intake_encoder_zero = 0.075
INTAKE_CONFIG = TalonConfig(0, 0, 0, 0, 0, brake_mode=True)
INTAKE_PIVOT_CONFIG = TalonConfig(2, 0, 0, -0.195, 0, motion_magic_cruise_velocity=97, brake_mode=True) # 97
intake_max_angle = math.radians(60)
intake_min_angle = math.radians(-1)
intake_angle_threshold = math.radians(2)
intake_current_threshold = 80 # placeholder
intake_current_time_threshold = 2 # placeholder
intake_max_ff = -0.075
intake_ff_offset = math.radians(90)
horizontal_intake_speed = 0.7
l1_eject_speed = 0.1
intake_algae_speed = 1
extake_algae_speed = 0.275
# elevator
elevator_lead_id = 9
elevator_follower_id = 10
elevator_height_threshold = 0.1 * inches_to_meters # placeholder
ELEVATOR_CONFIG = TalonConfig(
5,
0,
0.175,
0.13,
0,
0,
kG=0.28,
brake_mode=True,
motion_magic_cruise_velocity=110,
motion_magic_acceleration=275,
motion_magic_jerk=1000
)
# TO CHANGE
period: float = 0.03
elevator_l1_height: meters = 5 * inches_to_meters
elevator_l2_height: meters = 6 * inches_to_meters
elevator_l3_height: meters = 13.75 * inches_to_meters
elevator_l4_height: meters = constants.elevator_max_height
elevator_dhigh_height: meters = 11 * inches_to_meters
elevator_dlow_height: meters = 2.75 * inches_to_meters
elevator_barge_height: meters = constants.elevator_max_height
intake_algae_ground_angle = math.radians(58)
intake_algae_score_angle = math.radians(32)
intake_climb_angle = math.radians(20)
intake_coral_station_angle = math.radians(-1)
intake_l1_angle = math.radians(37)
intake_l1_hold_angle = math.radians(-5)
wrist_idle_angle = math.radians(-10)
wrist_intake_angle = math.radians(-114.5)
wrist_intake_l1_angle = math.radians(-100)
wrist_l1_angle = math.radians(64)
wrist_l2_angle = math.radians(64)
wrist_l3_angle = math.radians(64)
wrist_l4_angle = math.radians(54)
wrist_dhigh_angle = math.radians(55)
wrist_dlow_angle = math.radians(55)
wrist_barge_angle = math.radians(54)
wrist_processor_score_angle = 0
# TARGET POSITIONS
@dataclass
class TargetData:
elevator_idle: bool
wrist_idle: bool
intake_idle: bool
elevator_height: meters
wrist_angle: radians
wrist_feed_on: bool
wrist_score_on: bool
intake_angle: radians
intake_in_run: bool
intake_out_run: bool
intake_climb: bool = False
target_positions: dict[str, TargetData] = {
"IDLE": TargetData(
elevator_idle=True,
wrist_idle=True,
intake_idle=True,
elevator_height=0,
wrist_angle=wrist_idle_angle,
wrist_feed_on=False,
wrist_score_on=False,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"STATION_INTAKING": TargetData(
elevator_idle=True,
wrist_idle=False,
intake_idle=True,
elevator_height=0,
wrist_angle=wrist_intake_angle,
wrist_feed_on=True,
wrist_score_on=False,
intake_angle=intake_coral_station_angle,
intake_in_run=True,
intake_out_run=False,
),
"INTAKE_L1": TargetData(
elevator_idle=True,
wrist_idle=False,
intake_idle=True,
elevator_height=0,
wrist_angle=wrist_intake_l1_angle,
wrist_feed_on=True,
wrist_score_on=False,
intake_angle=intake_coral_station_angle,
intake_in_run=True,
intake_out_run=False,
),
"L1": TargetData(
elevator_idle=True,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_l1_height,
wrist_angle=wrist_l1_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"L2": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_l2_height,
wrist_angle=wrist_l2_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"L3": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_l3_height,
wrist_angle=wrist_l3_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"L4": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_l4_height,
wrist_angle=wrist_l4_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"DEALGAE_HIGH": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_dhigh_height,
wrist_angle=wrist_dhigh_angle,
wrist_feed_on=False,
wrist_score_on=False,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"DEALGAE_LOW": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_dlow_height,
wrist_angle=wrist_dlow_angle,
wrist_feed_on=False,
wrist_score_on=False,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"SCORE_BARGE": TargetData(
elevator_idle=False,
wrist_idle=False,
intake_idle=True,
elevator_height=elevator_barge_height,
wrist_angle=wrist_barge_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
# "SCORE_PROCESSOR_INTAKE": TargetData(
# elevator_idle=True,
# wrist_idle=True,
# intake_idle=True, # Might also be ground intake, tbd
# elevator_height=0,
# wrist_angle=0,
# wrist_feed_on=False,
# wrist_score_on=False,
# intake_in_run=False,
# intake_out_run=True
# ),
"SCORE_PROCESSOR_WRIST": TargetData(
elevator_idle=True,
wrist_idle=False,
intake_idle=True,
elevator_height=0,
wrist_angle=wrist_processor_score_angle,
wrist_feed_on=False,
wrist_score_on=True,
intake_angle=0,
intake_in_run=False,
intake_out_run=False,
),
"INTAKE_ALGAE": TargetData(
elevator_idle=True,
wrist_idle=True,
intake_idle=False,
elevator_height=0,
wrist_angle=0,
wrist_feed_on=False,
wrist_score_on=False,
intake_angle=intake_algae_ground_angle,
intake_in_run=True,
intake_out_run=False,
),
"CLIMB": TargetData(
elevator_idle=True,
wrist_idle=True,
intake_idle=False,
elevator_height=0,
wrist_angle=0,
wrist_feed_on=False,
wrist_score_on=False,
intake_angle=intake_climb_angle,
intake_in_run=True,
intake_out_run=False,
intake_climb=True,
),
}