Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <unistd.h> |
| 4 | #include <math.h> |
| 5 | |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 6 | #include "aos/common/actions/actions.h" |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 7 | #include "aos/common/input/driver_station_data.h" |
| 8 | #include "aos/common/logging/logging.h" |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 9 | #include "aos/common/time.h" |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 10 | #include "aos/common/util/log_interval.h" |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 11 | #include "aos/input/drivetrain_input.h" |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 12 | #include "aos/input/joystick_input.h" |
| 13 | #include "aos/linux_code/init.h" |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 14 | #include "frc971/autonomous/auto.q.h" |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 15 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 16 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 17 | #include "y2017/constants.h" |
| 18 | #include "y2017/control_loops/superstructure/superstructure.q.h" |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 19 | |
| 20 | using ::frc971::control_loops::drivetrain_queue; |
| 21 | using ::y2017::control_loops::superstructure_queue; |
| 22 | |
| 23 | using ::aos::input::driver_station::ButtonLocation; |
| 24 | using ::aos::input::driver_station::ControlBit; |
| 25 | using ::aos::input::driver_station::JoystickAxis; |
| 26 | using ::aos::input::driver_station::POVLocation; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 27 | using ::aos::input::DrivetrainInputReader; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 28 | |
| 29 | namespace y2017 { |
| 30 | namespace input { |
| 31 | namespace joysticks { |
| 32 | |
Austin Schuh | 55c8d30 | 2017-04-05 19:25:37 -0700 | [diff] [blame] | 33 | const ButtonLocation kGearSlotBack(2, 11); |
| 34 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 35 | const ButtonLocation kIntakeDown(3, 9); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 36 | const POVLocation kIntakeUp(3, 90); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 37 | const ButtonLocation kIntakeIn(3, 12); |
| 38 | const ButtonLocation kIntakeOut(3, 8); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 39 | const ButtonLocation kFire(3, 3); |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 40 | const ButtonLocation kVisionDistanceShot(3, 7); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 41 | const ButtonLocation kMiddleShot(3, 6); |
| 42 | const POVLocation kFarShot(3, 270); |
| 43 | |
| 44 | const ButtonLocation kVisionAlign(3, 5); |
| 45 | |
| 46 | const ButtonLocation kReverseIndexer(3, 4); |
| 47 | const ButtonLocation kExtra1(3, 11); |
| 48 | const ButtonLocation kExtra2(3, 10); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 49 | const ButtonLocation kHang(3, 2); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 50 | |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 51 | std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_; |
| 52 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 53 | class Reader : public ::aos::input::JoystickInput { |
| 54 | public: |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 55 | Reader() { |
| 56 | drivetrain_input_reader_ = DrivetrainInputReader::Make( |
| 57 | DrivetrainInputReader::InputType::kSteeringWheel); |
| 58 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 59 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 60 | enum class ShotDistance { VISION_SHOT, MIDDLE_SHOT, FAR_SHOT }; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 61 | |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 62 | ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 63 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 64 | void RunIteration(const ::aos::input::driver_station::Data &data) override { |
| 65 | bool last_auto_running = auto_running_; |
| 66 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
| 67 | data.GetControlBit(ControlBit::kEnabled); |
| 68 | if (auto_running_ != last_auto_running) { |
| 69 | if (auto_running_) { |
| 70 | StartAuto(); |
| 71 | } else { |
| 72 | StopAuto(); |
| 73 | } |
| 74 | } |
| 75 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 76 | if (!auto_running_) { |
| 77 | HandleDrivetrain(data); |
| 78 | HandleTeleop(data); |
| 79 | } |
| 80 | |
| 81 | // Process any pending actions. |
| 82 | action_queue_.Tick(); |
| 83 | was_running_ = action_queue_.Running(); |
| 84 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 85 | int intake_accumulator_ = 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 86 | |
| 87 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 88 | drivetrain_input_reader_->HandleDrivetrain(data); |
| 89 | robot_velocity_ = drivetrain_input_reader_->robot_velocity(); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
| 93 | // Default the intake to in. |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 94 | intake_goal_ = 0.07; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 95 | bool lights_on = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 96 | bool vision_track = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 97 | |
| 98 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 99 | action_queue_.CancelAllActions(); |
| 100 | LOG(DEBUG, "Canceling\n"); |
| 101 | } |
| 102 | |
| 103 | superstructure_queue.status.FetchLatest(); |
| 104 | if (!superstructure_queue.status.get()) { |
| 105 | LOG(ERROR, "Got no superstructure status packet.\n"); |
| 106 | return; |
| 107 | } |
| 108 | |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 109 | if (data.IsPressed(kIntakeUp)) { |
| 110 | intake_goal_ = 0.0; |
Austin Schuh | 3ae4743 | 2017-04-16 19:15:46 -0700 | [diff] [blame] | 111 | turret_goal_ = M_PI / 3.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 112 | } |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 113 | if (data.IsPressed(kIntakeDown)) { |
| 114 | intake_goal_ = 0.235; |
| 115 | // Don't go quite so far out since we have a gear mech out now. |
| 116 | if (data.IsPressed(kIntakeUp)) { |
| 117 | intake_goal_ = 0.160; |
| 118 | } |
| 119 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 120 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 121 | if (data.IsPressed(kVisionAlign)) { |
| 122 | // Align shot using vision |
| 123 | // TODO(campbell): Add vision aligning. |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 124 | lights_on = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 125 | vision_track = true; |
| 126 | } |
| 127 | if (data.PosEdge(kMiddleShot)) { |
| 128 | turret_goal_ = -M_PI; |
| 129 | } |
| 130 | if (data.PosEdge(kFarShot)) { |
| 131 | turret_goal_ = 0.0; |
| 132 | } |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 133 | if (data.PosEdge(kVisionDistanceShot)) { |
| 134 | turret_goal_ = 0.0; |
| 135 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 136 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 137 | if (data.IsPressed(kVisionDistanceShot)) { |
| 138 | last_shot_distance_ = ShotDistance::VISION_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 139 | } else if (data.IsPressed(kMiddleShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 140 | last_shot_distance_ = ShotDistance::MIDDLE_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 141 | } else if (data.IsPressed(kFarShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 142 | last_shot_distance_ = ShotDistance::FAR_SHOT; |
| 143 | } |
| 144 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 145 | if (data.IsPressed(kVisionAlign) || |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 146 | data.IsPressed(kMiddleShot) || data.IsPressed(kFarShot) || |
| 147 | data.IsPressed(kFire)) { |
| 148 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 149 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 150 | hood_goal_ = 0.10; |
| 151 | shooter_velocity_ = 300.0; |
| 152 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 153 | vision_distance_shot_ = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 154 | break; |
| 155 | case ShotDistance::MIDDLE_SHOT: |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 156 | hood_goal_ = 0.43 - 0.00; |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 157 | shooter_velocity_ = 364.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 158 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 159 | break; |
| 160 | case ShotDistance::FAR_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 161 | hood_goal_ = 0.47; |
| 162 | shooter_velocity_ = 410.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 163 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 164 | break; |
| 165 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 166 | } else { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 167 | //hood_goal_ = 0.15; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 168 | shooter_velocity_ = 0.0; |
| 169 | } |
| 170 | |
| 171 | if (data.IsPressed(kExtra1)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 172 | //turret_goal_ = -M_PI * 3.0 / 4.0; |
| 173 | turret_goal_ += 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 174 | } |
| 175 | if (data.IsPressed(kExtra2)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 176 | //turret_goal_ = M_PI * 3.0 / 4.0; |
| 177 | turret_goal_ -= 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 178 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 179 | turret_goal_ = ::std::max(::std::min(turret_goal_, M_PI), -M_PI); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 180 | |
| 181 | fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 182 | if (data.IsPressed(kVisionAlign)) { |
| 183 | fire_ = fire_ && superstructure_queue.status->turret.vision_tracking; |
| 184 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 185 | |
| 186 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 187 | if (data.IsPressed(kHang)) { |
| 188 | intake_goal_ = 0.23; |
| 189 | } |
| 190 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 191 | new_superstructure_goal->intake.distance = intake_goal_; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 192 | new_superstructure_goal->intake.disable_intake = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 193 | new_superstructure_goal->turret.angle = turret_goal_; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 194 | new_superstructure_goal->turret.track = vision_track; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 195 | new_superstructure_goal->hood.angle = hood_goal_; |
| 196 | new_superstructure_goal->shooter.angular_velocity = shooter_velocity_; |
| 197 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 198 | if (data.IsPressed(kIntakeUp)) { |
Austin Schuh | d6fa5e0 | 2017-04-12 20:52:17 -0700 | [diff] [blame] | 199 | new_superstructure_goal->intake.gear_servo = 0.30; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 200 | } else { |
| 201 | // Clamp the gear |
Austin Schuh | d6fa5e0 | 2017-04-12 20:52:17 -0700 | [diff] [blame] | 202 | new_superstructure_goal->intake.gear_servo = 0.66; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 205 | new_superstructure_goal->intake.profile_params.max_velocity = 0.50; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 206 | new_superstructure_goal->hood.profile_params.max_velocity = 5.0; |
| 207 | |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 208 | new_superstructure_goal->intake.profile_params.max_acceleration = 3.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 209 | if (vision_track) { |
| 210 | new_superstructure_goal->turret.profile_params.max_acceleration = 35.0; |
| 211 | new_superstructure_goal->turret.profile_params.max_velocity = 10.0; |
| 212 | } else { |
| 213 | new_superstructure_goal->turret.profile_params.max_acceleration = 15.0; |
| 214 | new_superstructure_goal->turret.profile_params.max_velocity = 6.0; |
| 215 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 216 | new_superstructure_goal->hood.profile_params.max_acceleration = 25.0; |
| 217 | |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 218 | new_superstructure_goal->intake.voltage_rollers = 0.0; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 219 | new_superstructure_goal->lights_on = lights_on; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 220 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 221 | if (data.IsPressed(kVisionAlign) && vision_distance_shot_) { |
| 222 | new_superstructure_goal->use_vision_for_shots = true; |
| 223 | } else { |
| 224 | new_superstructure_goal->use_vision_for_shots = false; |
| 225 | } |
| 226 | |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 227 | if (superstructure_queue.status->intake.position > |
| 228 | superstructure_queue.status->intake.unprofiled_goal_position + 0.01) { |
| 229 | intake_accumulator_ = 10; |
| 230 | } |
| 231 | if (intake_accumulator_ > 0) { |
| 232 | --intake_accumulator_; |
| 233 | if (!superstructure_queue.status->intake.estopped) { |
| 234 | new_superstructure_goal->intake.voltage_rollers = 10.0; |
| 235 | } |
| 236 | } |
| 237 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 238 | if (data.IsPressed(kHang)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 239 | new_superstructure_goal->intake.voltage_rollers = -10.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 240 | new_superstructure_goal->intake.disable_intake = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 241 | } else if (data.IsPressed(kIntakeIn) || data.IsPressed(kFire)) { |
| 242 | if (robot_velocity_ > 2.0) { |
| 243 | new_superstructure_goal->intake.voltage_rollers = 12.0; |
| 244 | } else { |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 245 | new_superstructure_goal->intake.voltage_rollers = 11.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 246 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 247 | } else if (data.IsPressed(kIntakeOut)) { |
| 248 | new_superstructure_goal->intake.voltage_rollers = -8.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 249 | } |
| 250 | if (intake_goal_ < 0.1) { |
| 251 | new_superstructure_goal->intake.voltage_rollers = |
| 252 | ::std::min(8.0, new_superstructure_goal->intake.voltage_rollers); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | if (data.IsPressed(kReverseIndexer)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 256 | new_superstructure_goal->indexer.voltage_rollers = -12.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 257 | new_superstructure_goal->indexer.angular_velocity = 4.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 258 | new_superstructure_goal->indexer.angular_velocity = 1.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 259 | } else if (fire_) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 260 | new_superstructure_goal->indexer.voltage_rollers = 12.0; |
| 261 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 262 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 263 | new_superstructure_goal->indexer.angular_velocity = -1.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 264 | break; |
| 265 | case ShotDistance::MIDDLE_SHOT: |
| 266 | case ShotDistance::FAR_SHOT: |
| 267 | new_superstructure_goal->indexer.angular_velocity = -2.25 * M_PI; |
| 268 | break; |
| 269 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 270 | } else { |
| 271 | new_superstructure_goal->indexer.voltage_rollers = 0.0; |
| 272 | new_superstructure_goal->indexer.angular_velocity = 0.0; |
| 273 | } |
| 274 | |
| 275 | LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal); |
| 276 | if (!new_superstructure_goal.Send()) { |
| 277 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | private: |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 282 | void StartAuto() { |
| 283 | LOG(INFO, "Starting auto mode\n"); |
| 284 | |
| 285 | ::frc971::autonomous::AutonomousActionParams params; |
| 286 | ::frc971::autonomous::auto_mode.FetchLatest(); |
| 287 | if (::frc971::autonomous::auto_mode.get() != nullptr) { |
| 288 | params.mode = ::frc971::autonomous::auto_mode->mode; |
| 289 | } else { |
| 290 | LOG(WARNING, "no auto mode values\n"); |
| 291 | params.mode = 0; |
| 292 | } |
| 293 | action_queue_.EnqueueAction( |
| 294 | ::frc971::autonomous::MakeAutonomousAction(params)); |
| 295 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 296 | |
| 297 | void StopAuto() { |
| 298 | LOG(INFO, "Stopping auto mode\n"); |
| 299 | action_queue_.CancelAllActions(); |
| 300 | } |
| 301 | |
| 302 | // Current goals to send to the robot. |
| 303 | double intake_goal_ = 0.0; |
| 304 | double turret_goal_ = 0.0; |
| 305 | double hood_goal_ = 0.3; |
| 306 | double shooter_velocity_ = 0.0; |
| 307 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 308 | bool was_running_ = false; |
| 309 | bool auto_running_ = false; |
| 310 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 311 | bool vision_distance_shot_ = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 312 | |
| 313 | bool fire_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 314 | double robot_velocity_ = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 315 | |
| 316 | ::aos::common::actions::ActionQueue action_queue_; |
| 317 | }; |
| 318 | |
| 319 | } // namespace joysticks |
| 320 | } // namespace input |
| 321 | } // namespace y2017 |
| 322 | |
| 323 | int main() { |
| 324 | ::aos::Init(-1); |
| 325 | ::y2017::input::joysticks::Reader reader; |
| 326 | reader.Run(); |
| 327 | ::aos::Cleanup(); |
| 328 | } |