James Kuszmaul | f254c1a | 2013-03-10 16:31:26 -0700 | [diff] [blame] | 1 | #include "frc971/control_loops/drivetrain/drivetrain.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <sched.h> |
| 5 | #include <cmath> |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 6 | #include <memory> |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 7 | #include "Eigen/Dense" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 8 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 9 | #include "aos/common/logging/logging.h" |
| 10 | #include "aos/common/queue.h" |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 11 | #include "aos/controls/polytope.h" |
| 12 | #include "aos/common/commonmath.h" |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 13 | #include "aos/common/logging/queue_logging.h" |
| 14 | |
James Kuszmaul | f254c1a | 2013-03-10 16:31:26 -0700 | [diff] [blame] | 15 | #include "frc971/control_loops/state_feedback_loop.h" |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 16 | #include "frc971/control_loops/drivetrain/polydrivetrain_cim_plant.h" |
James Kuszmaul | f254c1a | 2013-03-10 16:31:26 -0700 | [diff] [blame] | 17 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 18 | #include "frc971/queues/gyro_angle.q.h" |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 19 | #include "frc971/constants.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 20 | |
| 21 | using frc971::sensors::gyro; |
| 22 | |
| 23 | namespace frc971 { |
| 24 | namespace control_loops { |
| 25 | |
| 26 | // Width of the robot. |
| 27 | const double width = 22.0 / 100.0 * 2.54; |
| 28 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 29 | Eigen::Matrix<double, 2, 1> CoerceGoal(aos::controls::HPolytope<2> ®ion, |
| 30 | const Eigen::Matrix<double, 1, 2> &K, |
| 31 | double w, |
| 32 | const Eigen::Matrix<double, 2, 1> &R) { |
| 33 | if (region.IsInside(R)) { |
| 34 | return R; |
| 35 | } |
| 36 | Eigen::Matrix<double, 2, 1> parallel_vector; |
| 37 | Eigen::Matrix<double, 2, 1> perpendicular_vector; |
| 38 | perpendicular_vector = K.transpose().normalized(); |
| 39 | parallel_vector << perpendicular_vector(1, 0), -perpendicular_vector(0, 0); |
| 40 | |
| 41 | aos::controls::HPolytope<1> t_poly( |
| 42 | region.H() * parallel_vector, |
| 43 | region.k() - region.H() * perpendicular_vector * w); |
| 44 | |
| 45 | Eigen::Matrix<double, 1, Eigen::Dynamic> vertices = t_poly.Vertices(); |
| 46 | if (vertices.innerSize() > 0) { |
| 47 | double min_distance_sqr = 0; |
| 48 | Eigen::Matrix<double, 2, 1> closest_point; |
| 49 | for (int i = 0; i < vertices.innerSize(); i++) { |
| 50 | Eigen::Matrix<double, 2, 1> point; |
| 51 | point = parallel_vector * vertices(0, i) + perpendicular_vector * w; |
| 52 | const double length = (R - point).squaredNorm(); |
| 53 | if (i == 0 || length < min_distance_sqr) { |
| 54 | closest_point = point; |
| 55 | min_distance_sqr = length; |
| 56 | } |
| 57 | } |
| 58 | return closest_point; |
| 59 | } else { |
| 60 | Eigen::Matrix<double, 2, Eigen::Dynamic> region_vertices = |
| 61 | region.Vertices(); |
Brian Silverman | 41abe01 | 2014-02-08 18:25:02 -0800 | [diff] [blame] | 62 | double min_distance = INFINITY; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 63 | int closest_i = 0; |
| 64 | for (int i = 0; i < region_vertices.outerSize(); i++) { |
| 65 | const double length = ::std::abs( |
| 66 | (perpendicular_vector.transpose() * (region_vertices.col(i)))(0, 0)); |
| 67 | if (i == 0 || length < min_distance) { |
| 68 | closest_i = i; |
| 69 | min_distance = length; |
| 70 | } |
| 71 | } |
| 72 | return region_vertices.col(closest_i); |
| 73 | } |
| 74 | } |
| 75 | |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 76 | class DrivetrainMotorsSS { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 77 | public: |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 78 | DrivetrainMotorsSS() |
| 79 | : loop_(new StateFeedbackLoop<4, 2, 2>( |
| 80 | constants::GetValues().make_drivetrain_loop())) { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 81 | _offset = 0; |
| 82 | _integral_offset = 0; |
| 83 | _left_goal = 0.0; |
| 84 | _right_goal = 0.0; |
| 85 | _raw_left = 0.0; |
| 86 | _raw_right = 0.0; |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 87 | _control_loop_driving = false; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 88 | } |
| 89 | void SetGoal(double left, double left_velocity, double right, double right_velocity) { |
| 90 | _left_goal = left; |
| 91 | _right_goal = right; |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 92 | loop_->R << left, left_velocity, right, right_velocity; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 93 | } |
| 94 | void SetRawPosition(double left, double right) { |
| 95 | _raw_right = right; |
| 96 | _raw_left = left; |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 97 | Eigen::Matrix<double, 2, 1> Y; |
| 98 | Y << left, right; |
| 99 | loop_->Correct(Y); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 100 | } |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 101 | void SetPosition( |
| 102 | double left, double right, double gyro, bool control_loop_driving) { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 103 | // Decay the offset quickly because this gyro is great. |
| 104 | _offset = (0.25) * (right - left - gyro * width) / 2.0 + 0.75 * _offset; |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 105 | //const double angle_error = (_right_goal - _left_goal) / width - (_raw_right - _offset - _raw_left - _offset) / width; |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 106 | // TODO(aschuh): Add in the gyro. |
| 107 | _integral_offset = 0.0; |
| 108 | _offset = 0.0; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 109 | _gyro = gyro; |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 110 | _control_loop_driving = control_loop_driving; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 111 | SetRawPosition(left, right); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 112 | } |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 113 | |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 114 | void Update(bool stop_motors) { |
| 115 | loop_->Update(stop_motors); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 118 | void SendMotors(Drivetrain::Output *output) { |
| 119 | if (output) { |
| 120 | output->left_voltage = loop_->U(0, 0); |
| 121 | output->right_voltage = loop_->U(1, 0); |
brians | 8ad7405 | 2013-03-16 21:04:51 +0000 | [diff] [blame] | 122 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 123 | } |
| 124 | void PrintMotors() const { |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 125 | ::Eigen::Matrix<double, 4, 1> E = loop_->R - loop_->X_hat; |
| 126 | LOG(DEBUG, "E[0, 0]: %f E[1, 0] %f E[2, 0] %f E[3, 0] %f\n", E(0, 0), E(1, 0), E(2, 0), E(3, 0)); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | private: |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 130 | ::std::unique_ptr<StateFeedbackLoop<4, 2, 2>> loop_; |
| 131 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 132 | double _integral_offset; |
| 133 | double _offset; |
| 134 | double _gyro; |
| 135 | double _left_goal; |
| 136 | double _right_goal; |
| 137 | double _raw_left; |
| 138 | double _raw_right; |
Austin Schuh | 4352ac6 | 2013-03-19 06:23:16 +0000 | [diff] [blame] | 139 | bool _control_loop_driving; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 142 | class PolyDrivetrain { |
| 143 | public: |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 144 | |
| 145 | enum Gear { |
| 146 | HIGH, |
| 147 | LOW, |
| 148 | SHIFTING_UP, |
| 149 | SHIFTING_DOWN |
| 150 | }; |
| 151 | // Stall Torque in N m |
| 152 | static constexpr double kStallTorque = 2.42; |
| 153 | // Stall Current in Amps |
| 154 | static constexpr double kStallCurrent = 133; |
| 155 | // Free Speed in RPM. Used number from last year. |
| 156 | static constexpr double kFreeSpeed = 4650.0; |
| 157 | // Free Current in Amps |
| 158 | static constexpr double kFreeCurrent = 2.7; |
| 159 | // Moment of inertia of the drivetrain in kg m^2 |
| 160 | // Just borrowed from last year. |
| 161 | static constexpr double J = 6.4; |
| 162 | // Mass of the robot, in kg. |
| 163 | static constexpr double m = 68; |
| 164 | // Radius of the robot, in meters (from last year). |
| 165 | static constexpr double rb = 0.617998644 / 2.0; |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 166 | static constexpr double kWheelRadius = 0.04445; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 167 | // Resistance of the motor, divided by the number of motors. |
| 168 | static constexpr double kR = (12.0 / kStallCurrent / 4 + 0.03) / (0.93 * 0.93); |
| 169 | // Motor velocity constant |
| 170 | static constexpr double Kv = |
| 171 | ((kFreeSpeed / 60.0 * 2.0 * M_PI) / (12.0 - kR * kFreeCurrent)); |
| 172 | // Torque constant |
| 173 | static constexpr double Kt = kStallTorque / kStallCurrent; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 174 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 175 | PolyDrivetrain() |
| 176 | : U_Poly_((Eigen::Matrix<double, 4, 2>() << /*[[*/ 1, 0 /*]*/, |
| 177 | /*[*/ -1, 0 /*]*/, |
| 178 | /*[*/ 0, 1 /*]*/, |
| 179 | /*[*/ 0, -1 /*]]*/).finished(), |
| 180 | (Eigen::Matrix<double, 4, 1>() << /*[[*/ 12 /*]*/, |
| 181 | /*[*/ 12 /*]*/, |
| 182 | /*[*/ 12 /*]*/, |
| 183 | /*[*/ 12 /*]]*/).finished()), |
Brian Silverman | 2c590c3 | 2013-11-04 18:08:54 -0800 | [diff] [blame] | 184 | loop_(new StateFeedbackLoop<2, 2, 2>( |
| 185 | constants::GetValues().make_v_drivetrain_loop())), |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 186 | left_cim_(new StateFeedbackLoop<1, 1, 1>(MakeCIMLoop())), |
| 187 | right_cim_(new StateFeedbackLoop<1, 1, 1>(MakeCIMLoop())), |
| 188 | ttrust_(1.1), |
| 189 | wheel_(0.0), |
| 190 | throttle_(0.0), |
| 191 | quickturn_(false), |
| 192 | stale_count_(0), |
| 193 | position_time_delta_(0.01), |
| 194 | left_gear_(LOW), |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 195 | right_gear_(LOW), |
| 196 | counter_(0) { |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 197 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 198 | last_position_.Zero(); |
| 199 | position_.Zero(); |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 200 | } |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 201 | static bool IsInGear(Gear gear) { return gear == LOW || gear == HIGH; } |
| 202 | |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 203 | static double MotorSpeed(const constants::ShifterHallEffect &hall_effect, |
| 204 | double shifter_position, double velocity) { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 205 | // TODO(austin): G_high, G_low and kWheelRadius |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 206 | const double avg_hall_effect = |
| 207 | (hall_effect.clear_high + hall_effect.clear_low) / 2.0; |
| 208 | |
| 209 | if (shifter_position > avg_hall_effect) { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 210 | return velocity / constants::GetValues().high_gear_ratio / kWheelRadius; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 211 | } else { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 212 | return velocity / constants::GetValues().low_gear_ratio / kWheelRadius; |
| 213 | } |
| 214 | } |
| 215 | |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 216 | Gear ComputeGear(const constants::ShifterHallEffect &hall_effect, |
| 217 | double velocity, Gear current) { |
| 218 | const double low_omega = MotorSpeed(hall_effect, 0.0, ::std::abs(velocity)); |
| 219 | const double high_omega = |
| 220 | MotorSpeed(hall_effect, 1.0, ::std::abs(velocity)); |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 221 | |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 222 | double high_torque = ((12.0 - high_omega / Kv) * Kt / kR); |
| 223 | double low_torque = ((12.0 - low_omega / Kv) * Kt / kR); |
| 224 | double high_power = high_torque * high_omega; |
| 225 | double low_power = low_torque * low_omega; |
Brian Silverman | 55a930b | 2013-11-04 20:59:00 -0800 | [diff] [blame] | 226 | |
| 227 | // TODO(aschuh): Do this right! |
| 228 | if ((current == HIGH || high_power > low_power + 160) && |
| 229 | ::std::abs(velocity) > 0.14) { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 230 | return HIGH; |
| 231 | } else { |
| 232 | return LOW; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 236 | void SetGoal(double wheel, double throttle, bool quickturn, bool highgear) { |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 237 | const double kWheelNonLinearity = 0.3; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 238 | // Apply a sin function that's scaled to make it feel better. |
| 239 | const double angular_range = M_PI_2 * kWheelNonLinearity; |
| 240 | wheel_ = sin(angular_range * wheel) / sin(angular_range); |
| 241 | wheel_ = sin(angular_range * wheel_) / sin(angular_range); |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 242 | quickturn_ = quickturn; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 243 | |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 244 | static const double kThrottleDeadband = 0.05; |
| 245 | if (::std::abs(throttle) < kThrottleDeadband) { |
| 246 | throttle_ = 0; |
| 247 | } else { |
| 248 | throttle_ = copysign((::std::abs(throttle) - kThrottleDeadband) / |
| 249 | (1.0 - kThrottleDeadband), throttle); |
| 250 | } |
| 251 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 252 | // TODO(austin): Fix the upshift logic to include states. |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 253 | Gear requested_gear; |
Brian Silverman | 55a930b | 2013-11-04 20:59:00 -0800 | [diff] [blame] | 254 | if (false) { |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 255 | const auto &values = constants::GetValues(); |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 256 | const double current_left_velocity = |
| 257 | (position_.left_encoder - last_position_.left_encoder) / |
| 258 | position_time_delta_; |
| 259 | const double current_right_velocity = |
| 260 | (position_.right_encoder - last_position_.right_encoder) / |
| 261 | position_time_delta_; |
| 262 | |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 263 | Gear left_requested = |
| 264 | ComputeGear(values.left_drive, current_left_velocity, left_gear_); |
| 265 | Gear right_requested = |
| 266 | ComputeGear(values.right_drive, current_right_velocity, right_gear_); |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 267 | requested_gear = |
| 268 | (left_requested == HIGH || right_requested == HIGH) ? HIGH : LOW; |
| 269 | } else { |
| 270 | requested_gear = highgear ? HIGH : LOW; |
| 271 | } |
| 272 | |
| 273 | const Gear shift_up = |
| 274 | constants::GetValues().clutch_transmission ? HIGH : SHIFTING_UP; |
| 275 | const Gear shift_down = |
| 276 | constants::GetValues().clutch_transmission ? LOW : SHIFTING_DOWN; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 277 | |
| 278 | if (left_gear_ != requested_gear) { |
| 279 | if (IsInGear(left_gear_)) { |
| 280 | if (requested_gear == HIGH) { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 281 | left_gear_ = shift_up; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 282 | } else { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 283 | left_gear_ = shift_down; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 284 | } |
Brian Silverman | 55a930b | 2013-11-04 20:59:00 -0800 | [diff] [blame] | 285 | } else { |
| 286 | if (requested_gear == HIGH && left_gear_ == SHIFTING_DOWN) { |
| 287 | left_gear_ = SHIFTING_UP; |
| 288 | } else if (requested_gear == LOW && left_gear_ == SHIFTING_UP) { |
| 289 | left_gear_ = SHIFTING_DOWN; |
| 290 | } |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | if (right_gear_ != requested_gear) { |
| 294 | if (IsInGear(right_gear_)) { |
| 295 | if (requested_gear == HIGH) { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 296 | right_gear_ = shift_up; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 297 | } else { |
Brian Silverman | 1a6590d | 2013-11-04 14:46:46 -0800 | [diff] [blame] | 298 | right_gear_ = shift_down; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 299 | } |
Brian Silverman | 55a930b | 2013-11-04 20:59:00 -0800 | [diff] [blame] | 300 | } else { |
| 301 | if (requested_gear == HIGH && right_gear_ == SHIFTING_DOWN) { |
| 302 | right_gear_ = SHIFTING_UP; |
| 303 | } else if (requested_gear == LOW && right_gear_ == SHIFTING_UP) { |
| 304 | right_gear_ = SHIFTING_DOWN; |
| 305 | } |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 306 | } |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 309 | void SetPosition(const Drivetrain::Position *position) { |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 310 | const auto &values = constants::GetValues(); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 311 | if (position == NULL) { |
| 312 | ++stale_count_; |
| 313 | } else { |
| 314 | last_position_ = position_; |
| 315 | position_ = *position; |
| 316 | position_time_delta_ = (stale_count_ + 1) * 0.01; |
| 317 | stale_count_ = 0; |
| 318 | } |
| 319 | |
| 320 | if (position) { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 321 | GearLogging gear_logging; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 322 | // Switch to the correct controller. |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 323 | const double left_middle_shifter_position = |
| 324 | (values.left_drive.clear_high + values.left_drive.clear_low) / 2.0; |
| 325 | const double right_middle_shifter_position = |
| 326 | (values.right_drive.clear_high + values.right_drive.clear_low) / 2.0; |
| 327 | |
| 328 | if (position->left_shifter_position < left_middle_shifter_position) { |
| 329 | if (position->right_shifter_position < right_middle_shifter_position || |
| 330 | right_gear_ == LOW) { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 331 | gear_logging.left_loop_high = false; |
| 332 | gear_logging.right_loop_high = false; |
| 333 | loop_->set_controller_index(gear_logging.controller_index = 0); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 334 | } else { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 335 | gear_logging.left_loop_high = false; |
| 336 | gear_logging.right_loop_high = true; |
| 337 | loop_->set_controller_index(gear_logging.controller_index = 1); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 338 | } |
| 339 | } else { |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 340 | if (position->right_shifter_position < right_middle_shifter_position || |
| 341 | left_gear_ == LOW) { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 342 | gear_logging.left_loop_high = true; |
| 343 | gear_logging.right_loop_high = false; |
| 344 | loop_->set_controller_index(gear_logging.controller_index = 2); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 345 | } else { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 346 | gear_logging.left_loop_high = true; |
| 347 | gear_logging.right_loop_high = true; |
| 348 | loop_->set_controller_index(gear_logging.controller_index = 3); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 351 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 352 | // TODO(austin): Constants. |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 353 | if (position->left_shifter_position > values.left_drive.clear_high && left_gear_ == SHIFTING_UP) { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 354 | left_gear_ = HIGH; |
| 355 | } |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 356 | if (position->left_shifter_position < values.left_drive.clear_low && left_gear_ == SHIFTING_DOWN) { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 357 | left_gear_ = LOW; |
| 358 | } |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 359 | if (position->right_shifter_position > values.right_drive.clear_high && right_gear_ == SHIFTING_UP) { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 360 | right_gear_ = HIGH; |
| 361 | } |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 362 | if (position->right_shifter_position < values.right_drive.clear_low && right_gear_ == SHIFTING_DOWN) { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 363 | right_gear_ = LOW; |
| 364 | } |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 365 | |
| 366 | gear_logging.left_state = left_gear_; |
| 367 | gear_logging.right_state = right_gear_; |
| 368 | LOG_STRUCT(DEBUG, "state", gear_logging); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 372 | double FilterVelocity(double throttle) { |
| 373 | const Eigen::Matrix<double, 2, 2> FF = |
| 374 | loop_->B().inverse() * |
| 375 | (Eigen::Matrix<double, 2, 2>::Identity() - loop_->A()); |
| 376 | |
| 377 | constexpr int kHighGearController = 3; |
| 378 | const Eigen::Matrix<double, 2, 2> FF_high = |
| 379 | loop_->controller(kHighGearController).plant.B.inverse() * |
| 380 | (Eigen::Matrix<double, 2, 2>::Identity() - |
| 381 | loop_->controller(kHighGearController).plant.A); |
| 382 | |
| 383 | ::Eigen::Matrix<double, 1, 2> FF_sum = FF.colwise().sum(); |
| 384 | int min_FF_sum_index; |
| 385 | const double min_FF_sum = FF_sum.minCoeff(&min_FF_sum_index); |
| 386 | const double min_K_sum = loop_->K().col(min_FF_sum_index).sum(); |
| 387 | const double high_min_FF_sum = FF_high.col(0).sum(); |
| 388 | |
| 389 | const double adjusted_ff_voltage = ::aos::Clip( |
| 390 | throttle * 12.0 * min_FF_sum / high_min_FF_sum, -12.0, 12.0); |
| 391 | return ((adjusted_ff_voltage + |
| 392 | ttrust_ * min_K_sum * (loop_->X_hat(0, 0) + loop_->X_hat(1, 0)) / |
| 393 | 2.0) / |
| 394 | (ttrust_ * min_K_sum + min_FF_sum)); |
| 395 | } |
| 396 | |
Brian Silverman | 718b1d7 | 2013-10-28 16:22:45 -0700 | [diff] [blame] | 397 | double MaxVelocity() { |
| 398 | const Eigen::Matrix<double, 2, 2> FF = |
| 399 | loop_->B().inverse() * |
| 400 | (Eigen::Matrix<double, 2, 2>::Identity() - loop_->A()); |
| 401 | |
| 402 | constexpr int kHighGearController = 3; |
| 403 | const Eigen::Matrix<double, 2, 2> FF_high = |
| 404 | loop_->controller(kHighGearController).plant.B.inverse() * |
| 405 | (Eigen::Matrix<double, 2, 2>::Identity() - |
| 406 | loop_->controller(kHighGearController).plant.A); |
| 407 | |
| 408 | ::Eigen::Matrix<double, 1, 2> FF_sum = FF.colwise().sum(); |
| 409 | int min_FF_sum_index; |
| 410 | const double min_FF_sum = FF_sum.minCoeff(&min_FF_sum_index); |
| 411 | //const double min_K_sum = loop_->K().col(min_FF_sum_index).sum(); |
| 412 | const double high_min_FF_sum = FF_high.col(0).sum(); |
| 413 | |
| 414 | const double adjusted_ff_voltage = ::aos::Clip( |
| 415 | 12.0 * min_FF_sum / high_min_FF_sum, -12.0, 12.0); |
| 416 | return adjusted_ff_voltage / min_FF_sum; |
| 417 | } |
| 418 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 419 | void Update() { |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 420 | const auto &values = constants::GetValues(); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 421 | // TODO(austin): Observer for the current velocity instead of difference |
| 422 | // calculations. |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 423 | ++counter_; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 424 | const double current_left_velocity = |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 425 | (position_.left_encoder - last_position_.left_encoder) / |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 426 | position_time_delta_; |
| 427 | const double current_right_velocity = |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 428 | (position_.right_encoder - last_position_.right_encoder) / |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 429 | position_time_delta_; |
| 430 | const double left_motor_speed = |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 431 | MotorSpeed(values.left_drive, position_.left_shifter_position, |
| 432 | current_left_velocity); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 433 | const double right_motor_speed = |
Austin Schuh | 78d5546 | 2014-02-23 01:39:30 -0800 | [diff] [blame] | 434 | MotorSpeed(values.right_drive, position_.right_shifter_position, |
| 435 | current_right_velocity); |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 436 | |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 437 | { |
| 438 | CIMLogging logging; |
| 439 | |
| 440 | // Reset the CIM model to the current conditions to be ready for when we |
| 441 | // shift. |
| 442 | if (IsInGear(left_gear_)) { |
| 443 | logging.left_in_gear = true; |
| 444 | left_cim_->X_hat(0, 0) = left_motor_speed; |
| 445 | } else { |
| 446 | logging.left_in_gear = false; |
| 447 | } |
| 448 | logging.left_motor_speed = left_motor_speed; |
| 449 | logging.left_velocity = current_left_velocity; |
| 450 | if (IsInGear(right_gear_)) { |
| 451 | logging.right_in_gear = true; |
| 452 | right_cim_->X_hat(0, 0) = right_motor_speed; |
| 453 | } else { |
| 454 | logging.right_in_gear = false; |
| 455 | } |
| 456 | logging.right_motor_speed = right_motor_speed; |
| 457 | logging.right_velocity = current_right_velocity; |
| 458 | |
| 459 | LOG_STRUCT(DEBUG, "currently", logging); |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 460 | } |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 461 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 462 | if (IsInGear(left_gear_) && IsInGear(right_gear_)) { |
| 463 | // FF * X = U (steady state) |
| 464 | const Eigen::Matrix<double, 2, 2> FF = |
| 465 | loop_->B().inverse() * |
| 466 | (Eigen::Matrix<double, 2, 2>::Identity() - loop_->A()); |
| 467 | |
| 468 | // Invert the plant to figure out how the velocity filter would have to |
| 469 | // work |
| 470 | // out in order to filter out the forwards negative inertia. |
| 471 | // This math assumes that the left and right power and velocity are |
| 472 | // equals, |
| 473 | // and that the plant is the same on the left and right. |
| 474 | const double fvel = FilterVelocity(throttle_); |
| 475 | |
| 476 | const double sign_svel = wheel_ * ((fvel > 0.0) ? 1.0 : -1.0); |
| 477 | double steering_velocity; |
| 478 | if (quickturn_) { |
| 479 | steering_velocity = wheel_ * MaxVelocity(); |
| 480 | } else { |
| 481 | steering_velocity = ::std::abs(fvel) * wheel_; |
| 482 | } |
| 483 | const double left_velocity = fvel - steering_velocity; |
| 484 | const double right_velocity = fvel + steering_velocity; |
| 485 | |
| 486 | // Integrate velocity to get the position. |
| 487 | // This position is used to get integral control. |
| 488 | loop_->R << left_velocity, right_velocity; |
| 489 | |
| 490 | if (!quickturn_) { |
| 491 | // K * R = w |
| 492 | Eigen::Matrix<double, 1, 2> equality_k; |
| 493 | equality_k << 1 + sign_svel, -(1 - sign_svel); |
| 494 | const double equality_w = 0.0; |
| 495 | |
| 496 | // Construct a constraint on R by manipulating the constraint on U |
| 497 | ::aos::controls::HPolytope<2> R_poly = ::aos::controls::HPolytope<2>( |
| 498 | U_Poly_.H() * (loop_->K() + FF), |
| 499 | U_Poly_.k() + U_Poly_.H() * loop_->K() * loop_->X_hat); |
| 500 | |
| 501 | // Limit R back inside the box. |
| 502 | loop_->R = CoerceGoal(R_poly, equality_k, equality_w, loop_->R); |
| 503 | } |
| 504 | |
| 505 | const Eigen::Matrix<double, 2, 1> FF_volts = FF * loop_->R; |
| 506 | const Eigen::Matrix<double, 2, 1> U_ideal = |
| 507 | loop_->K() * (loop_->R - loop_->X_hat) + FF_volts; |
| 508 | |
| 509 | for (int i = 0; i < 2; i++) { |
| 510 | loop_->U[i] = ::aos::Clip(U_ideal[i], -12, 12); |
| 511 | } |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 512 | |
| 513 | // TODO(austin): Model this better. |
| 514 | // TODO(austin): Feed back? |
| 515 | loop_->X_hat = loop_->A() * loop_->X_hat + loop_->B() * loop_->U; |
Brian Silverman | 718b1d7 | 2013-10-28 16:22:45 -0700 | [diff] [blame] | 516 | } else { |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 517 | // Any motor is not in gear. Speed match. |
| 518 | ::Eigen::Matrix<double, 1, 1> R_left; |
| 519 | R_left(0, 0) = left_motor_speed; |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 520 | const double wiggle = |
| 521 | (static_cast<double>((counter_ % 4) / 2) - 0.5) * 3.5; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 522 | |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 523 | loop_->U(0, 0) = |
| 524 | ::aos::Clip((R_left / Kv)(0, 0) + wiggle, -position_.battery_voltage, |
| 525 | position_.battery_voltage); |
| 526 | right_cim_->X_hat = right_cim_->A() * right_cim_->X_hat + |
| 527 | right_cim_->B() * loop_->U(0, 0); |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 528 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 529 | ::Eigen::Matrix<double, 1, 1> R_right; |
| 530 | R_right(0, 0) = right_motor_speed; |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 531 | loop_->U(1, 0) = |
| 532 | ::aos::Clip((R_right / Kv)(0, 0) + wiggle, -position_.battery_voltage, |
| 533 | position_.battery_voltage); |
| 534 | right_cim_->X_hat = right_cim_->A() * right_cim_->X_hat + |
| 535 | right_cim_->B() * loop_->U(1, 0); |
| 536 | loop_->U *= 12.0 / position_.battery_voltage; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 537 | } |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void SendMotors(Drivetrain::Output *output) { |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 541 | if (output != NULL) { |
| 542 | output->left_voltage = loop_->U(0, 0); |
| 543 | output->right_voltage = loop_->U(1, 0); |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 544 | output->left_high = left_gear_ == HIGH || left_gear_ == SHIFTING_UP; |
| 545 | output->right_high = right_gear_ == HIGH || right_gear_ == SHIFTING_UP; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | private: |
| 550 | const ::aos::controls::HPolytope<2> U_Poly_; |
| 551 | |
| 552 | ::std::unique_ptr<StateFeedbackLoop<2, 2, 2>> loop_; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 553 | ::std::unique_ptr<StateFeedbackLoop<1, 1, 1>> left_cim_; |
| 554 | ::std::unique_ptr<StateFeedbackLoop<1, 1, 1>> right_cim_; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 555 | |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 556 | const double ttrust_; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 557 | double wheel_; |
| 558 | double throttle_; |
| 559 | bool quickturn_; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 560 | int stale_count_; |
| 561 | double position_time_delta_; |
| 562 | Gear left_gear_; |
| 563 | Gear right_gear_; |
| 564 | Drivetrain::Position last_position_; |
| 565 | Drivetrain::Position position_; |
Brian Silverman | de8fd55 | 2013-11-03 15:53:42 -0800 | [diff] [blame] | 566 | int counter_; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 567 | }; |
Brian Silverman | cec3c8d | 2013-12-20 21:04:55 -0800 | [diff] [blame] | 568 | constexpr double PolyDrivetrain::kStallTorque; |
| 569 | constexpr double PolyDrivetrain::kStallCurrent; |
| 570 | constexpr double PolyDrivetrain::kFreeSpeed; |
| 571 | constexpr double PolyDrivetrain::kFreeCurrent; |
| 572 | constexpr double PolyDrivetrain::J; |
| 573 | constexpr double PolyDrivetrain::m; |
| 574 | constexpr double PolyDrivetrain::rb; |
| 575 | constexpr double PolyDrivetrain::kWheelRadius; |
| 576 | constexpr double PolyDrivetrain::kR; |
| 577 | constexpr double PolyDrivetrain::Kv; |
| 578 | constexpr double PolyDrivetrain::Kt; |
| 579 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 580 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 581 | void DrivetrainLoop::RunIteration(const Drivetrain::Goal *goal, |
| 582 | const Drivetrain::Position *position, |
| 583 | Drivetrain::Output *output, |
| 584 | Drivetrain::Status * /*status*/) { |
| 585 | // TODO(aschuh): These should be members of the class. |
| 586 | static DrivetrainMotorsSS dt_closedloop; |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 587 | static PolyDrivetrain dt_openloop; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 588 | |
| 589 | bool bad_pos = false; |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 590 | if (position == nullptr) { |
Brian Silverman | 9c9ab42 | 2014-02-25 13:42:53 -0800 | [diff] [blame^] | 591 | LOG_INTERVAL(no_position_); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 592 | bad_pos = true; |
| 593 | } |
Brian Silverman | 9c9ab42 | 2014-02-25 13:42:53 -0800 | [diff] [blame^] | 594 | no_position_.Print(); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 595 | |
| 596 | double wheel = goal->steering; |
| 597 | double throttle = goal->throttle; |
| 598 | bool quickturn = goal->quickturn; |
| 599 | bool highgear = goal->highgear; |
| 600 | |
| 601 | bool control_loop_driving = goal->control_loop_driving; |
| 602 | double left_goal = goal->left_goal; |
| 603 | double right_goal = goal->right_goal; |
| 604 | |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 605 | dt_closedloop.SetGoal(left_goal, goal->left_velocity_goal, right_goal, |
| 606 | goal->right_velocity_goal); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 607 | if (!bad_pos) { |
| 608 | const double left_encoder = position->left_encoder; |
| 609 | const double right_encoder = position->right_encoder; |
| 610 | if (gyro.FetchLatest()) { |
Brian Silverman | 61e41fd | 2014-02-16 19:08:50 -0800 | [diff] [blame] | 611 | LOG_STRUCT(DEBUG, "using", *gyro); |
Austin Schuh | 2054f5f | 2013-10-27 14:54:10 -0700 | [diff] [blame] | 612 | dt_closedloop.SetPosition(left_encoder, right_encoder, gyro->angle, |
| 613 | control_loop_driving); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 614 | } else { |
| 615 | dt_closedloop.SetRawPosition(left_encoder, right_encoder); |
| 616 | } |
| 617 | } |
Austin Schuh | 427b370 | 2013-11-02 13:44:09 -0700 | [diff] [blame] | 618 | dt_openloop.SetPosition(position); |
Austin Schuh | f9286cd | 2014-02-11 00:51:09 -0800 | [diff] [blame] | 619 | dt_closedloop.Update(output == NULL); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 620 | dt_openloop.SetGoal(wheel, throttle, quickturn, highgear); |
| 621 | dt_openloop.Update(); |
Brian Silverman | 2845c4c | 2013-03-16 19:54:08 -0700 | [diff] [blame] | 622 | if (control_loop_driving) { |
| 623 | dt_closedloop.SendMotors(output); |
| 624 | } else { |
| 625 | dt_openloop.SendMotors(output); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | } // namespace control_loops |
| 630 | } // namespace frc971 |