Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 1 | #include "aos/input/drivetrain_input.h" |
| 2 | |
| 3 | #include <math.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <cmath> |
| 7 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 8 | #include "aos/commonmath.h" |
| 9 | #include "aos/input/driver_station_data.h" |
| 10 | #include "aos/logging/logging.h" |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 12 | |
| 13 | using ::frc971::control_loops::drivetrain_queue; |
| 14 | using ::aos::input::driver_station::ButtonLocation; |
| 15 | using ::aos::input::driver_station::ControlBit; |
| 16 | using ::aos::input::driver_station::JoystickAxis; |
| 17 | using ::aos::input::driver_station::POVLocation; |
| 18 | |
| 19 | namespace aos { |
| 20 | namespace input { |
| 21 | |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 22 | const ButtonLocation kShiftHigh(2, 3), kShiftHigh2(2, 2), kShiftLow(2, 1); |
| 23 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 24 | void DrivetrainInputReader::HandleDrivetrain( |
| 25 | const ::aos::input::driver_station::Data &data) { |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 26 | const auto wheel_and_throttle = GetWheelAndThrottle(data); |
| 27 | const double wheel = wheel_and_throttle.wheel; |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 28 | const double wheel_velocity = wheel_and_throttle.wheel_velocity; |
| 29 | const double wheel_torque = wheel_and_throttle.wheel_torque; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 30 | const double throttle = wheel_and_throttle.throttle; |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 31 | const double throttle_velocity = wheel_and_throttle.throttle_velocity; |
| 32 | const double throttle_torque = wheel_and_throttle.throttle_torque; |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 33 | const bool high_gear = wheel_and_throttle.high_gear; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 34 | |
| 35 | drivetrain_queue.status.FetchLatest(); |
| 36 | if (drivetrain_queue.status.get()) { |
| 37 | robot_velocity_ = drivetrain_queue.status->robot_speed; |
| 38 | } |
| 39 | |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame^] | 40 | // If we have a vision align function, and it is in control, don't run the |
| 41 | // normal driving code. |
| 42 | if (vision_align_fn_) { |
| 43 | if (vision_align_fn_(data)) { |
| 44 | return; |
| 45 | } |
| 46 | } |
| 47 | |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 48 | bool is_control_loop_driving = false; |
| 49 | bool is_line_following = false; |
| 50 | |
| 51 | if (data.IsPressed(turn1_)) { |
| 52 | switch (turn1_use_) { |
| 53 | case TurnButtonUse::kControlLoopDriving: |
| 54 | is_control_loop_driving = true; |
| 55 | break; |
| 56 | case TurnButtonUse::kLineFollow: |
| 57 | is_line_following = true; |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (data.IsPressed(turn2_)) { |
| 63 | switch (turn2_use_) { |
| 64 | case TurnButtonUse::kControlLoopDriving: |
| 65 | is_control_loop_driving = true; |
| 66 | break; |
| 67 | case TurnButtonUse::kLineFollow: |
| 68 | is_line_following = true; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 73 | if (drivetrain_queue.status.get()) { |
| 74 | if (is_control_loop_driving && !last_is_control_loop_driving_) { |
Austin Schuh | f9202e8 | 2019-03-22 21:55:11 -0700 | [diff] [blame] | 75 | left_goal_ = drivetrain_queue.status->estimated_left_position + |
| 76 | wheel * wheel_multiplier_; |
| 77 | right_goal_ = drivetrain_queue.status->estimated_right_position - |
| 78 | wheel * wheel_multiplier_; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 79 | } |
| 80 | } |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 81 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 82 | const double current_left_goal = |
| 83 | left_goal_ - wheel * wheel_multiplier_ + throttle * 0.3; |
| 84 | const double current_right_goal = |
| 85 | right_goal_ + wheel * wheel_multiplier_ + throttle * 0.3; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 86 | auto new_drivetrain_goal = drivetrain_queue.goal.MakeMessage(); |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 87 | new_drivetrain_goal->wheel = wheel; |
| 88 | new_drivetrain_goal->wheel_velocity = wheel_velocity; |
| 89 | new_drivetrain_goal->wheel_torque = wheel_torque; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 90 | new_drivetrain_goal->throttle = throttle; |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 91 | new_drivetrain_goal->throttle_velocity = throttle_velocity; |
| 92 | new_drivetrain_goal->throttle_torque = throttle_torque; |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 93 | new_drivetrain_goal->highgear = high_gear; |
| 94 | new_drivetrain_goal->quickturn = data.IsPressed(quick_turn_); |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 95 | new_drivetrain_goal->controller_type = |
| 96 | is_line_following ? 3 : (is_control_loop_driving ? 1 : 0); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 97 | new_drivetrain_goal->left_goal = current_left_goal; |
| 98 | new_drivetrain_goal->right_goal = current_right_goal; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 99 | |
| 100 | new_drivetrain_goal->linear.max_velocity = 3.0; |
| 101 | new_drivetrain_goal->linear.max_acceleration = 20.0; |
| 102 | |
| 103 | if (!new_drivetrain_goal.Send()) { |
| 104 | LOG(WARNING, "sending stick values failed\n"); |
| 105 | } |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 106 | |
| 107 | last_is_control_loop_driving_ = is_control_loop_driving; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | DrivetrainInputReader::WheelAndThrottle |
| 111 | SteeringWheelDrivetrainInputReader::GetWheelAndThrottle( |
| 112 | const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 113 | const double wheel = -data.GetAxis(wheel_); |
| 114 | const double throttle = -data.GetAxis(throttle_); |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 115 | |
| 116 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 117 | high_gear_ = default_high_gear_; |
| 118 | } |
| 119 | |
| 120 | if (data.PosEdge(kShiftLow)) { |
| 121 | high_gear_ = false; |
| 122 | } |
| 123 | |
| 124 | if (data.PosEdge(kShiftHigh) || data.PosEdge(kShiftHigh2)) { |
| 125 | high_gear_ = true; |
| 126 | } |
| 127 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 128 | return DrivetrainInputReader::WheelAndThrottle{ |
| 129 | wheel, 0.0, 0.0, throttle, 0.0, 0.0, high_gear_}; |
| 130 | } |
| 131 | |
| 132 | double UnwrappedAxis(const ::aos::input::driver_station::Data &data, |
| 133 | const JoystickAxis &high_bits, |
| 134 | const JoystickAxis &low_bits) { |
| 135 | const float high_bits_data = data.GetAxis(high_bits); |
| 136 | const float low_bits_data = data.GetAxis(low_bits); |
| 137 | const int16_t high_bits_data_int = |
| 138 | (high_bits_data < 0.0f ? high_bits_data * 128.0f |
| 139 | : high_bits_data * 127.0f); |
| 140 | const int16_t low_bits_data_int = |
| 141 | (low_bits_data < 0.0f ? low_bits_data * 128.0f : low_bits_data * 127.0f); |
| 142 | |
| 143 | const uint16_t high_bits_data_uint = |
| 144 | ((static_cast<uint16_t>(high_bits_data_int) & 0xff) + 0x80) & 0xff; |
| 145 | const uint16_t low_bits_data_uint = |
| 146 | ((static_cast<uint16_t>(low_bits_data_int) & 0xff) + 0x80) & 0xff; |
| 147 | |
| 148 | const uint16_t data_uint = (high_bits_data_uint << 8) | low_bits_data_uint; |
| 149 | |
| 150 | const int32_t data_int = static_cast<int32_t>(data_uint) - 0x8000; |
| 151 | |
| 152 | if (data_int < 0) { |
| 153 | return static_cast<double>(data_int) / static_cast<double>(0x8000); |
| 154 | } else { |
| 155 | return static_cast<double>(data_int) / static_cast<double>(0x7fff); |
| 156 | } |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | DrivetrainInputReader::WheelAndThrottle |
| 160 | PistolDrivetrainInputReader::GetWheelAndThrottle( |
| 161 | const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 162 | const double wheel = |
| 163 | -UnwrappedAxis(data, wheel_, wheel_low_); |
| 164 | const double wheel_velocity = |
| 165 | -UnwrappedAxis(data, wheel_velocity_high_, wheel_velocity_low_) * 50.0; |
| 166 | const double wheel_torque = |
| 167 | -UnwrappedAxis(data, wheel_torque_high_, wheel_torque_low_) / 2.0; |
| 168 | |
Austin Schuh | 876b4f0 | 2018-03-10 19:16:59 -0800 | [diff] [blame] | 169 | double throttle = |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 170 | UnwrappedAxis(data, throttle_, throttle_low_); |
| 171 | const double throttle_velocity = |
| 172 | UnwrappedAxis(data, throttle_velocity_high_, throttle_velocity_low_) * 50.0; |
| 173 | const double throttle_torque = |
| 174 | UnwrappedAxis(data, throttle_torque_high_, throttle_torque_low_) / 2.0; |
| 175 | |
Austin Schuh | 876b4f0 | 2018-03-10 19:16:59 -0800 | [diff] [blame] | 176 | // TODO(austin): Deal with haptics here. |
| 177 | if (throttle < 0) { |
| 178 | throttle = ::std::max(-1.0, throttle / 0.7); |
| 179 | } |
| 180 | |
James Kuszmaul | c4eb1b2 | 2019-04-13 15:48:34 -0700 | [diff] [blame] | 181 | if (data.IsPressed(slow_down_)) { |
| 182 | throttle *= 0.5; |
| 183 | } |
| 184 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 185 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 186 | high_gear_ = default_high_gear_; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 189 | if (data.PosEdge(shift_low_)) { |
| 190 | high_gear_ = false; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 191 | } |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 192 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 193 | if (data.PosEdge(shift_high_)) { |
| 194 | high_gear_ = true; |
| 195 | } |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 196 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 197 | return DrivetrainInputReader::WheelAndThrottle{ |
| 198 | wheel, wheel_velocity, wheel_torque, |
| 199 | throttle, throttle_velocity, throttle_torque, |
| 200 | high_gear_}; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | DrivetrainInputReader::WheelAndThrottle |
| 204 | XboxDrivetrainInputReader::GetWheelAndThrottle( |
| 205 | const ::aos::input::driver_station::Data &data) { |
| 206 | // xbox |
| 207 | constexpr double kWheelDeadband = 0.05; |
| 208 | constexpr double kThrottleDeadband = 0.05; |
| 209 | const double wheel = |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 210 | aos::Deadband(-data.GetAxis(wheel_), kWheelDeadband, 1.0); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 211 | |
| 212 | const double unmodified_throttle = |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 213 | aos::Deadband(-data.GetAxis(throttle_), kThrottleDeadband, 1.0); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 214 | |
| 215 | // Apply a sin function that's scaled to make it feel better. |
| 216 | constexpr double throttle_range = M_PI_2 * 0.9; |
| 217 | |
| 218 | double throttle = ::std::sin(throttle_range * unmodified_throttle) / |
| 219 | ::std::sin(throttle_range); |
| 220 | throttle = ::std::sin(throttle_range * throttle) / ::std::sin(throttle_range); |
| 221 | throttle = 2.0 * unmodified_throttle - throttle; |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 222 | return DrivetrainInputReader::WheelAndThrottle{wheel, 0.0, 0.0, throttle, |
| 223 | 0.0, 0.0, true}; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | std::unique_ptr<SteeringWheelDrivetrainInputReader> |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 227 | SteeringWheelDrivetrainInputReader::Make(bool default_high_gear) { |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 228 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
| 229 | const ButtonLocation kQuickTurn(1, 5); |
| 230 | const ButtonLocation kTurn1(1, 7); |
| 231 | const ButtonLocation kTurn2(1, 11); |
| 232 | std::unique_ptr<SteeringWheelDrivetrainInputReader> result( |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 233 | new SteeringWheelDrivetrainInputReader( |
| 234 | kSteeringWheel, kDriveThrottle, kQuickTurn, kTurn1, |
| 235 | TurnButtonUse::kControlLoopDriving, kTurn2, |
| 236 | TurnButtonUse::kControlLoopDriving)); |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 237 | result.get()->set_default_high_gear(default_high_gear); |
| 238 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 239 | return result; |
| 240 | } |
| 241 | |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 242 | std::unique_ptr<PistolDrivetrainInputReader> PistolDrivetrainInputReader::Make( |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 243 | bool default_high_gear, TopButtonUse top_button_use) { |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 244 | // Pistol Grip controller |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 245 | const JoystickAxis kTriggerHigh(1, 1), kTriggerLow(1, 4), |
| 246 | kTriggerVelocityHigh(1, 2), kTriggerVelocityLow(1, 5), |
| 247 | kTriggerTorqueHigh(1, 3), kTriggerTorqueLow(1, 6); |
| 248 | |
| 249 | const JoystickAxis kWheelHigh(2, 1), kWheelLow(2, 4), |
| 250 | kWheelVelocityHigh(2, 2), kWheelVelocityLow(2, 5), kWheelTorqueHigh(2, 3), |
| 251 | kWheelTorqueLow(2, 6); |
| 252 | |
Austin Schuh | e8a54c0 | 2018-03-05 00:25:58 -0800 | [diff] [blame] | 253 | const ButtonLocation kQuickTurn(1, 3); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 254 | |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 255 | const ButtonLocation TopButton(1, 1); |
| 256 | const ButtonLocation SecondButton(1, 2); |
James Kuszmaul | c4eb1b2 | 2019-04-13 15:48:34 -0700 | [diff] [blame] | 257 | const ButtonLocation BottomButton(1, 4); |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 258 | // Non-existant button for nops. |
| 259 | const ButtonLocation DummyButton(1, 10); |
| 260 | |
| 261 | // TODO(james): Make a copy assignment operator for ButtonLocation so we don't |
| 262 | // have to shoehorn in these ternary operators. |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 263 | const ButtonLocation kTurn1 = (top_button_use == TopButtonUse::kLineFollow) |
| 264 | ? SecondButton |
| 265 | : DummyButton; |
| 266 | // Turn2 does closed loop driving. |
| 267 | const ButtonLocation kTurn2 = |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 268 | (top_button_use == TopButtonUse::kLineFollow) ? TopButton : DummyButton; |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 269 | |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 270 | const ButtonLocation kShiftHigh = |
| 271 | (top_button_use == TopButtonUse::kShift) ? TopButton : DummyButton; |
| 272 | const ButtonLocation kShiftLow = |
| 273 | (top_button_use == TopButtonUse::kShift) ? SecondButton : DummyButton; |
| 274 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 275 | std::unique_ptr<PistolDrivetrainInputReader> result( |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 276 | new PistolDrivetrainInputReader( |
| 277 | kWheelHigh, kWheelLow, kTriggerVelocityHigh, kTriggerVelocityLow, |
| 278 | kTriggerTorqueHigh, kTriggerTorqueLow, kTriggerHigh, kTriggerLow, |
| 279 | kWheelVelocityHigh, kWheelVelocityLow, kWheelTorqueHigh, |
James Kuszmaul | c4eb1b2 | 2019-04-13 15:48:34 -0700 | [diff] [blame] | 280 | kWheelTorqueLow, kQuickTurn, kShiftHigh, kShiftLow, kTurn1, kTurn2, |
| 281 | BottomButton)); |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 282 | |
| 283 | result->set_default_high_gear(default_high_gear); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 284 | return result; |
| 285 | } |
| 286 | |
| 287 | std::unique_ptr<XboxDrivetrainInputReader> XboxDrivetrainInputReader::Make() { |
| 288 | // xbox |
| 289 | const JoystickAxis kSteeringWheel(1, 5), kDriveThrottle(1, 2); |
| 290 | const ButtonLocation kQuickTurn(1, 5); |
| 291 | |
| 292 | // Nop |
| 293 | const ButtonLocation kTurn1(1, 1); |
| 294 | const ButtonLocation kTurn2(1, 2); |
| 295 | |
| 296 | std::unique_ptr<XboxDrivetrainInputReader> result( |
| 297 | new XboxDrivetrainInputReader(kSteeringWheel, kDriveThrottle, kQuickTurn, |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 298 | kTurn1, TurnButtonUse::kControlLoopDriving, |
| 299 | kTurn2, |
| 300 | TurnButtonUse::kControlLoopDriving)); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 301 | return result; |
| 302 | } |
| 303 | ::std::unique_ptr<DrivetrainInputReader> DrivetrainInputReader::Make( |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 304 | InputType type, |
Austin Schuh | bcce26a | 2018-03-26 23:41:24 -0700 | [diff] [blame] | 305 | const ::frc971::control_loops::drivetrain::DrivetrainConfig<double> |
| 306 | &dt_config) { |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 307 | std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader; |
| 308 | |
| 309 | using InputType = DrivetrainInputReader::InputType; |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 310 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 311 | switch (type) { |
| 312 | case InputType::kSteeringWheel: |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 313 | drivetrain_input_reader = |
| 314 | SteeringWheelDrivetrainInputReader::Make(dt_config.default_high_gear); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 315 | break; |
| 316 | case InputType::kPistol: |
James Kuszmaul | 8bad241 | 2019-03-10 10:47:56 -0700 | [diff] [blame] | 317 | drivetrain_input_reader = PistolDrivetrainInputReader::Make( |
| 318 | dt_config.default_high_gear, |
| 319 | dt_config.pistol_grip_shift_enables_line_follow |
| 320 | ? PistolDrivetrainInputReader::TopButtonUse::kLineFollow |
| 321 | : PistolDrivetrainInputReader::TopButtonUse::kShift); |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 322 | break; |
| 323 | case InputType::kXbox: |
| 324 | drivetrain_input_reader = XboxDrivetrainInputReader::Make(); |
| 325 | break; |
| 326 | } |
| 327 | return drivetrain_input_reader; |
| 328 | } |
| 329 | |
| 330 | } // namespace input |
| 331 | } // namespace aos |