Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 1 | #include <unistd.h> |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 2 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 3 | #include <cmath> |
| 4 | #include <cstdio> |
| 5 | #include <cstring> |
| 6 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 7 | #include "aos/actions/actions.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 8 | #include "aos/init.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 9 | #include "aos/logging/logging.h" |
| 10 | #include "aos/time/time.h" |
| 11 | #include "aos/util/log_interval.h" |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 12 | #include "frc971/autonomous/base_autonomous_actor.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 13 | #include "frc971/input/action_joystick_input.h" |
| 14 | #include "frc971/input/driver_station_data.h" |
| 15 | #include "frc971/input/drivetrain_input.h" |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 16 | #include "y2017/constants.h" |
Sabina Davis | 82b1918 | 2017-11-10 09:30:25 -0800 | [diff] [blame] | 17 | #include "y2017/control_loops/drivetrain/drivetrain_base.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 18 | #include "y2017/control_loops/superstructure/superstructure_goal_generated.h" |
| 19 | #include "y2017/control_loops/superstructure/superstructure_status_generated.h" |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 20 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 21 | using ::frc971::input::DrivetrainInputReader; |
| 22 | using ::frc971::input::driver_station::ButtonLocation; |
| 23 | using ::frc971::input::driver_station::ControlBit; |
| 24 | using ::frc971::input::driver_station::JoystickAxis; |
| 25 | using ::frc971::input::driver_station::POVLocation; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 26 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 27 | namespace y2017::input::joysticks { |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 28 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 29 | namespace superstructure = control_loops::superstructure; |
| 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 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 49 | class Reader : public ::frc971::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) |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 52 | : ::frc971::input::ActionJoystickInput( |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 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_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 57 | event_loop |
| 58 | ->MakeFetcher<::y2017::control_loops::superstructure::Status>( |
| 59 | "/superstructure")), |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 60 | superstructure_goal_sender_( |
| 61 | event_loop |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 62 | ->MakeSender<::y2017::control_loops::superstructure::Goal>( |
| 63 | "/superstructure")) {} |
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 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 67 | void HandleTeleop(const ::frc971::input::driver_station::Data &data) { |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 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 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 115 | if (data.IsPressed(kVisionAlign) || data.IsPressed(kMiddleShot) || |
| 116 | data.IsPressed(kFarShot) || data.IsPressed(kFire)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 117 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 118 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 119 | hood_goal_ = 0.10; |
| 120 | shooter_velocity_ = 300.0; |
| 121 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 122 | vision_distance_shot_ = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 123 | break; |
| 124 | case ShotDistance::MIDDLE_SHOT: |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 125 | hood_goal_ = 0.43 - 0.00; |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 126 | shooter_velocity_ = 364.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 127 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 128 | break; |
| 129 | case ShotDistance::FAR_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 130 | hood_goal_ = 0.47; |
| 131 | shooter_velocity_ = 410.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 132 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 133 | break; |
| 134 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 135 | } else { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 136 | // hood_goal_ = 0.15; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 137 | shooter_velocity_ = 0.0; |
| 138 | } |
| 139 | |
| 140 | if (data.IsPressed(kExtra1)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 141 | // turret_goal_ = -M_PI * 3.0 / 4.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 142 | turret_goal_ += 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 143 | } |
| 144 | if (data.IsPressed(kExtra2)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 145 | // turret_goal_ = M_PI * 3.0 / 4.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 146 | turret_goal_ -= 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 147 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 148 | turret_goal_ = ::std::max(::std::min(turret_goal_, M_PI), -M_PI); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 149 | |
| 150 | fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 151 | if (data.IsPressed(kVisionAlign)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 152 | fire_ = |
| 153 | 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 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 156 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 157 | if (data.IsPressed(kHang)) { |
| 158 | intake_goal_ = 0.23; |
| 159 | } |
| 160 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 161 | bool intake_disable_intake = false; |
| 162 | double intake_gear_servo = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 163 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 164 | if (data.IsPressed(kIntakeUp)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 165 | intake_gear_servo = 0.30; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 166 | } else { |
| 167 | // Clamp the gear |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 168 | intake_gear_servo = 0.66; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 171 | double intake_voltage_rollers = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 172 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 173 | if (superstructure_status_fetcher_->intake()->position() > |
| 174 | superstructure_status_fetcher_->intake()->unprofiled_goal_position() + |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 175 | 0.01) { |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 176 | intake_accumulator_ = 10; |
| 177 | } |
| 178 | if (intake_accumulator_ > 0) { |
| 179 | --intake_accumulator_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 180 | if (!superstructure_status_fetcher_->intake()->estopped()) { |
| 181 | intake_voltage_rollers = 10.0; |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 185 | if (data.IsPressed(kHang)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 186 | intake_voltage_rollers = -10.0; |
| 187 | intake_disable_intake = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 188 | } else if (data.IsPressed(kIntakeIn) || data.IsPressed(kFire)) { |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 189 | if (robot_velocity() > 2.0) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 190 | intake_voltage_rollers = 12.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 191 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 192 | intake_voltage_rollers = 11.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 193 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 194 | } else if (data.IsPressed(kIntakeOut)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 195 | intake_voltage_rollers = -8.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 196 | } |
| 197 | if (intake_goal_ < 0.1) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 198 | intake_voltage_rollers = ::std::min(8.0, intake_voltage_rollers); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 201 | double indexer_voltage_rollers = 0.0; |
| 202 | double indexer_angular_velocity = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 203 | if (data.IsPressed(kReverseIndexer)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 204 | indexer_voltage_rollers = -12.0; |
| 205 | indexer_angular_velocity = 1.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 206 | } else if (fire_) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 207 | indexer_voltage_rollers = 12.0; |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 208 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 209 | case ShotDistance::VISION_SHOT: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 210 | indexer_angular_velocity = -1.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 211 | break; |
| 212 | case ShotDistance::MIDDLE_SHOT: |
| 213 | case ShotDistance::FAR_SHOT: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 214 | indexer_angular_velocity = -2.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 215 | break; |
| 216 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 217 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 218 | indexer_voltage_rollers = 0.0; |
| 219 | indexer_angular_velocity = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 222 | superstructure::IndexerGoal::Builder indexer_goal_builder = |
| 223 | builder.MakeBuilder<superstructure::IndexerGoal>(); |
| 224 | indexer_goal_builder.add_angular_velocity(indexer_angular_velocity); |
| 225 | indexer_goal_builder.add_voltage_rollers(indexer_voltage_rollers); |
| 226 | |
| 227 | flatbuffers::Offset<superstructure::IndexerGoal> indexer_goal_offset = |
| 228 | indexer_goal_builder.Finish(); |
| 229 | |
| 230 | flatbuffers::Offset<frc971::ProfileParameters> |
| 231 | turret_profile_parameters_offset; |
| 232 | if (vision_track) { |
| 233 | turret_profile_parameters_offset = |
| 234 | frc971::CreateProfileParameters(*builder.fbb(), 10.0, 35.0); |
| 235 | } else { |
| 236 | turret_profile_parameters_offset = |
| 237 | frc971::CreateProfileParameters(*builder.fbb(), 6.0, 15.0); |
| 238 | } |
| 239 | superstructure::TurretGoal::Builder turret_goal_builder = |
| 240 | builder.MakeBuilder<superstructure::TurretGoal>(); |
| 241 | turret_goal_builder.add_angle(turret_goal_); |
| 242 | turret_goal_builder.add_track(vision_track); |
| 243 | turret_goal_builder.add_profile_params(turret_profile_parameters_offset); |
| 244 | flatbuffers::Offset<superstructure::TurretGoal> turret_goal_offset = |
| 245 | turret_goal_builder.Finish(); |
| 246 | |
| 247 | flatbuffers::Offset<frc971::ProfileParameters> |
| 248 | intake_profile_parameters_offset = |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 249 | frc971::CreateProfileParameters(*builder.fbb(), 0.5, 3.0); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 250 | |
| 251 | superstructure::IntakeGoal::Builder intake_goal_builder = |
| 252 | builder.MakeBuilder<superstructure::IntakeGoal>(); |
| 253 | intake_goal_builder.add_voltage_rollers(intake_voltage_rollers); |
| 254 | intake_goal_builder.add_distance(intake_goal_); |
| 255 | intake_goal_builder.add_disable_intake(intake_disable_intake); |
| 256 | intake_goal_builder.add_gear_servo(intake_gear_servo); |
| 257 | intake_goal_builder.add_profile_params(intake_profile_parameters_offset); |
| 258 | flatbuffers::Offset<superstructure::IntakeGoal> intake_goal_offset = |
| 259 | intake_goal_builder.Finish(); |
| 260 | |
| 261 | flatbuffers::Offset<frc971::ProfileParameters> |
| 262 | hood_profile_parameters_offset = |
| 263 | frc971::CreateProfileParameters(*builder.fbb(), 5.0, 25.0); |
| 264 | |
| 265 | superstructure::HoodGoal::Builder hood_goal_builder = |
| 266 | builder.MakeBuilder<superstructure::HoodGoal>(); |
| 267 | hood_goal_builder.add_angle(hood_goal_); |
| 268 | hood_goal_builder.add_profile_params(hood_profile_parameters_offset); |
| 269 | flatbuffers::Offset<superstructure::HoodGoal> hood_goal_offset = |
| 270 | hood_goal_builder.Finish(); |
| 271 | |
| 272 | superstructure::ShooterGoal::Builder shooter_goal_builder = |
| 273 | builder.MakeBuilder<superstructure::ShooterGoal>(); |
| 274 | shooter_goal_builder.add_angular_velocity(shooter_velocity_); |
| 275 | flatbuffers::Offset<superstructure::ShooterGoal> shooter_goal_offset = |
| 276 | shooter_goal_builder.Finish(); |
| 277 | |
| 278 | superstructure::Goal::Builder goal_builder = |
| 279 | builder.MakeBuilder<superstructure::Goal>(); |
| 280 | goal_builder.add_lights_on(lights_on); |
| 281 | if (data.IsPressed(kVisionAlign) && vision_distance_shot_) { |
| 282 | goal_builder.add_use_vision_for_shots(true); |
| 283 | } else { |
| 284 | goal_builder.add_use_vision_for_shots(false); |
| 285 | } |
| 286 | |
| 287 | goal_builder.add_intake(intake_goal_offset); |
| 288 | goal_builder.add_indexer(indexer_goal_offset); |
| 289 | goal_builder.add_turret(turret_goal_offset); |
| 290 | goal_builder.add_hood(hood_goal_offset); |
| 291 | goal_builder.add_shooter(shooter_goal_offset); |
| 292 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 293 | if (builder.Send(goal_builder.Finish()) != aos::RawSender::Error::kOk) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 294 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 299 | ::aos::Fetcher<::y2017::control_loops::superstructure::Status> |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 300 | superstructure_status_fetcher_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 301 | ::aos::Sender<::y2017::control_loops::superstructure::Goal> |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 302 | superstructure_goal_sender_; |
| 303 | |
| 304 | ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT; |
| 305 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 306 | // Current goals to send to the robot. |
| 307 | double intake_goal_ = 0.0; |
| 308 | double turret_goal_ = 0.0; |
| 309 | double hood_goal_ = 0.3; |
| 310 | double shooter_velocity_ = 0.0; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 311 | int intake_accumulator_ = 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 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; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 316 | }; |
| 317 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 318 | } // namespace y2017::input::joysticks |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 319 | |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 320 | int main(int argc, char **argv) { |
| 321 | ::aos::InitGoogle(&argc, &argv); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 322 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 323 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 324 | aos::configuration::ReadConfig("aos_config.json"); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 325 | |
| 326 | ::aos::ShmEventLoop event_loop(&config.message()); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 327 | ::y2017::input::joysticks::Reader reader(&event_loop); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 328 | |
| 329 | event_loop.Run(); |
| 330 | |
Austin Schuh | ae87e31 | 2020-08-01 16:15:01 -0700 | [diff] [blame] | 331 | return 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 332 | } |