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