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 | |
| 27 | namespace y2017 { |
| 28 | namespace input { |
| 29 | namespace joysticks { |
| 30 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | namespace superstructure = control_loops::superstructure; |
| 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 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 51 | class Reader : public ::frc971::input::ActionJoystickInput { |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 52 | public: |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 53 | Reader(::aos::EventLoop *event_loop) |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 54 | : ::frc971::input::ActionJoystickInput( |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 55 | event_loop, |
| 56 | ::y2017::control_loops::drivetrain::GetDrivetrainConfig(), |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 57 | DrivetrainInputReader::InputType::kSteeringWheel, {}), |
| 58 | superstructure_status_fetcher_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 59 | event_loop |
| 60 | ->MakeFetcher<::y2017::control_loops::superstructure::Status>( |
| 61 | "/superstructure")), |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 62 | superstructure_goal_sender_( |
| 63 | event_loop |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 64 | ->MakeSender<::y2017::control_loops::superstructure::Goal>( |
| 65 | "/superstructure")) {} |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 66 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 67 | enum class ShotDistance { VISION_SHOT, MIDDLE_SHOT, FAR_SHOT }; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 68 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 69 | void HandleTeleop(const ::frc971::input::driver_station::Data &data) { |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 70 | // Default the intake to in. |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 71 | intake_goal_ = 0.07; |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 72 | bool lights_on = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 73 | bool vision_track = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 74 | |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 75 | superstructure_status_fetcher_.Fetch(); |
| 76 | if (!superstructure_status_fetcher_.get()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 77 | AOS_LOG(ERROR, "Got no superstructure status packet.\n"); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 78 | return; |
| 79 | } |
| 80 | |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 81 | if (data.IsPressed(kIntakeUp)) { |
| 82 | intake_goal_ = 0.0; |
Austin Schuh | 3ae4743 | 2017-04-16 19:15:46 -0700 | [diff] [blame] | 83 | turret_goal_ = M_PI / 3.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 84 | } |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 85 | if (data.IsPressed(kIntakeDown)) { |
| 86 | intake_goal_ = 0.235; |
| 87 | // Don't go quite so far out since we have a gear mech out now. |
| 88 | if (data.IsPressed(kIntakeUp)) { |
| 89 | intake_goal_ = 0.160; |
| 90 | } |
| 91 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 92 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 93 | if (data.IsPressed(kVisionAlign)) { |
| 94 | // Align shot using vision |
| 95 | // TODO(campbell): Add vision aligning. |
Adam Snaider | e0554ef | 2017-03-11 23:02:45 -0800 | [diff] [blame] | 96 | lights_on = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 97 | vision_track = true; |
| 98 | } |
| 99 | if (data.PosEdge(kMiddleShot)) { |
| 100 | turret_goal_ = -M_PI; |
| 101 | } |
| 102 | if (data.PosEdge(kFarShot)) { |
| 103 | turret_goal_ = 0.0; |
| 104 | } |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 105 | if (data.PosEdge(kVisionDistanceShot)) { |
| 106 | turret_goal_ = 0.0; |
| 107 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 108 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 109 | if (data.IsPressed(kVisionDistanceShot)) { |
| 110 | last_shot_distance_ = ShotDistance::VISION_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 111 | } else if (data.IsPressed(kMiddleShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 112 | last_shot_distance_ = ShotDistance::MIDDLE_SHOT; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 113 | } else if (data.IsPressed(kFarShot)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 114 | last_shot_distance_ = ShotDistance::FAR_SHOT; |
| 115 | } |
| 116 | |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 117 | if (data.IsPressed(kVisionAlign) || data.IsPressed(kMiddleShot) || |
| 118 | data.IsPressed(kFarShot) || data.IsPressed(kFire)) { |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 119 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 120 | case ShotDistance::VISION_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 121 | hood_goal_ = 0.10; |
| 122 | shooter_velocity_ = 300.0; |
| 123 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 124 | vision_distance_shot_ = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 125 | break; |
| 126 | case ShotDistance::MIDDLE_SHOT: |
Austin Schuh | 405724e | 2017-04-09 18:34:18 -0700 | [diff] [blame] | 127 | hood_goal_ = 0.43 - 0.00; |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 128 | shooter_velocity_ = 364.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 129 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 130 | break; |
| 131 | case ShotDistance::FAR_SHOT: |
Austin Schuh | 4b5f7df | 2017-04-16 20:31:12 -0700 | [diff] [blame] | 132 | hood_goal_ = 0.47; |
| 133 | shooter_velocity_ = 410.0; |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 134 | vision_distance_shot_ = false; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 135 | break; |
| 136 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 137 | } else { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 138 | // hood_goal_ = 0.15; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 139 | shooter_velocity_ = 0.0; |
| 140 | } |
| 141 | |
| 142 | if (data.IsPressed(kExtra1)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 143 | // turret_goal_ = -M_PI * 3.0 / 4.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 144 | turret_goal_ += 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 145 | } |
| 146 | if (data.IsPressed(kExtra2)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 147 | // turret_goal_ = M_PI * 3.0 / 4.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 148 | turret_goal_ -= 0.150; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 149 | } |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 150 | turret_goal_ = ::std::max(::std::min(turret_goal_, M_PI), -M_PI); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 151 | |
| 152 | fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 153 | if (data.IsPressed(kVisionAlign)) { |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 154 | fire_ = |
| 155 | fire_ && superstructure_status_fetcher_->turret()->vision_tracking(); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 156 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 157 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 158 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 159 | if (data.IsPressed(kHang)) { |
| 160 | intake_goal_ = 0.23; |
| 161 | } |
| 162 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 163 | bool intake_disable_intake = false; |
| 164 | double intake_gear_servo = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 165 | |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 166 | if (data.IsPressed(kIntakeUp)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 167 | intake_gear_servo = 0.30; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 168 | } else { |
| 169 | // Clamp the gear |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 170 | intake_gear_servo = 0.66; |
Austin Schuh | 6a8131b | 2017-04-08 15:39:22 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 173 | double intake_voltage_rollers = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 174 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 175 | if (superstructure_status_fetcher_->intake()->position() > |
| 176 | superstructure_status_fetcher_->intake()->unprofiled_goal_position() + |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 177 | 0.01) { |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 178 | intake_accumulator_ = 10; |
| 179 | } |
| 180 | if (intake_accumulator_ > 0) { |
| 181 | --intake_accumulator_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 182 | if (!superstructure_status_fetcher_->intake()->estopped()) { |
| 183 | intake_voltage_rollers = 10.0; |
Austin Schuh | 8e4a7ee | 2017-04-05 19:26:06 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 187 | if (data.IsPressed(kHang)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 188 | intake_voltage_rollers = -10.0; |
| 189 | intake_disable_intake = true; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 190 | } else if (data.IsPressed(kIntakeIn) || data.IsPressed(kFire)) { |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 191 | if (robot_velocity() > 2.0) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 192 | intake_voltage_rollers = 12.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 193 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 194 | intake_voltage_rollers = 11.0; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 195 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 196 | } else if (data.IsPressed(kIntakeOut)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 197 | intake_voltage_rollers = -8.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 198 | } |
| 199 | if (intake_goal_ < 0.1) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 200 | intake_voltage_rollers = ::std::min(8.0, intake_voltage_rollers); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 203 | double indexer_voltage_rollers = 0.0; |
| 204 | double indexer_angular_velocity = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 205 | if (data.IsPressed(kReverseIndexer)) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 206 | indexer_voltage_rollers = -12.0; |
| 207 | indexer_angular_velocity = 1.0; |
Austin Schuh | 3028b1d | 2017-03-11 22:12:13 -0800 | [diff] [blame] | 208 | } else if (fire_) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 209 | indexer_voltage_rollers = 12.0; |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 210 | switch (last_shot_distance_) { |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 211 | case ShotDistance::VISION_SHOT: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 212 | indexer_angular_velocity = -1.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 213 | break; |
| 214 | case ShotDistance::MIDDLE_SHOT: |
| 215 | case ShotDistance::FAR_SHOT: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 216 | indexer_angular_velocity = -2.25 * M_PI; |
Austin Schuh | d0629b1 | 2017-03-22 22:37:16 -0700 | [diff] [blame] | 217 | break; |
| 218 | } |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 219 | } else { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 220 | indexer_voltage_rollers = 0.0; |
| 221 | indexer_angular_velocity = 0.0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 224 | superstructure::IndexerGoal::Builder indexer_goal_builder = |
| 225 | builder.MakeBuilder<superstructure::IndexerGoal>(); |
| 226 | indexer_goal_builder.add_angular_velocity(indexer_angular_velocity); |
| 227 | indexer_goal_builder.add_voltage_rollers(indexer_voltage_rollers); |
| 228 | |
| 229 | flatbuffers::Offset<superstructure::IndexerGoal> indexer_goal_offset = |
| 230 | indexer_goal_builder.Finish(); |
| 231 | |
| 232 | flatbuffers::Offset<frc971::ProfileParameters> |
| 233 | turret_profile_parameters_offset; |
| 234 | if (vision_track) { |
| 235 | turret_profile_parameters_offset = |
| 236 | frc971::CreateProfileParameters(*builder.fbb(), 10.0, 35.0); |
| 237 | } else { |
| 238 | turret_profile_parameters_offset = |
| 239 | frc971::CreateProfileParameters(*builder.fbb(), 6.0, 15.0); |
| 240 | } |
| 241 | superstructure::TurretGoal::Builder turret_goal_builder = |
| 242 | builder.MakeBuilder<superstructure::TurretGoal>(); |
| 243 | turret_goal_builder.add_angle(turret_goal_); |
| 244 | turret_goal_builder.add_track(vision_track); |
| 245 | turret_goal_builder.add_profile_params(turret_profile_parameters_offset); |
| 246 | flatbuffers::Offset<superstructure::TurretGoal> turret_goal_offset = |
| 247 | turret_goal_builder.Finish(); |
| 248 | |
| 249 | flatbuffers::Offset<frc971::ProfileParameters> |
| 250 | intake_profile_parameters_offset = |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 251 | frc971::CreateProfileParameters(*builder.fbb(), 0.5, 3.0); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 252 | |
| 253 | superstructure::IntakeGoal::Builder intake_goal_builder = |
| 254 | builder.MakeBuilder<superstructure::IntakeGoal>(); |
| 255 | intake_goal_builder.add_voltage_rollers(intake_voltage_rollers); |
| 256 | intake_goal_builder.add_distance(intake_goal_); |
| 257 | intake_goal_builder.add_disable_intake(intake_disable_intake); |
| 258 | intake_goal_builder.add_gear_servo(intake_gear_servo); |
| 259 | intake_goal_builder.add_profile_params(intake_profile_parameters_offset); |
| 260 | flatbuffers::Offset<superstructure::IntakeGoal> intake_goal_offset = |
| 261 | intake_goal_builder.Finish(); |
| 262 | |
| 263 | flatbuffers::Offset<frc971::ProfileParameters> |
| 264 | hood_profile_parameters_offset = |
| 265 | frc971::CreateProfileParameters(*builder.fbb(), 5.0, 25.0); |
| 266 | |
| 267 | superstructure::HoodGoal::Builder hood_goal_builder = |
| 268 | builder.MakeBuilder<superstructure::HoodGoal>(); |
| 269 | hood_goal_builder.add_angle(hood_goal_); |
| 270 | hood_goal_builder.add_profile_params(hood_profile_parameters_offset); |
| 271 | flatbuffers::Offset<superstructure::HoodGoal> hood_goal_offset = |
| 272 | hood_goal_builder.Finish(); |
| 273 | |
| 274 | superstructure::ShooterGoal::Builder shooter_goal_builder = |
| 275 | builder.MakeBuilder<superstructure::ShooterGoal>(); |
| 276 | shooter_goal_builder.add_angular_velocity(shooter_velocity_); |
| 277 | flatbuffers::Offset<superstructure::ShooterGoal> shooter_goal_offset = |
| 278 | shooter_goal_builder.Finish(); |
| 279 | |
| 280 | superstructure::Goal::Builder goal_builder = |
| 281 | builder.MakeBuilder<superstructure::Goal>(); |
| 282 | goal_builder.add_lights_on(lights_on); |
| 283 | if (data.IsPressed(kVisionAlign) && vision_distance_shot_) { |
| 284 | goal_builder.add_use_vision_for_shots(true); |
| 285 | } else { |
| 286 | goal_builder.add_use_vision_for_shots(false); |
| 287 | } |
| 288 | |
| 289 | goal_builder.add_intake(intake_goal_offset); |
| 290 | goal_builder.add_indexer(indexer_goal_offset); |
| 291 | goal_builder.add_turret(turret_goal_offset); |
| 292 | goal_builder.add_hood(hood_goal_offset); |
| 293 | goal_builder.add_shooter(shooter_goal_offset); |
| 294 | |
milind | 1f1dca3 | 2021-07-03 13:50:07 -0700 | [diff] [blame] | 295 | if (builder.Send(goal_builder.Finish()) != |
| 296 | aos::RawSender::Error::kOk) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 297 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | private: |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 302 | ::aos::Fetcher<::y2017::control_loops::superstructure::Status> |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 303 | superstructure_status_fetcher_; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 304 | ::aos::Sender<::y2017::control_loops::superstructure::Goal> |
Austin Schuh | 402722c | 2019-06-29 21:27:06 -0700 | [diff] [blame] | 305 | superstructure_goal_sender_; |
| 306 | |
| 307 | ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT; |
| 308 | |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 309 | // Current goals to send to the robot. |
| 310 | double intake_goal_ = 0.0; |
| 311 | double turret_goal_ = 0.0; |
| 312 | double hood_goal_ = 0.3; |
| 313 | double shooter_velocity_ = 0.0; |
Austin Schuh | a250b2d | 2019-05-27 16:14:02 -0700 | [diff] [blame] | 314 | int intake_accumulator_ = 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 315 | |
Parker Schuh | 208a58d | 2017-04-12 20:51:38 -0700 | [diff] [blame] | 316 | bool vision_distance_shot_ = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 317 | |
| 318 | bool fire_ = false; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | } // namespace joysticks |
| 322 | } // namespace input |
| 323 | } // namespace y2017 |
| 324 | |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 325 | int main(int argc, char **argv) { |
| 326 | ::aos::InitGoogle(&argc, &argv); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 327 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 328 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame^] | 329 | aos::configuration::ReadConfig("aos_config.json"); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 330 | |
| 331 | ::aos::ShmEventLoop event_loop(&config.message()); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 332 | ::y2017::input::joysticks::Reader reader(&event_loop); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame] | 333 | |
| 334 | event_loop.Run(); |
| 335 | |
Austin Schuh | ae87e31 | 2020-08-01 16:15:01 -0700 | [diff] [blame] | 336 | return 0; |
Campbell Crowley | 71b5f13 | 2017-02-18 13:16:08 -0800 | [diff] [blame] | 337 | } |