Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <unistd.h> |
| 4 | #include <math.h> |
| 5 | |
| 6 | #include "aos/linux_code/init.h" |
| 7 | #include "aos/input/joystick_input.h" |
| 8 | #include "aos/common/input/driver_station_data.h" |
| 9 | #include "aos/common/logging/logging.h" |
| 10 | #include "aos/common/util/log_interval.h" |
| 11 | #include "aos/common/time.h" |
| 12 | #include "aos/common/actions/actions.h" |
| 13 | |
| 14 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 15 | #include "y2016/control_loops/shooter/shooter.q.h" |
| 16 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 17 | #include "y2016/control_loops/superstructure/superstructure.h" |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 18 | #include "y2016/queues/ball_detector.q.h" |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 19 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 20 | #include "y2016/constants.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 21 | #include "frc971/queues/gyro.q.h" |
| 22 | #include "frc971/autonomous/auto.q.h" |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 23 | #include "y2016/actors/autonomous_actor.h" |
Austin Schuh | 1879911 | 2016-03-16 22:09:54 -0700 | [diff] [blame] | 24 | #include "y2016/actors/vision_align_actor.h" |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 25 | |
| 26 | using ::frc971::control_loops::drivetrain_queue; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 27 | using ::y2016::control_loops::shooter::shooter_queue; |
| 28 | using ::y2016::control_loops::superstructure_queue; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 29 | |
| 30 | using ::aos::input::driver_station::ButtonLocation; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 31 | using ::aos::input::driver_station::ControlBit; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 32 | using ::aos::input::driver_station::JoystickAxis; |
| 33 | using ::aos::input::driver_station::POVLocation; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 34 | |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 35 | namespace y2016 { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 36 | namespace input { |
| 37 | namespace joysticks { |
| 38 | |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | constexpr double kMaxIntakeAngleBeforeArmInterference = control_loops:: |
| 42 | superstructure::CollisionAvoidance::kMaxIntakeAngleBeforeArmInterference; |
| 43 | |
| 44 | } // namespace |
| 45 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 46 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
Campbell Crowley | 5b27f02 | 2016-02-20 16:55:35 -0800 | [diff] [blame] | 47 | const ButtonLocation kShiftHigh(2, 3), kShiftHigh2(2, 2), kShiftLow(2, 1); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 48 | const ButtonLocation kQuickTurn(1, 5); |
| 49 | |
Austin Schuh | 781cdcc | 2016-03-12 13:03:12 -0800 | [diff] [blame] | 50 | const ButtonLocation kTurn1(1, 7); |
| 51 | const ButtonLocation kTurn2(1, 11); |
| 52 | |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 53 | // Buttons on the lexan driver station to get things running on bring-up day. |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 54 | const ButtonLocation kIntakeDown(3, 11); |
| 55 | const POVLocation kFrontLong(3, 180); |
| 56 | const POVLocation kBackLong(3, 0); |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 57 | const POVLocation kBackFender(3, 90); |
| 58 | const POVLocation kFrontFender(3, 270); |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 59 | const ButtonLocation kTest3(3, 7); |
| 60 | const ButtonLocation kIntakeIn(3, 12); |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 61 | const ButtonLocation kTest5(3, 8); |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 62 | const ButtonLocation kFire(3, 3); |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 63 | const ButtonLocation kTest7(3, 5); |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 64 | const ButtonLocation kIntakeOut(3, 9); |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 65 | |
Austin Schuh | 1879911 | 2016-03-16 22:09:54 -0700 | [diff] [blame] | 66 | const ButtonLocation kVisionAlign(1, 6); |
| 67 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 68 | class Reader : public ::aos::input::JoystickInput { |
| 69 | public: |
| 70 | Reader() |
Austin Schuh | 94596dd | 2016-03-13 21:41:26 -0700 | [diff] [blame] | 71 | : is_high_gear_(true), |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 72 | intake_goal_(0.0), |
| 73 | shoulder_goal_(M_PI / 2.0), |
| 74 | wrist_goal_(0.0) {} |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 75 | |
| 76 | void RunIteration(const ::aos::input::driver_station::Data &data) override { |
| 77 | bool last_auto_running = auto_running_; |
| 78 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
| 79 | data.GetControlBit(ControlBit::kEnabled); |
| 80 | if (auto_running_ != last_auto_running) { |
| 81 | if (auto_running_) { |
| 82 | StartAuto(); |
| 83 | } else { |
| 84 | StopAuto(); |
| 85 | } |
| 86 | } |
| 87 | |
Austin Schuh | 94596dd | 2016-03-13 21:41:26 -0700 | [diff] [blame] | 88 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 89 | // If we are not enabled, reset the waiting for zero bit. |
| 90 | LOG(DEBUG, "Waiting for zero.\n"); |
| 91 | waiting_for_zero_ = true; |
| 92 | is_high_gear_ = true; |
| 93 | } |
| 94 | |
| 95 | if (!auto_running_) { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 96 | HandleDrivetrain(data); |
| 97 | HandleTeleop(data); |
| 98 | } |
Austin Schuh | 81d71db | 2016-03-15 20:56:24 -0700 | [diff] [blame] | 99 | |
| 100 | // Process any pending actions. |
| 101 | action_queue_.Tick(); |
| 102 | was_running_ = action_queue_.Running(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
| 106 | bool is_control_loop_driving = false; |
Austin Schuh | 781cdcc | 2016-03-12 13:03:12 -0800 | [diff] [blame] | 107 | static double left_goal = 0.0; |
| 108 | static double right_goal = 0.0; |
| 109 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 110 | const double wheel = -data.GetAxis(kSteeringWheel); |
| 111 | const double throttle = -data.GetAxis(kDriveThrottle); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 112 | |
Austin Schuh | 1879911 | 2016-03-16 22:09:54 -0700 | [diff] [blame] | 113 | if (data.PosEdge(kVisionAlign)) { |
| 114 | actors::VisionAlignActionParams params; |
| 115 | action_queue_.EnqueueAction(actors::MakeVisionAlignAction(params)); |
| 116 | } |
| 117 | |
| 118 | if (data.NegEdge(kVisionAlign)) { |
| 119 | action_queue_.CancelAllActions(); |
| 120 | } |
| 121 | |
| 122 | // Don't do any normal drivetrain stuff if vision is in charge. |
| 123 | if (was_running_) { |
| 124 | return; |
| 125 | } |
| 126 | |
Austin Schuh | 781cdcc | 2016-03-12 13:03:12 -0800 | [diff] [blame] | 127 | if (data.PosEdge(kTurn1) || data.PosEdge(kTurn2)) { |
| 128 | drivetrain_queue.status.FetchLatest(); |
| 129 | if (drivetrain_queue.status.get()) { |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 130 | left_goal = drivetrain_queue.status->estimated_left_position; |
| 131 | right_goal = drivetrain_queue.status->estimated_right_position; |
Austin Schuh | 781cdcc | 2016-03-12 13:03:12 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | if (data.IsPressed(kTurn1) || data.IsPressed(kTurn2)) { |
| 135 | is_control_loop_driving = true; |
| 136 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 137 | if (!drivetrain_queue.goal.MakeWithBuilder() |
| 138 | .steering(wheel) |
| 139 | .throttle(throttle) |
| 140 | .highgear(is_high_gear_) |
| 141 | .quickturn(data.IsPressed(kQuickTurn)) |
| 142 | .control_loop_driving(is_control_loop_driving) |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 143 | .left_goal(left_goal - wheel * 0.5 + throttle * 0.3) |
| 144 | .right_goal(right_goal + wheel * 0.5 + throttle * 0.3) |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 145 | .left_velocity_goal(0) |
| 146 | .right_velocity_goal(0) |
| 147 | .Send()) { |
| 148 | LOG(WARNING, "sending stick values failed\n"); |
| 149 | } |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 150 | |
Campbell Crowley | 5b27f02 | 2016-02-20 16:55:35 -0800 | [diff] [blame] | 151 | if (data.PosEdge(kShiftLow)) { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 152 | is_high_gear_ = false; |
| 153 | } |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 154 | |
Campbell Crowley | 5b27f02 | 2016-02-20 16:55:35 -0800 | [diff] [blame] | 155 | if (data.PosEdge(kShiftHigh) || data.PosEdge(kShiftHigh2)) { |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 156 | is_high_gear_ = true; |
| 157 | } |
| 158 | } |
| 159 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 160 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 161 | // Default the intake to up. |
| 162 | intake_goal_ = constants::Values::kIntakeRange.upper - 0.04; |
| 163 | |
| 164 | bool force_lights_on = false; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 165 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 166 | action_queue_.CancelAllActions(); |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 167 | LOG(DEBUG, "Canceling\n"); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 170 | superstructure_queue.status.FetchLatest(); |
| 171 | if (!superstructure_queue.status.get()) { |
| 172 | LOG(ERROR, "Got no superstructure status packet.\n"); |
| 173 | } |
| 174 | |
| 175 | if (superstructure_queue.status.get() && |
| 176 | superstructure_queue.status->zeroed) { |
| 177 | if (waiting_for_zero_) { |
Austin Schuh | 94596dd | 2016-03-13 21:41:26 -0700 | [diff] [blame] | 178 | LOG(DEBUG, "Zeroed! Starting teleop mode.\n"); |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 179 | waiting_for_zero_ = false; |
| 180 | } |
| 181 | } else { |
| 182 | waiting_for_zero_ = true; |
| 183 | } |
| 184 | |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 185 | if (data.IsPressed(kFrontLong)) { |
| 186 | // Forwards shot |
Austin Schuh | 5a6db4d | 2016-02-28 22:02:42 -0800 | [diff] [blame] | 187 | shoulder_goal_ = M_PI / 2.0 - 0.2; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 188 | wrist_goal_ = M_PI + 0.42; |
| 189 | shooter_velocity_ = 640.0; |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 190 | intake_goal_ = kMaxIntakeAngleBeforeArmInterference; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 191 | } else if (data.IsPressed(kBackLong)) { |
| 192 | // Backwards shot |
| 193 | shoulder_goal_ = M_PI / 2.0 - 0.2; |
| 194 | wrist_goal_ = -0.59; |
| 195 | shooter_velocity_ = 640.0; |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 196 | intake_goal_ = kMaxIntakeAngleBeforeArmInterference; |
| 197 | } else if (data.IsPressed(kBackFender)) { |
| 198 | // Fender shot back |
| 199 | shoulder_goal_ = 0.65; |
| 200 | wrist_goal_ = -1.0; |
| 201 | shooter_velocity_ = 550.0; |
| 202 | intake_goal_ = kMaxIntakeAngleBeforeArmInterference; |
| 203 | } else if (data.IsPressed(kFrontFender)) { |
| 204 | // Fender shot back |
| 205 | shoulder_goal_ = 1.45; |
| 206 | wrist_goal_ = 2.5 + 1.7; |
| 207 | shooter_velocity_ = 550.0; |
| 208 | intake_goal_ = kMaxIntakeAngleBeforeArmInterference; |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 209 | } else { |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 210 | wrist_goal_ = 0.0; |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 211 | shoulder_goal_ = -0.010; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 212 | shooter_velocity_ = 0.0; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 215 | if (data.IsPressed(kTest3)) { |
| 216 | wrist_goal_ = 0.0; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 219 | bool ball_detected = false; |
| 220 | ::y2016::sensors::ball_detector.FetchLatest(); |
| 221 | if (::y2016::sensors::ball_detector.get()) { |
| 222 | ball_detected = ::y2016::sensors::ball_detector->voltage > 2.5; |
| 223 | } |
| 224 | if (data.PosEdge(kIntakeIn)) { |
| 225 | saw_ball_when_started_intaking_ = ball_detected; |
| 226 | } |
| 227 | |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 228 | if (data.IsPressed(kIntakeIn)) { |
| 229 | is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_); |
| 230 | if (ball_detected) { |
| 231 | force_lights_on = true; |
| 232 | } |
| 233 | } else { |
| 234 | is_intaking_ = false; |
| 235 | } |
| 236 | |
| 237 | if (data.IsPressed(kIntakeDown)) { |
| 238 | if (is_intaking_) { |
| 239 | intake_goal_ = 0.1; |
| 240 | } else { |
| 241 | intake_goal_ = -0.05; |
| 242 | } |
| 243 | } |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 244 | |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 245 | if (data.IsPressed(kFire) && shooter_velocity_ != 0.0) { |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 246 | fire_ = true; |
| 247 | } else { |
| 248 | fire_ = false; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | if (data.PosEdge(kTest7)) { |
| 252 | } |
| 253 | |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 254 | is_outtaking_ = data.IsPressed(kIntakeOut); |
Austin Schuh | 5a6db4d | 2016-02-28 22:02:42 -0800 | [diff] [blame] | 255 | |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 256 | if (!waiting_for_zero_) { |
| 257 | if (!action_queue_.Running()) { |
| 258 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
| 259 | new_superstructure_goal->angle_intake = intake_goal_; |
| 260 | new_superstructure_goal->angle_shoulder = shoulder_goal_; |
| 261 | new_superstructure_goal->angle_wrist = wrist_goal_; |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 262 | |
| 263 | new_superstructure_goal->max_angular_velocity_intake = 7.0; |
| 264 | new_superstructure_goal->max_angular_velocity_shoulder = 4.0; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 265 | new_superstructure_goal->max_angular_velocity_wrist = 10.0; |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 266 | new_superstructure_goal->max_angular_acceleration_intake = 40.0; |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 267 | new_superstructure_goal->max_angular_acceleration_shoulder = 10.0; |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 268 | new_superstructure_goal->max_angular_acceleration_wrist = 25.0; |
| 269 | |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 270 | // Granny mode |
Austin Schuh | 4ea06c1 | 2016-03-12 17:54:31 -0800 | [diff] [blame] | 271 | /* |
Austin Schuh | 3f0b119 | 2016-03-12 13:03:56 -0800 | [diff] [blame] | 272 | new_superstructure_goal->max_angular_velocity_intake = 0.2; |
| 273 | new_superstructure_goal->max_angular_velocity_shoulder = 0.2; |
| 274 | new_superstructure_goal->max_angular_velocity_wrist = 0.2; |
| 275 | new_superstructure_goal->max_angular_acceleration_intake = 1.0; |
| 276 | new_superstructure_goal->max_angular_acceleration_shoulder = 1.0; |
| 277 | new_superstructure_goal->max_angular_acceleration_wrist = 1.0; |
| 278 | */ |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 279 | if (is_intaking_) { |
| 280 | new_superstructure_goal->voltage_top_rollers = 12.0; |
Austin Schuh | 5a6db4d | 2016-02-28 22:02:42 -0800 | [diff] [blame] | 281 | new_superstructure_goal->voltage_bottom_rollers = 12.0; |
| 282 | } else if (is_outtaking_) { |
| 283 | new_superstructure_goal->voltage_top_rollers = -12.0; |
| 284 | new_superstructure_goal->voltage_bottom_rollers = -7.0; |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 285 | } else { |
| 286 | new_superstructure_goal->voltage_top_rollers = 0.0; |
| 287 | new_superstructure_goal->voltage_bottom_rollers = 0.0; |
| 288 | } |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 289 | |
| 290 | if (!new_superstructure_goal.Send()) { |
| 291 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 292 | } else { |
| 293 | LOG(DEBUG, "sending goals: intake: %f, shoulder: %f, wrist: %f\n", |
| 294 | intake_goal_, shoulder_goal_, wrist_goal_); |
| 295 | } |
| 296 | |
| 297 | if (!shooter_queue.goal.MakeWithBuilder() |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 298 | .angular_velocity(shooter_velocity_) |
Austin Schuh | 5a6db4d | 2016-02-28 22:02:42 -0800 | [diff] [blame] | 299 | .clamp_open(is_intaking_ || is_outtaking_) |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 300 | .push_to_shooter(fire_) |
Austin Schuh | 45d07f6 | 2016-03-13 15:33:31 -0700 | [diff] [blame] | 301 | .force_lights_on(force_lights_on) |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 302 | .Send()) { |
| 303 | LOG(ERROR, "Sending shooter goal failed.\n"); |
| 304 | } |
| 305 | } |
| 306 | } |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 309 | private: |
| 310 | void StartAuto() { |
| 311 | LOG(INFO, "Starting auto mode\n"); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 312 | |
| 313 | actors::AutonomousActionParams params; |
| 314 | params.mode = 0; |
| 315 | action_queue_.EnqueueAction(actors::MakeAutonomousAction(params)); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void StopAuto() { |
| 319 | LOG(INFO, "Stopping auto mode\n"); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 320 | action_queue_.CancelAllActions(); |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | bool is_high_gear_; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 324 | // Whatever these are set to are our default goals to send out after zeroing. |
| 325 | double intake_goal_; |
| 326 | double shoulder_goal_; |
| 327 | double wrist_goal_; |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 328 | double shooter_velocity_ = 0.0; |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 329 | |
| 330 | bool was_running_ = false; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 331 | bool auto_running_ = false; |
| 332 | |
Comran Morshed | 200dd4b | 2016-02-16 17:54:58 +0000 | [diff] [blame] | 333 | // If we're waiting for the subsystems to zero. |
| 334 | bool waiting_for_zero_ = true; |
| 335 | |
Comran Morshed | aa0573c | 2016-03-05 19:05:54 +0000 | [diff] [blame] | 336 | // If true, the ball was present when the intaking button was pressed. |
| 337 | bool saw_ball_when_started_intaking_ = false; |
| 338 | |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 339 | bool is_intaking_ = false; |
Austin Schuh | 5a6db4d | 2016-02-28 22:02:42 -0800 | [diff] [blame] | 340 | bool is_outtaking_ = false; |
Austin Schuh | de802e9 | 2016-02-27 14:49:03 -0800 | [diff] [blame] | 341 | bool fire_ = false; |
| 342 | |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 343 | ::aos::common::actions::ActionQueue action_queue_; |
| 344 | |
| 345 | ::aos::util::SimpleLogInterval no_drivetrain_status_ = |
| 346 | ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING, |
| 347 | "no drivetrain status"); |
| 348 | }; |
| 349 | |
| 350 | } // namespace joysticks |
| 351 | } // namespace input |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 352 | } // namespace y2016 |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 353 | |
| 354 | int main() { |
| 355 | ::aos::Init(-1); |
Comran Morshed | 6c6a0a9 | 2016-01-17 12:45:16 +0000 | [diff] [blame] | 356 | ::y2016::input::joysticks::Reader reader; |
Comran Morshed | 9a9948c | 2016-01-16 15:58:04 +0000 | [diff] [blame] | 357 | reader.Run(); |
| 358 | ::aos::Cleanup(); |
| 359 | } |