Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 1 | #include "frc971/constants.h" |
| 2 | |
| 3 | #include <math.h> |
| 4 | #include <stdint.h> |
| 5 | #include <inttypes.h> |
| 6 | |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 7 | #include <map> |
| 8 | |
| 9 | #if __has_feature(address_sanitizer) |
| 10 | #include "sanitizer/lsan_interface.h" |
| 11 | #endif |
| 12 | |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 13 | #include "aos/common/logging/logging.h" |
| 14 | #include "aos/common/once.h" |
| 15 | #include "aos/common/network/team_number.h" |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 16 | #include "aos/common/mutex.h" |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 17 | |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 18 | #include "frc971/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h" |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 19 | #include "frc971/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 20 | |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 21 | #ifndef M_PI |
| 22 | #define M_PI 3.14159265358979323846 |
| 23 | #endif |
| 24 | |
| 25 | namespace frc971 { |
| 26 | namespace constants { |
| 27 | namespace { |
| 28 | |
Brian Silverman | e5db0c6 | 2014-03-13 15:53:18 -0700 | [diff] [blame] | 29 | const uint16_t kCompTeamNumber = 971; |
Brian Silverman | a20703b | 2014-03-20 14:29:37 -0700 | [diff] [blame] | 30 | const uint16_t kPracticeTeamNumber = 9971; |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 31 | |
| 32 | // ///// Drivetrain Constants |
Brian Silverman | e5db0c6 | 2014-03-13 15:53:18 -0700 | [diff] [blame] | 33 | |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 34 | // These three constants were set by Daniel on 2/13/15. |
Austin Schuh | 58baa35 | 2015-02-20 22:08:26 -0800 | [diff] [blame] | 35 | const double kDrivetrainEncoderRatio = 20.0 / 50.0; |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 36 | const double kLowGearRatio = kDrivetrainEncoderRatio * 20.0 / 50.0; |
| 37 | const double kHighGearRatio = kLowGearRatio; |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 38 | |
Brian Silverman | e5db0c6 | 2014-03-13 15:53:18 -0700 | [diff] [blame] | 39 | const ShifterHallEffect kCompRightDriveShifter{555, 657, 660, 560, 0.2, 0.7}; |
| 40 | const ShifterHallEffect kCompLeftDriveShifter{555, 660, 644, 552, 0.2, 0.7}; |
Brian Silverman | 6eb51f1 | 2013-11-02 14:39:01 -0700 | [diff] [blame] | 41 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 42 | const ShifterHallEffect kPracticeRightDriveShifter{2.95, 3.95, 3.95, |
| 43 | 2.95, 0.2, 0.7}; |
| 44 | const ShifterHallEffect kPracticeLeftDriveShifter{2.95, 4.2, 3.95, |
| 45 | 3.0, 0.2, 0.7}; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 46 | const double kToteHeight = 0.3; |
Brian Silverman | e5db0c6 | 2014-03-13 15:53:18 -0700 | [diff] [blame] | 47 | |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 48 | // Set by Daniel on 2/13/15. |
| 49 | // Distance from the center of the left wheel to the center of the right wheel. |
| 50 | const double kRobotWidth = 37.806 /*inches*/ * 0.0254; |
Brian Silverman | 6eb51f1 | 2013-11-02 14:39:01 -0700 | [diff] [blame] | 51 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 52 | // ///// Superstructure Constants |
| 53 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 54 | // Elevator gearbox pulley output constants. |
| 55 | const int kElevatorGearboxOutputPulleyTeeth = 32; // 32 teeth |
| 56 | const double kElevatorGearboxOutputPitch = 0.005; // 5 mm/tooth |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 57 | const double kElevatorGearboxOutputRadianDistance = |
| 58 | kElevatorGearboxOutputPulleyTeeth * kElevatorGearboxOutputPitch / |
| 59 | (2.0 * M_PI); |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 60 | |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 61 | const double kArmZeroingHeight = 0.2; |
| 62 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 63 | const double kMaxAllowedLeftRightArmDifference = 0.04; // radians |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 64 | const double kMaxAllowedLeftRightElevatorDifference = 0.01; // meters |
| 65 | |
Benjamin Fredrickson | a74b0bd | 2015-03-07 00:32:52 -0800 | [diff] [blame^] | 66 | const Values::ClawGeometry kClawGeometry{ |
| 67 | // Horizontal distance from the center of the grabber to the end. |
| 68 | 0.5 * 18.0 * 0.0254, |
| 69 | // Vertical distance from the arm rotation center to the bottom of |
| 70 | // the |
| 71 | // grabber. Distance measured with arm vertical (theta = 0). |
| 72 | 5.1 * 0.0254, |
| 73 | // Vertical separation of the claw and arm rotation centers with the |
| 74 | // elevator at 0.0 and the arm angle set to zero. |
| 75 | 10.5 * 0.0254, |
| 76 | // Horizontal separation of the claw and arm rotation centers with |
| 77 | // the |
| 78 | // elevator at 0.0 and the arm angle set to zero. |
| 79 | 6.5 * 0.0254, |
| 80 | // Distance between the center of the claw to the top of the claw. |
| 81 | // 2.75 inches would work most of the time. Using 3.5 inches because |
| 82 | // of the |
| 83 | // pnumatics fitting on the piston. |
| 84 | 3.5 * 0.0254, |
| 85 | // The grabber is safe at any height if it is behind this location. |
| 86 | // The location of the grabber is used here and not the location of |
| 87 | // the end |
| 88 | // of the grabber. The grabber location is (0, 0) when the elevator |
| 89 | // is at 0 |
| 90 | // and the arm angle is 0. |
| 91 | (18.0 - 0.3) * 0.0254, |
| 92 | // The grabber is safe at any x if it is above this location. |
| 93 | // The location of the grabber is used here and not the location of |
| 94 | // the end |
| 95 | // of the grabber. The grabber location is (0, 0) when the elevator |
| 96 | // is at 0 |
| 97 | // and the arm angle is 0. |
| 98 | // The "-5.4" is the location of the bottom of the grabber when |
| 99 | // the elevator is at the bottom (-0.3 inches) and arm angle is 0. |
| 100 | -8.0 * 0.0254, |
| 101 | }; |
| 102 | |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 103 | // Gearing ratios of the pots and encoders for the elevator and arm. |
| 104 | // Ratio is output shaft rotations per encoder/pot rotation |
| 105 | // Checked by Daniel on 2/13/15. |
| 106 | const double kArmEncoderRatio = 18.0 / 48.0 * 16.0 / 72.0; |
| 107 | const double kArmPotRatio = 48.0 / 48.0 * 16.0 / 72.0; |
| 108 | const double kElevatorEncoderRatio = 14.0 / 84.0; |
| 109 | const double kElevatorPotRatio = 1.0; |
| 110 | const double kClawEncoderRatio = 18.0 / 72.0; |
| 111 | const double kClawPotRatio = 18.0 / 72.0; |
| 112 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 113 | // Number of radians between each index pulse on the arm. |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 114 | const double kArmEncoderIndexDifference = 2.0 * M_PI * kArmEncoderRatio; |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 115 | // Number of meters between each index pulse on the elevator. |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 116 | const double kElevatorEncoderIndexDifference = |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 117 | kElevatorEncoderRatio * 2.0 * M_PI * // radians |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 118 | kElevatorGearboxOutputRadianDistance; |
| 119 | // Number of radians between index pulses on the claw. |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 120 | const double kClawEncoderIndexDifference = 2.0 * M_PI * kClawEncoderRatio; |
| 121 | |
Austin Schuh | 44cd580 | 2015-03-01 00:06:09 -0800 | [diff] [blame] | 122 | const int kZeroingSampleSize = 200; |
Brian Silverman | edcfd2d | 2014-04-03 13:04:16 -0700 | [diff] [blame] | 123 | |
Daniel Petti | 9cf68c8 | 2015-02-14 14:57:17 -0800 | [diff] [blame] | 124 | // TODO(danielp): All these values might need to change. |
| 125 | const double kClawPistonSwitchTime = 0.4; |
| 126 | const double kClawZeroingRange = 0.3; |
| 127 | |
Ben Fredrickson | a9dcfa4 | 2014-02-23 02:05:59 +0000 | [diff] [blame] | 128 | const Values *DoGetValuesForTeam(uint16_t team) { |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 129 | switch (team) { |
Brian Silverman | 0d2b7cb | 2014-02-18 20:25:57 -0800 | [diff] [blame] | 130 | case 1: // for tests |
| 131 | return new Values{ |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 132 | kDrivetrainEncoderRatio, |
| 133 | kArmEncoderRatio, |
| 134 | kArmPotRatio, |
| 135 | kElevatorEncoderRatio, |
| 136 | kElevatorPotRatio, |
| 137 | kElevatorGearboxOutputRadianDistance, |
| 138 | kClawEncoderRatio, |
| 139 | kClawPotRatio, |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 140 | kToteHeight, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 141 | kLowGearRatio, |
| 142 | kHighGearRatio, |
Brian Silverman | 0d2b7cb | 2014-02-18 20:25:57 -0800 | [diff] [blame] | 143 | kCompLeftDriveShifter, |
| 144 | kCompRightDriveShifter, |
Austin Schuh | 1172621 | 2014-03-02 14:01:02 -0800 | [diff] [blame] | 145 | false, |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 146 | 0.5, |
Austin Schuh | a25a041 | 2014-03-09 00:50:04 -0800 | [diff] [blame] | 147 | control_loops::MakeVelocityDrivetrainLoop, |
| 148 | control_loops::MakeDrivetrainLoop, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 149 | 0.02, // drivetrain done delta |
| 150 | 5.0, // drivetrain max speed |
| 151 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 152 | // Motion ranges: hard_lower_limit, hard_upper_limit, |
| 153 | // soft_lower_limit, soft_upper_limit |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 154 | {// Claw values, in radians. |
| 155 | // 0 is level with the ground. |
| 156 | // Positive moves in the direction of positive encoder values. |
Brian Silverman | 24e37ad | 2015-02-18 01:58:08 -0500 | [diff] [blame] | 157 | {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 158 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 159 | // Zeroing constants for wrist. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 160 | {kZeroingSampleSize, kClawEncoderIndexDifference, 0.9, 0.3}, |
Daniel Petti | 9cf68c8 | 2015-02-14 14:57:17 -0800 | [diff] [blame] | 161 | |
Brian Silverman | 24e37ad | 2015-02-18 01:58:08 -0500 | [diff] [blame] | 162 | 6.308141, |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 163 | kClawPistonSwitchTime, |
| 164 | kClawZeroingRange}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 165 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 166 | {// Elevator values, in meters. |
Brian Silverman | 24e37ad | 2015-02-18 01:58:08 -0500 | [diff] [blame] | 167 | // 0 is the portion of the elevator carriage that Spencer removed |
| 168 | // lining up with the bolt. |
| 169 | // Positive is up. |
| 170 | {-0.005, 0.679000, 0.010000, 0.650000}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 171 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 172 | // Arm values, in radians. |
| 173 | // 0 is sticking straight out horizontally over the intake/front. |
| 174 | // Positive is rotating up and into the robot (towards the back). |
Brian Silverman | 24e37ad | 2015-02-18 01:58:08 -0500 | [diff] [blame] | 175 | {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 176 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 177 | // Elevator zeroing constants: left, right. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 178 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.0, 0.3}, |
| 179 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.0, 0.3}, |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 180 | // Arm zeroing constants: left, right. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 181 | {kZeroingSampleSize, kArmEncoderIndexDifference, 0.0, 0.3}, |
| 182 | {kZeroingSampleSize, kArmEncoderIndexDifference, 0.0, 0.3}, |
Brian Silverman | 24e37ad | 2015-02-18 01:58:08 -0500 | [diff] [blame] | 183 | 0.7, |
| 184 | -0.08, |
| 185 | -3.5 - 0.01 - -0.02, |
| 186 | 3.5 - 0.17 - -0.15, |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 187 | |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 188 | kArmZeroingHeight, |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 189 | }, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 190 | // End "sensor" values. |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 191 | |
| 192 | kMaxAllowedLeftRightArmDifference, |
| 193 | kMaxAllowedLeftRightElevatorDifference, |
Benjamin Fredrickson | a74b0bd | 2015-03-07 00:32:52 -0800 | [diff] [blame^] | 194 | kClawGeometry, |
Brian Silverman | 0d2b7cb | 2014-02-18 20:25:57 -0800 | [diff] [blame] | 195 | }; |
| 196 | break; |
Austin Schuh | 58baa35 | 2015-02-20 22:08:26 -0800 | [diff] [blame] | 197 | case kPracticeTeamNumber: |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 198 | return new Values{ |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 199 | kDrivetrainEncoderRatio, |
| 200 | kArmEncoderRatio, |
| 201 | kArmPotRatio, |
| 202 | kElevatorEncoderRatio, |
| 203 | kElevatorPotRatio, |
| 204 | kElevatorGearboxOutputRadianDistance, |
| 205 | kClawEncoderRatio, |
| 206 | kClawPotRatio, |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 207 | kToteHeight, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 208 | kLowGearRatio, |
| 209 | kHighGearRatio, |
Austin Schuh | 288c8c3 | 2014-02-16 17:20:17 -0800 | [diff] [blame] | 210 | kCompLeftDriveShifter, |
| 211 | kCompRightDriveShifter, |
Brian Silverman | edcfd2d | 2014-04-03 13:04:16 -0700 | [diff] [blame] | 212 | false, |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 213 | kRobotWidth, |
Austin Schuh | a25a041 | 2014-03-09 00:50:04 -0800 | [diff] [blame] | 214 | control_loops::MakeVelocityDrivetrainLoop, |
| 215 | control_loops::MakeDrivetrainLoop, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 216 | 0.02, // drivetrain done delta |
| 217 | 5.0, // drivetrain max speed |
| 218 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 219 | // Motion ranges: hard_lower_limit, hard_upper_limit, |
| 220 | // soft_lower_limit, soft_upper_limit |
| 221 | // TODO(sensors): Get actual bounds before turning on robot. |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 222 | {// Claw values, in radians. |
| 223 | // 0 is level with the ground. |
| 224 | // Positive moves in the direction of positive encoder values. |
| 225 | {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 226 | |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 227 | // Zeroing constants for wrist. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 228 | {kZeroingSampleSize, kClawEncoderIndexDifference, 0.9104180000000001, |
| 229 | 0.3}, |
Daniel Petti | 9cf68c8 | 2015-02-14 14:57:17 -0800 | [diff] [blame] | 230 | |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 231 | 6.308141, |
| 232 | kClawPistonSwitchTime, |
| 233 | kClawZeroingRange}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 234 | |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 235 | {// Elevator values, in meters. |
| 236 | // 0 is the portion of the elevator carriage that Spencer removed |
| 237 | // lining up with the bolt. |
| 238 | // Positive is up. |
| 239 | {-0.00500, 0.679000, 0.010000, 0.650000}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 240 | |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 241 | // Arm values, in radians. |
| 242 | // 0 is sticking straight out horizontally over the intake/front. |
| 243 | // Positive is rotating up and into the robot (towards the back). |
| 244 | {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 245 | |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 246 | // Elevator zeroing constants: left, right. |
Austin Schuh | 44cd580 | 2015-03-01 00:06:09 -0800 | [diff] [blame] | 247 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.094297, 0.3}, |
| 248 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, 0.106393, 0.3}, |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 249 | // Arm zeroing constants: left, right. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 250 | {kZeroingSampleSize, kArmEncoderIndexDifference, -0.324437, 0.3}, |
| 251 | {kZeroingSampleSize, kArmEncoderIndexDifference, -0.064683, 0.3}, |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 252 | 0.722230 - -0.000594, |
| 253 | -0.081354 - -0.000374, |
Austin Schuh | 0b406bb | 2015-02-17 02:28:48 -0800 | [diff] [blame] | 254 | -3.509611 - 0.007415 - -0.019081, |
| 255 | 3.506927 - 0.170017 - -0.147970, |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 256 | |
| 257 | kArmZeroingHeight, |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 258 | }, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 259 | // End "sensor" values. |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 260 | |
| 261 | kMaxAllowedLeftRightArmDifference, |
| 262 | kMaxAllowedLeftRightElevatorDifference, |
Benjamin Fredrickson | a74b0bd | 2015-03-07 00:32:52 -0800 | [diff] [blame^] | 263 | kClawGeometry, |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 264 | }; |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 265 | break; |
Austin Schuh | 58baa35 | 2015-02-20 22:08:26 -0800 | [diff] [blame] | 266 | case kCompTeamNumber: |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 267 | return new Values{ |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 268 | kDrivetrainEncoderRatio, |
| 269 | kArmEncoderRatio, |
| 270 | kArmPotRatio, |
| 271 | kElevatorEncoderRatio, |
| 272 | kElevatorPotRatio, |
| 273 | kElevatorGearboxOutputRadianDistance, |
| 274 | kClawEncoderRatio, |
| 275 | kClawPotRatio, |
Daniel Petti | dfc90ba | 2015-02-17 21:42:15 -0800 | [diff] [blame] | 276 | kToteHeight, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 277 | kLowGearRatio, |
| 278 | kHighGearRatio, |
Austin Schuh | 288c8c3 | 2014-02-16 17:20:17 -0800 | [diff] [blame] | 279 | kPracticeLeftDriveShifter, |
| 280 | kPracticeRightDriveShifter, |
| 281 | false, |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 282 | kRobotWidth, |
Austin Schuh | a25a041 | 2014-03-09 00:50:04 -0800 | [diff] [blame] | 283 | control_loops::MakeVelocityDrivetrainLoop, |
| 284 | control_loops::MakeDrivetrainLoop, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 285 | 0.02, // drivetrain done delta |
| 286 | 5.0, // drivetrain max speed |
| 287 | |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 288 | // Motion ranges: hard_lower_limit, hard_upper_limit, |
| 289 | // soft_lower_limit, soft_upper_limit |
| 290 | // TODO(sensors): Get actual bounds before turning on robot. |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 291 | {// Claw values, in radians. |
| 292 | // 0 is level with the ground. |
| 293 | // Positive moves in the direction of positive encoder values. |
| 294 | {-0.05, M_PI / 2.0 + 0.1, 0.0, M_PI / 2.0}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 295 | |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 296 | // Zeroing constants for wrist. |
| 297 | // TODO(sensors): Get actual offsets for these. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 298 | {kZeroingSampleSize, kClawEncoderIndexDifference, 0.973311, 0.3}, |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 299 | 6.1663463999999992, |
Daniel Petti | 9cf68c8 | 2015-02-14 14:57:17 -0800 | [diff] [blame] | 300 | |
| 301 | kClawPistonSwitchTime, |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 302 | kClawZeroingRange}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 303 | |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 304 | {// Elevator values, in meters. |
| 305 | // 0 is at the top of the elevator frame. |
| 306 | // Positive is down towards the drivebase. |
| 307 | {-0.00500, 0.679000, 0.010000, 0.650000}, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 308 | |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 309 | // Arm values, in radians. |
| 310 | // 0 is sticking straight out horizontally over the intake/front. |
| 311 | // Positive is rotating up and into the robot (towards the back). |
| 312 | {-M_PI / 2 - 0.05, M_PI / 2 + 0.05, -M_PI / 2, M_PI / 2}, |
Daniel Petti | a782741 | 2015-02-13 20:55:57 -0800 | [diff] [blame] | 313 | |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 314 | // Elevator zeroing constants: left, right. |
| 315 | // TODO(sensors): Get actual offsets for these. |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 316 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 317 | 0.016041 + 0.001290, 0.3}, |
Daniel Petti | ee4fa80 | 2015-02-17 10:39:27 -0800 | [diff] [blame] | 318 | {kZeroingSampleSize, kElevatorEncoderIndexDifference, |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 319 | 0.011367 + 0.003216, 0.3}, |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 320 | // Arm zeroing constants: left, right. |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 321 | {kZeroingSampleSize, kArmEncoderIndexDifference, 0.060592, 0.3}, |
| 322 | {kZeroingSampleSize, kArmEncoderIndexDifference, 0.210155, 0.3}, |
Austin Schuh | bfb8b24 | 2015-02-16 15:45:22 -0800 | [diff] [blame] | 323 | 0.72069366666666679 - 0.026008, |
| 324 | -0.078959636363636357 - 0.024646, |
Austin Schuh | 58baa35 | 2015-02-20 22:08:26 -0800 | [diff] [blame] | 325 | -3.509611 - 0.007415 - -0.019081 - 0.029393 - -0.013585, |
| 326 | 3.506927 - 0.170017 - -0.147970 - 0.005045 - -0.026504, |
Daniel Petti | e1bb13e | 2015-02-17 13:59:15 -0800 | [diff] [blame] | 327 | |
| 328 | kArmZeroingHeight, |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 329 | }, |
Comran Morshed | 79bd3db | 2015-02-07 14:51:13 +0000 | [diff] [blame] | 330 | // TODO(sensors): End "sensor" values. |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 331 | |
| 332 | kMaxAllowedLeftRightArmDifference, |
| 333 | kMaxAllowedLeftRightElevatorDifference, |
Benjamin Fredrickson | a74b0bd | 2015-03-07 00:32:52 -0800 | [diff] [blame^] | 334 | kClawGeometry, |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 335 | }; |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 336 | break; |
| 337 | default: |
| 338 | LOG(FATAL, "unknown team #%" PRIu16 "\n", team); |
| 339 | } |
| 340 | } |
| 341 | |
Ben Fredrickson | a9dcfa4 | 2014-02-23 02:05:59 +0000 | [diff] [blame] | 342 | const Values *DoGetValues() { |
| 343 | uint16_t team = ::aos::network::GetTeamNumber(); |
| 344 | LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team); |
| 345 | return DoGetValuesForTeam(team); |
| 346 | } |
| 347 | |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 348 | } // namespace |
| 349 | |
| 350 | const Values &GetValues() { |
| 351 | static ::aos::Once<const Values> once(DoGetValues); |
| 352 | return *once.Get(); |
| 353 | } |
| 354 | |
Ben Fredrickson | a9dcfa4 | 2014-02-23 02:05:59 +0000 | [diff] [blame] | 355 | const Values &GetValuesForTeam(uint16_t team_number) { |
Brian Silverman | 0a151c9 | 2014-05-02 15:28:44 -0700 | [diff] [blame] | 356 | static ::aos::Mutex mutex; |
| 357 | ::aos::MutexLocker locker(&mutex); |
| 358 | |
| 359 | // IMPORTANT: This declaration has to stay after the mutex is locked to avoid |
| 360 | // race conditions. |
| 361 | static ::std::map<uint16_t, const Values *> values; |
| 362 | |
| 363 | if (values.count(team_number) == 0) { |
| 364 | values[team_number] = DoGetValuesForTeam(team_number); |
| 365 | #if __has_feature(address_sanitizer) |
| 366 | __lsan_ignore_object(values[team_number]); |
| 367 | #endif |
| 368 | } |
| 369 | return *values[team_number]; |
Ben Fredrickson | a9dcfa4 | 2014-02-23 02:05:59 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 372 | } // namespace constants |
| 373 | } // namespace frc971 |