|
| 1 | +# Copyright (c) FIRST and other WPILib contributors. |
| 2 | +# Open Source Software; you can modify and/or share it under the terms of |
| 3 | +# the WPILib BSD license file in the root directory of this project. |
| 4 | + |
| 5 | +""" |
| 6 | +The constants module is a convenience place for teams to hold robot-wide |
| 7 | +numerical or boolean constants. Don't use this for any other purpose! |
| 8 | +""" |
| 9 | + |
| 10 | + |
| 11 | +import math |
| 12 | + |
| 13 | +from wpimath import units |
| 14 | +from wpimath.geometry import Translation2d |
| 15 | +from wpimath.kinematics import SwerveDrive4Kinematics |
| 16 | +from wpimath.trajectory import TrapezoidProfileRadians |
| 17 | + |
| 18 | +from rev import CANSparkMax |
| 19 | + |
| 20 | + |
| 21 | +class NeoMotorConstants: |
| 22 | + kFreeSpeedRpm = 5676 |
| 23 | + |
| 24 | + |
| 25 | +class DriveConstants: |
| 26 | + # Driving Parameters - Note that these are not the maximum capable speeds of |
| 27 | + # the robot, rather the allowed maximum speeds |
| 28 | + kMaxSpeedMetersPerSecond = 4.8 |
| 29 | + kMaxAngularSpeed = 2 * math.pi # radians per second |
| 30 | + |
| 31 | + kDirectionSlewRate = 1.2 # radians per second |
| 32 | + kMagnitudeSlewRate = 1.8 # percent per second (1 = 100%) |
| 33 | + kRotationalSlewRate = 2.0 # percent per second (1 = 100%) |
| 34 | + |
| 35 | + # Chassis configuration |
| 36 | + kTrackWidth = units.inchesToMeters(26.5) |
| 37 | + # Distance between centers of right and left wheels on robot |
| 38 | + kWheelBase = units.inchesToMeters(26.5) |
| 39 | + |
| 40 | + # Distance between front and back wheels on robot |
| 41 | + kModulePositions = [ |
| 42 | + Translation2d(kWheelBase / 2, kTrackWidth / 2), |
| 43 | + Translation2d(kWheelBase / 2, -kTrackWidth / 2), |
| 44 | + Translation2d(-kWheelBase / 2, kTrackWidth / 2), |
| 45 | + Translation2d(-kWheelBase / 2, -kTrackWidth / 2), |
| 46 | + ] |
| 47 | + kDriveKinematics = SwerveDrive4Kinematics(*kModulePositions) |
| 48 | + |
| 49 | + # Angular offsets of the modules relative to the chassis in radians |
| 50 | + kFrontLeftChassisAngularOffset = -math.pi / 2 |
| 51 | + kFrontRightChassisAngularOffset = 0 |
| 52 | + kBackLeftChassisAngularOffset = math.pi |
| 53 | + kBackRightChassisAngularOffset = math.pi / 2 |
| 54 | + |
| 55 | + # SPARK MAX CAN IDs |
| 56 | + kFrontLeftDrivingCanId = 11 |
| 57 | + kRearLeftDrivingCanId = 13 |
| 58 | + kFrontRightDrivingCanId = 15 |
| 59 | + kRearRightDrivingCanId = 17 |
| 60 | + |
| 61 | + kFrontLeftTurningCanId = 10 |
| 62 | + kRearLeftTurningCanId = 12 |
| 63 | + kFrontRightTurningCanId = 14 |
| 64 | + kRearRightTurningCanId = 16 |
| 65 | + |
| 66 | + kGyroReversed = False |
| 67 | + |
| 68 | + |
| 69 | +class ModuleConstants: |
| 70 | + # The MAXSwerve module can be configured with one of three pinion gears: 12T, 13T, or 14T. |
| 71 | + # This changes the drive speed of the module (a pinion gear with more teeth will result in a |
| 72 | + # robot that drives faster). |
| 73 | + kDrivingMotorPinionTeeth = 14 |
| 74 | + |
| 75 | + # Invert the turning encoder, since the output shaft rotates in the opposite direction of |
| 76 | + # the steering motor in the MAXSwerve Module. |
| 77 | + kTurningEncoderInverted = True |
| 78 | + |
| 79 | + # Calculations required for driving motor conversion factors and feed forward |
| 80 | + kDrivingMotorFreeSpeedRps = NeoMotorConstants.kFreeSpeedRpm / 60 |
| 81 | + kWheelDiameterMeters = 0.0762 |
| 82 | + kWheelCircumferenceMeters = kWheelDiameterMeters * math.pi |
| 83 | + # 45 teeth on the wheel's bevel gear, 22 teeth on the first-stage spur gear, 15 teeth on the bevel pinion |
| 84 | + kDrivingMotorReduction = (45.0 * 22) / (kDrivingMotorPinionTeeth * 15) |
| 85 | + kDriveWheelFreeSpeedRps = ( |
| 86 | + kDrivingMotorFreeSpeedRps * kWheelCircumferenceMeters |
| 87 | + ) / kDrivingMotorReduction |
| 88 | + |
| 89 | + kDrivingEncoderPositionFactor = ( |
| 90 | + kWheelDiameterMeters * math.pi |
| 91 | + ) / kDrivingMotorReduction # meters |
| 92 | + kDrivingEncoderVelocityFactor = ( |
| 93 | + (kWheelDiameterMeters * math.pi) / kDrivingMotorReduction |
| 94 | + ) / 60.0 # meters per second |
| 95 | + |
| 96 | + kTurningEncoderPositionFactor = 2 * math.pi # radian |
| 97 | + kTurningEncoderVelocityFactor = (2 * math.pi) / 60.0 # radians per second |
| 98 | + |
| 99 | + kTurningEncoderPositionPIDMinInput = 0 # radian |
| 100 | + kTurningEncoderPositionPIDMaxInput = kTurningEncoderPositionFactor # radian |
| 101 | + |
| 102 | + kDrivingP = 0.04 |
| 103 | + kDrivingI = 0 |
| 104 | + kDrivingD = 0 |
| 105 | + kDrivingFF = 1 / kDriveWheelFreeSpeedRps |
| 106 | + kDrivingMinOutput = -1 |
| 107 | + kDrivingMaxOutput = 1 |
| 108 | + |
| 109 | + kTurningP = 1 |
| 110 | + kTurningI = 0 |
| 111 | + kTurningD = 0 |
| 112 | + kTurningFF = 0 |
| 113 | + kTurningMinOutput = -1 |
| 114 | + kTurningMaxOutput = 1 |
| 115 | + |
| 116 | + kDrivingMotorIdleMode = CANSparkMax.IdleMode.kBrake |
| 117 | + kTurningMotorIdleMode = CANSparkMax.IdleMode.kBrake |
| 118 | + |
| 119 | + kDrivingMotorCurrentLimit = 50 # amp |
| 120 | + kTurningMotorCurrentLimit = 20 # amp |
| 121 | + |
| 122 | + |
| 123 | +class OIConstants: |
| 124 | + kDriverControllerPort = 0 |
| 125 | + kDriveDeadband = 0.05 |
| 126 | + |
| 127 | + |
| 128 | +class AutoConstants: |
| 129 | + kMaxSpeedMetersPerSecond = 3 |
| 130 | + kMaxAccelerationMetersPerSecondSquared = 3 |
| 131 | + kMaxAngularSpeedRadiansPerSecond = math.pi |
| 132 | + kMaxAngularSpeedRadiansPerSecondSquared = math.pi |
| 133 | + |
| 134 | + kPXController = 1 |
| 135 | + kPYController = 1 |
| 136 | + kPThetaController = 1 |
| 137 | + |
| 138 | + # Constraint for the motion profiled robot angle controller |
| 139 | + kThetaControllerConstraints = TrapezoidProfileRadians.Constraints( |
| 140 | + kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared |
| 141 | + ) |
0 commit comments