joe | 93778a6 | 2014-02-15 13:22:14 -0800 | [diff] [blame] | 1 | #include "frc971/control_loops/shooter/shooter.h" |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #include <algorithm> |
| 6 | |
| 7 | #include "aos/common/control_loop/control_loops.q.h" |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 8 | #include "aos/common/control_loop/control_loops.q.h" |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 9 | #include "aos/common/logging/logging.h" |
| 10 | |
| 11 | #include "frc971/constants.h" |
joe | 93778a6 | 2014-02-15 13:22:14 -0800 | [diff] [blame] | 12 | #include "frc971/control_loops/shooter/shooter_motor_plant.h" |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 13 | |
| 14 | namespace frc971 { |
| 15 | namespace control_loops { |
| 16 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 17 | using ::aos::time::Time; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 18 | |
| 19 | void ZeroedStateFeedbackLoop::CapU() { |
| 20 | const double old_voltage = voltage_; |
| 21 | voltage_ += U(0, 0); |
| 22 | |
| 23 | uncapped_voltage_ = voltage_; |
| 24 | |
| 25 | double limit = zeroing_state() != UNKNOWN_POSITION ? 12.0 : kZeroingMaxVoltage; |
| 26 | |
| 27 | // Make sure that reality and the observer can't get too far off. There is a |
| 28 | // delay by one cycle between the applied voltage and X_hat(2, 0), so compare |
| 29 | // against last cycle's voltage. |
| 30 | if (X_hat(2, 0) > last_voltage_ + 2.0) { |
| 31 | voltage_ -= X_hat(2, 0) - (last_voltage_ + 2.0); |
| 32 | LOG(DEBUG, "X_hat(2, 0) = %f\n", X_hat(2, 0)); |
| 33 | } else if (X_hat(2, 0) < last_voltage_ -2.0) { |
| 34 | voltage_ += X_hat(2, 0) - (last_voltage_ - 2.0); |
| 35 | LOG(DEBUG, "X_hat(2, 0) = %f\n", X_hat(2, 0)); |
| 36 | } |
| 37 | |
| 38 | voltage_ = std::min(limit, voltage_); |
| 39 | voltage_ = std::max(-limit, voltage_); |
| 40 | U(0, 0) = voltage_ - old_voltage; |
| 41 | LOG(DEBUG, "abc %f\n", X_hat(2, 0) - voltage_); |
| 42 | LOG(DEBUG, "error %f\n", X_hat(0, 0) - R(0, 0)); |
| 43 | |
| 44 | last_voltage_ = voltage_; |
| 45 | } |
| 46 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 47 | ShooterMotor::ShooterMotor(control_loops::ShooterGroup *my_shooter) |
| 48 | : aos::control_loops::ControlLoop<control_loops::ShooterGroup>(my_shooter), |
| 49 | shooter_(MakeShooterLoop()), |
| 50 | calibration_position_(0.0), |
| 51 | state_(STATE_INITIALIZE), |
| 52 | loading_problem_end_time_(0,0), |
| 53 | shooter_brake_set_time_(0,0), |
| 54 | prepare_fire_end_time_(0,0), |
| 55 | shot_end_time_(0,0), |
| 56 | cycles_not_moved_(0) { } |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 57 | |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 58 | |
| 59 | // Positive is out, and positive power is out. |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 60 | void ShooterMotor::RunIteration( |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 61 | const control_loops::ShooterGroup::Goal *goal, |
| 62 | const control_loops::ShooterGroup::Position *position, |
| 63 | control_loops::ShooterGroup::Output *output, |
| 64 | control_loops::ShooterGroup::Status * status) { |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 65 | constexpr double dt = 0.01; |
| 66 | |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 67 | // we must always have these or we have issues. |
| 68 | if (goal == NULL || status == NULL) { |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 69 | if (output) output->voltage = 0; |
| 70 | LOG(ERROR, "Thought I would just check for null and die.\n"); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 71 | return; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 72 | } |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 73 | |
| 74 | // Disable the motors now so that all early returns will return with the |
| 75 | // motors disabled. |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 76 | if (output) output->voltage = 0; |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 77 | |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 78 | const frc971::constants::Values &values = constants::GetValues(); |
| 79 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 80 | double real_position = position->position - calibration_position_; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 81 | |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 82 | // don't even let the control loops run |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 83 | bool shooter_loop_disable = false; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 84 | |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 85 | // adds voltage to take up slack in gears before shot |
| 86 | bool apply_some_voltage = false; |
| 87 | |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 88 | switch (state_) { |
| 89 | case STATE_INITIALIZE: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 90 | // start off with the assumption that we are at the value |
| 91 | // futhest back given our sensors |
| 92 | if (position && position->pusher_distal_hall_effect){ |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 93 | calibration_position_ = position->position - |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 94 | values.shooter.pusher_distal.lower_limit; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 95 | } else if (position && position->pusher_proximal_hall_effect) { |
| 96 | calibration_position_ = position->position - |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 97 | values.shooter.pusher_proximal.lower_limit; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 98 | } else { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 99 | calibration_position_ = values.shooter_total_length; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 102 | state_ = STATE_REQUEST_LOAD; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 103 | |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 104 | // zero out initial goal |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 105 | shooter_.SetGoalPosition(0.0, 0.0); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 106 | if (position) { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 107 | output->latch_piston = position->plunger_back_hall_effect; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 108 | } else { |
| 109 | // we don't know what is going on so just close the latch to be safe |
| 110 | output->latch_piston = true; |
| 111 | } |
| 112 | output->brake_piston = false; |
| 113 | break; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 114 | case STATE_REQUEST_LOAD: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 115 | if (position->plunger_back_hall_effect && position->latch_hall_effect) { |
| 116 | // already latched |
| 117 | state_ = STATE_PREPARE_SHOT; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 118 | } else if (position->pusher_distal_hall_effect || |
| 119 | (real_position) < 0) { |
| 120 | state_ = STATE_LOAD_BACKTRACK; |
| 121 | if (position) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 122 | calibration_position_ = position->position; |
| 123 | } |
| 124 | } else { |
| 125 | state_ = STATE_LOAD; |
| 126 | } |
| 127 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 128 | shooter_.SetGoalPosition(0.0, 0.0); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 129 | if (position && output) output->latch_piston = position->plunger_back_hall_effect; |
| 130 | output->brake_piston = false; |
| 131 | break; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 132 | case STATE_LOAD_BACKTRACK: |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 133 | if (real_position < values.shooter.pusher_distal.upper_limit + 0.01) { |
| 134 | shooter_.SetGoalPosition(position->position + values.shooter_zeroing_speed*dt, |
| 135 | values.shooter_zeroing_speed); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 136 | } else { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 137 | state_ = STATE_LOAD; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | output->latch_piston = false; |
| 141 | output->brake_piston = true; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 142 | break; |
| 143 | case STATE_LOAD: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 144 | if (position->pusher_proximal_hall_effect && |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 145 | !last_position_.pusher_proximal_hall_effect) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 146 | calibration_position_ = position->position - |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 147 | values.shooter.pusher_proximal.upper_limit; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 148 | } |
| 149 | if (position->pusher_distal_hall_effect && |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 150 | !last_position_.pusher_distal_hall_effect) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 151 | calibration_position_ = position->position - |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 152 | values.shooter.pusher_distal.lower_limit; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 155 | shooter_.SetGoalPosition(calibration_position_, 0.0); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 156 | if (position && output) output->latch_piston = position->plunger_back_hall_effect; |
| 157 | if(output) output->brake_piston = false; |
| 158 | |
| 159 | if (position->plunger_back_hall_effect && position->latch_hall_effect) { |
| 160 | state_ = STATE_PREPARE_SHOT; |
| 161 | } else if (position->plunger_back_hall_effect && |
| 162 | position->position == PowerToPosition(goal->shot_power)) { |
| 163 | //TODO_ben: I'm worried it will bounce states if the position is drifting slightly |
| 164 | state_ = STATE_LOADING_PROBLEM; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 165 | loading_problem_end_time_ = Time::Now(Time::kDefaultClock) + Time::InSeconds(3.0); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 166 | } |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 167 | break; |
| 168 | case STATE_LOADING_PROBLEM: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 169 | if (position->plunger_back_hall_effect && position->latch_hall_effect) { |
| 170 | state_ = STATE_PREPARE_SHOT; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 171 | } else if (real_position < -0.02 || Time::Now() > loading_problem_end_time_) { |
| 172 | state_ = STATE_UNLOAD; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 175 | shooter_.SetGoalPosition(position->position - values.shooter_zeroing_speed*dt, |
| 176 | values.shooter_zeroing_speed); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 177 | if (output) output->latch_piston = true; |
| 178 | if (output) output->brake_piston = false; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 179 | break; |
| 180 | case STATE_PREPARE_SHOT: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 181 | shooter_.SetGoalPosition( |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 182 | PowerToPosition(goal->shot_power), 0.0); |
| 183 | //TODO_ben: I'm worried it will bounce states if the position is drifting slightly |
| 184 | if (position->position == PowerToPosition(goal->shot_power)) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 185 | state_ = STATE_READY; |
| 186 | output->latch_piston = true; |
| 187 | output->brake_piston = true; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 188 | shooter_brake_set_time_ = Time::Now(Time::kDefaultClock) + Time::InSeconds(3.0); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 189 | } else { |
| 190 | output->latch_piston =true; |
| 191 | output->brake_piston = false; |
| 192 | } |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 193 | break; |
| 194 | case STATE_READY: |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 195 | if (Time::Now() > shooter_brake_set_time_) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 196 | shooter_loop_disable = true; |
| 197 | if (goal->unload_requested) { |
| 198 | state_ = STATE_UNLOAD; |
| 199 | } else if (PowerToPosition(goal->shot_power) |
| 200 | != position->position) { |
| 201 | //TODO_ben: I'm worried it will bounce states if the position is drifting slightly |
| 202 | state_ = STATE_PREPARE_SHOT; |
| 203 | }else if (goal->shot_requested) { |
| 204 | state_ = STATE_REQUEST_FIRE; |
| 205 | } |
| 206 | |
| 207 | } |
| 208 | output->latch_piston = true; |
| 209 | output->brake_piston = true; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 210 | break; |
| 211 | case STATE_REQUEST_FIRE: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 212 | shooter_loop_disable = true; |
| 213 | if (position->plunger_back_hall_effect) { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 214 | prepare_fire_end_time_ = Time::Now(Time::kDefaultClock) |
| 215 | + Time::InMS(40.0); |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 216 | apply_some_voltage = true; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 217 | state_ = STATE_PREPARE_FIRE; |
| 218 | } else { |
| 219 | state_ = STATE_REQUEST_LOAD; |
| 220 | } |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 221 | break; |
| 222 | case STATE_PREPARE_FIRE: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 223 | shooter_loop_disable = true; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 224 | if (Time::Now(Time::kDefaultClock) < prepare_fire_end_time_) { |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 225 | apply_some_voltage = true; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 226 | } else { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 227 | state_ = STATE_FIRE; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 228 | cycles_not_moved_ = 0; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 229 | shot_end_time_ = Time::Now(Time::kDefaultClock) + |
| 230 | Time::InMS(500); |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | output->latch_piston = true; |
| 234 | output->brake_piston = true; |
| 235 | |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 236 | break; |
| 237 | case STATE_FIRE: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 238 | shooter_loop_disable = true; |
| 239 | //TODO_ben: need approamately equal |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 240 | if (last_position_.position - position->position < 7) { |
| 241 | cycles_not_moved_++; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 242 | } else { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 243 | cycles_not_moved_ = 0; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 244 | } |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 245 | if ((real_position < 10.0 && cycles_not_moved_ > 5) || |
| 246 | Time::Now(Time::kDefaultClock) > shot_end_time_) { |
| 247 | state_ = STATE_REQUEST_LOAD; |
| 248 | } |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 249 | output->latch_piston = true; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 250 | output->brake_piston = true; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 251 | break; |
| 252 | case STATE_UNLOAD: |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 253 | if (position->plunger_back_hall_effect && position->latch_hall_effect) { |
| 254 | shooter_.SetGoalPosition(0.02, 0.0); |
| 255 | if (real_position == 0.02) { |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 256 | output->latch_piston = false; |
| 257 | } |
| 258 | } else { |
| 259 | output->latch_piston = false; |
| 260 | state_ = STATE_UNLOAD_MOVE; |
| 261 | } |
| 262 | |
| 263 | output->brake_piston = false; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 264 | break; |
| 265 | case STATE_UNLOAD_MOVE: |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 266 | if (position->position > values.shooter_total_length - 0.03) { |
| 267 | shooter_.SetGoalPosition(position->position, 0.0); |
| 268 | state_ = STATE_READY_UNLOAD; |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 269 | } else { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 270 | shooter_.SetGoalPosition( |
| 271 | position->position + values.shooter_zeroing_speed*dt, |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 272 | values.shooter_zeroing_speed); |
| 273 | } |
| 274 | |
| 275 | output->latch_piston = false; |
| 276 | output->brake_piston = false; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 277 | break; |
| 278 | case STATE_READY_UNLOAD: |
Ben Fredrickson | 1f633ef | 2014-02-16 05:35:45 +0000 | [diff] [blame] | 279 | if (!goal->unload_requested) { |
| 280 | state_ = STATE_REQUEST_LOAD; |
| 281 | } |
| 282 | |
| 283 | output->latch_piston = false; |
| 284 | output->brake_piston = false; |
Ben Fredrickson | 1e512ff | 2014-02-15 21:36:52 +0000 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 288 | if (position) { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 289 | last_position_ = *position; |
| 290 | LOG(DEBUG, "pos: hall: real: %.2f absolute: %.2f\n", |
| 291 | real_position, position->position); |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 294 | if (apply_some_voltage) { |
| 295 | output->voltage = 2.0; |
| 296 | } else if (!shooter_loop_disable) { |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 297 | output->voltage = shooter_.voltage(); |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 298 | } else { |
| 299 | output->voltage = 0.0; |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 300 | } |
Ben Fredrickson | 7d980c2 | 2014-02-16 21:39:02 +0000 | [diff] [blame^] | 301 | |
Ben Fredrickson | edf0e09 | 2014-02-16 10:46:50 +0000 | [diff] [blame] | 302 | status->done = ::std::abs(position->position - PowerToPosition(goal->shot_power)) < 0.004; |
joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | } // namespace control_loops |
| 306 | } // namespace frc971 |