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 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 6 | #include "aos/actions/actions.h" |
| 7 | #include "aos/input/driver_station_data.h" |
| 8 | #include "aos/logging/logging.h" |
| 9 | #include "aos/time/time.h" |
| 10 | #include "aos/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 | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 12 | #include "aos/input/action_joystick_input.h" |
John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 13 | #include "aos/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 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 21 | using ::aos::input::driver_station::ButtonLocation; |
| 22 | using ::aos::input::driver_station::ControlBit; |
| 23 | using ::aos::input::driver_station::JoystickAxis; |
| 24 | using ::aos::input::driver_station::POVLocation; |
Sabina Davis | 92d2efa | 2017-11-04 22:35:25 -0700 | [diff] [blame] | 25 | using ::aos::input::DrivetrainInputReader; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 26 | |
| 27 | namespace y2017 { |
| 28 | namespace input { |
| 29 | namespace joysticks { |
| 30 | |
Austin Schuh | 55c8d30 | 2017-04-05 19:25:37 -0700 | [diff] [blame] | 31 | const ButtonLocation kGearSlotBack(2, 11); |
| 32 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 33 | const ButtonLocation kIntakeDown(3, 9); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 34 | const POVLocation kIntakeUp(3, 90); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 35 | const ButtonLocation kIntakeIn(3, 12); |
| 36 | const ButtonLocation kIntakeOut(3, 8); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 37 | const ButtonLocation kFire(3, 3); |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 38 | const ButtonLocation kVisionDistanceShot(3, 7); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 39 | const ButtonLocation kMiddleShot(3, 6); |
| 40 | const POVLocation kFarShot(3, 270); |
| 41 | |
| 42 | const ButtonLocation kVisionAlign(3, 5); |
| 43 | |
| 44 | const ButtonLocation kReverseIndexer(3, 4); |
| 45 | const ButtonLocation kExtra1(3, 11); |
| 46 | const ButtonLocation kExtra2(3, 10); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 47 | const ButtonLocation kHang(3, 2); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 48 | |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 49 | class Reader : public ::aos::input::ActionJoystickInput { |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 50 | public: |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 51 | Reader(::aos::EventLoop *event_loop) |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 52 | : ::aos::input::ActionJoystickInput( |
| 53 | event_loop, |
| 54 | ::y2017::control_loops::drivetrain::GetDrivetrainConfig(), |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 55 | DrivetrainInputReader::InputType::kSteeringWheel, {}), |
| 56 | superstructure_status_fetcher_( |
| 57 | event_loop->MakeFetcher< |
| 58 | ::y2017::control_loops::SuperstructureQueue::Status>( |
| 59 | ".y2017.control_loops.superstructure_queue.status")), |
| 60 | superstructure_goal_sender_( |
| 61 | event_loop |
| 62 | ->MakeSender<::y2017::control_loops::SuperstructureQueue::Goal>( |
| 63 | ".y2017.control_loops.superstructure_queue.goal")) {} |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 64 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 65 | enum class ShotDistance { VISION_SHOT, MIDDLE_SHOT, FAR_SHOT }; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 66 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 67 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
| 68 | // Default the intake to in. |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 69 | intake_goal_ = 0.07; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 70 | bool lights_on = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 71 | bool vision_track = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 72 | |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 73 | superstructure_status_fetcher_.Fetch(); |
| 74 | if (!superstructure_status_fetcher_.get()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 75 | AOS_LOG(ERROR, "Got no superstructure status packet.\n"); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 79 | if (data.IsPressed(kIntakeUp)) { |
| 80 | intake_goal_ = 0.0; |
Austin Schuh | 3ae4743 | 2017-04-16 19:15:46 -0700 | [diff] [blame] | 81 | turret_goal_ = M_PI / 3.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 82 | } |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 83 | if (data.IsPressed(kIntakeDown)) { |
| 84 | intake_goal_ = 0.235; |
| 85 | // Don't go quite so far out since we have a gear mech out now. |
| 86 | if (data.IsPressed(kIntakeUp)) { |
| 87 | intake_goal_ = 0.160; |
| 88 | } |
| 89 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 90 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 91 | if (data.IsPressed(kVisionAlign)) { |
| 92 | // Align shot using vision |
| 93 | // TODO(campbell): Add vision aligning. |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 94 | lights_on = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 95 | vision_track = true; |
| 96 | } |
| 97 | if (data.PosEdge(kMiddleShot)) { |
| 98 | turret_goal_ = -M_PI; |
| 99 | } |
| 100 | if (data.PosEdge(kFarShot)) { |
| 101 | turret_goal_ = 0.0; |
| 102 | } |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 103 | if (data.PosEdge(kVisionDistanceShot)) { |
| 104 | turret_goal_ = 0.0; |
| 105 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 106 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 107 | if (data.IsPressed(kVisionDistanceShot)) { |
| 108 | last_shot_distance_ = ShotDistance::VISION_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 109 | } else if (data.IsPressed(kMiddleShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 110 | last_shot_distance_ = ShotDistance::MIDDLE_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 111 | } else if (data.IsPressed(kFarShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 112 | last_shot_distance_ = ShotDistance::FAR_SHOT; |
| 113 | } |
| 114 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 115 | if (data.IsPressed(kVisionAlign) || |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 116 | data.IsPressed(kMiddleShot) || data.IsPressed(kFarShot) || |
| 117 | data.IsPressed(kFire)) { |
| 118 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 119 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 120 | hood_goal_ = 0.10; |
| 121 | shooter_velocity_ = 300.0; |
| 122 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 123 | vision_distance_shot_ = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 124 | break; |
| 125 | case ShotDistance::MIDDLE_SHOT: |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 126 | hood_goal_ = 0.43 - 0.00; |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 127 | shooter_velocity_ = 364.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 128 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 129 | break; |
| 130 | case ShotDistance::FAR_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 131 | hood_goal_ = 0.47; |
| 132 | shooter_velocity_ = 410.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 133 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 134 | break; |
| 135 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 136 | } else { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 137 | //hood_goal_ = 0.15; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 138 | shooter_velocity_ = 0.0; |
| 139 | } |
| 140 | |
| 141 | if (data.IsPressed(kExtra1)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 142 | //turret_goal_ = -M_PI * 3.0 / 4.0; |
| 143 | turret_goal_ += 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 144 | } |
| 145 | if (data.IsPressed(kExtra2)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 146 | //turret_goal_ = M_PI * 3.0 / 4.0; |
| 147 | turret_goal_ -= 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 148 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 149 | turret_goal_ = ::std::max(::std::min(turret_goal_, M_PI), -M_PI); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 150 | |
| 151 | fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 152 | if (data.IsPressed(kVisionAlign)) { |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 153 | fire_ = fire_ && superstructure_status_fetcher_->turret.vision_tracking; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 154 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 155 | |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 156 | auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage(); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 157 | if (data.IsPressed(kHang)) { |
| 158 | intake_goal_ = 0.23; |
| 159 | } |
| 160 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 161 | new_superstructure_goal->intake.distance = intake_goal_; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 162 | new_superstructure_goal->intake.disable_intake = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 163 | new_superstructure_goal->turret.angle = turret_goal_; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 164 | new_superstructure_goal->turret.track = vision_track; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 165 | new_superstructure_goal->hood.angle = hood_goal_; |
| 166 | new_superstructure_goal->shooter.angular_velocity = shooter_velocity_; |
| 167 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 168 | if (data.IsPressed(kIntakeUp)) { |
Austin Schuh | d6fa5e0 | 2017-04-12 20:52:17 -0700 | [diff] [blame] | 169 | new_superstructure_goal->intake.gear_servo = 0.30; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 170 | } else { |
| 171 | // Clamp the gear |
Austin Schuh | d6fa5e0 | 2017-04-12 20:52:17 -0700 | [diff] [blame] | 172 | new_superstructure_goal->intake.gear_servo = 0.66; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 175 | new_superstructure_goal->intake.profile_params.max_velocity = 0.50; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 176 | new_superstructure_goal->hood.profile_params.max_velocity = 5.0; |
| 177 | |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 178 | new_superstructure_goal->intake.profile_params.max_acceleration = 3.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 179 | if (vision_track) { |
| 180 | new_superstructure_goal->turret.profile_params.max_acceleration = 35.0; |
| 181 | new_superstructure_goal->turret.profile_params.max_velocity = 10.0; |
| 182 | } else { |
| 183 | new_superstructure_goal->turret.profile_params.max_acceleration = 15.0; |
| 184 | new_superstructure_goal->turret.profile_params.max_velocity = 6.0; |
| 185 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 186 | new_superstructure_goal->hood.profile_params.max_acceleration = 25.0; |
| 187 | |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 188 | new_superstructure_goal->intake.voltage_rollers = 0.0; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 189 | new_superstructure_goal->lights_on = lights_on; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 190 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 191 | if (data.IsPressed(kVisionAlign) && vision_distance_shot_) { |
| 192 | new_superstructure_goal->use_vision_for_shots = true; |
| 193 | } else { |
| 194 | new_superstructure_goal->use_vision_for_shots = false; |
| 195 | } |
| 196 | |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 197 | if (superstructure_status_fetcher_->intake.position > |
| 198 | superstructure_status_fetcher_->intake.unprofiled_goal_position + |
| 199 | 0.01) { |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 200 | intake_accumulator_ = 10; |
| 201 | } |
| 202 | if (intake_accumulator_ > 0) { |
| 203 | --intake_accumulator_; |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 204 | if (!superstructure_status_fetcher_->intake.estopped) { |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 205 | new_superstructure_goal->intake.voltage_rollers = 10.0; |
| 206 | } |
| 207 | } |
| 208 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 209 | if (data.IsPressed(kHang)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 210 | new_superstructure_goal->intake.voltage_rollers = -10.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 211 | new_superstructure_goal->intake.disable_intake = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 212 | } else if (data.IsPressed(kIntakeIn) || data.IsPressed(kFire)) { |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 213 | if (robot_velocity() > 2.0) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 214 | new_superstructure_goal->intake.voltage_rollers = 12.0; |
| 215 | } else { |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 216 | new_superstructure_goal->intake.voltage_rollers = 11.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 217 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 218 | } else if (data.IsPressed(kIntakeOut)) { |
| 219 | new_superstructure_goal->intake.voltage_rollers = -8.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 220 | } |
| 221 | if (intake_goal_ < 0.1) { |
| 222 | new_superstructure_goal->intake.voltage_rollers = |
| 223 | ::std::min(8.0, new_superstructure_goal->intake.voltage_rollers); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | if (data.IsPressed(kReverseIndexer)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 227 | new_superstructure_goal->indexer.voltage_rollers = -12.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 228 | new_superstructure_goal->indexer.angular_velocity = 4.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 229 | new_superstructure_goal->indexer.angular_velocity = 1.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 230 | } else if (fire_) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 231 | new_superstructure_goal->indexer.voltage_rollers = 12.0; |
| 232 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 233 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 234 | new_superstructure_goal->indexer.angular_velocity = -1.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 235 | break; |
| 236 | case ShotDistance::MIDDLE_SHOT: |
| 237 | case ShotDistance::FAR_SHOT: |
| 238 | new_superstructure_goal->indexer.angular_velocity = -2.25 * M_PI; |
| 239 | break; |
| 240 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 241 | } else { |
| 242 | new_superstructure_goal->indexer.voltage_rollers = 0.0; |
| 243 | new_superstructure_goal->indexer.angular_velocity = 0.0; |
| 244 | } |
| 245 | |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 246 | AOS_LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 247 | if (!new_superstructure_goal.Send()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 248 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | private: |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 253 | ::aos::Fetcher<::y2017::control_loops::SuperstructureQueue::Status> |
| 254 | superstructure_status_fetcher_; |
| 255 | ::aos::Sender<::y2017::control_loops::SuperstructureQueue::Goal> |
| 256 | superstructure_goal_sender_; |
| 257 | |
| 258 | ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT; |
| 259 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 260 | // Current goals to send to the robot. |
| 261 | double intake_goal_ = 0.0; |
| 262 | double turret_goal_ = 0.0; |
| 263 | double hood_goal_ = 0.3; |
| 264 | double shooter_velocity_ = 0.0; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 265 | int intake_accumulator_ = 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 266 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 267 | bool vision_distance_shot_ = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 268 | |
| 269 | bool fire_ = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | } // namespace joysticks |
| 273 | } // namespace input |
| 274 | } // namespace y2017 |
| 275 | |
| 276 | int main() { |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 277 | ::aos::InitNRT(true); |
| 278 | |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 279 | ::aos::ShmEventLoop event_loop; |
| 280 | ::y2017::input::joysticks::Reader reader(&event_loop); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 281 | |
| 282 | event_loop.Run(); |
| 283 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 284 | ::aos::Cleanup(); |
| 285 | } |