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