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