blob: 618b5381d00e177a47f9c2712145ab9be5f1fa23 [file] [log] [blame]
Comran Morshed9a9948c2016-01-16 15:58:04 +00001#include <stdio.h>
2#include <string.h>
3#include <unistd.h>
4#include <math.h>
5
Austin Schuha250b2d2019-05-27 16:14:02 -07006#include "aos/actions/actions.h"
John Park398c74a2018-10-20 21:17:39 -07007#include "aos/init.h"
Austin Schuha250b2d2019-05-27 16:14:02 -07008#include "aos/input/action_joystick_input.h"
John Park33858a32018-09-28 23:05:48 -07009#include "aos/input/driver_station_data.h"
10#include "aos/logging/logging.h"
John Park33858a32018-09-28 23:05:48 -070011#include "aos/time/time.h"
Austin Schuha250b2d2019-05-27 16:14:02 -070012#include "aos/util/log_interval.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000013
Austin Schuh3028b1d2017-03-11 22:12:13 -080014#include "frc971/autonomous/auto.q.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000015#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh3028b1d2017-03-11 22:12:13 -080016#include "frc971/queues/gyro.q.h"
17#include "y2016/actors/autonomous_actor.h"
18#include "y2016/actors/superstructure_actor.h"
19#include "y2016/actors/vision_align_actor.h"
20#include "y2016/constants.h"
21#include "y2016/control_loops/drivetrain/drivetrain_base.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000022#include "y2016/control_loops/shooter/shooter.q.h"
Austin Schuh45d07f62016-03-13 15:33:31 -070023#include "y2016/control_loops/superstructure/superstructure.h"
Austin Schuh3028b1d2017-03-11 22:12:13 -080024#include "y2016/control_loops/superstructure/superstructure.q.h"
Comran Morshedaa0573c2016-03-05 19:05:54 +000025#include "y2016/queues/ball_detector.q.h"
Austin Schuhadd6d792016-03-19 01:20:01 -070026#include "y2016/vision/vision.q.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000027
Comran Morshed9a9948c2016-01-16 15:58:04 +000028using ::frc971::control_loops::drivetrain_queue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000029
30using ::aos::input::driver_station::ButtonLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000031using ::aos::input::driver_station::ControlBit;
Austin Schuh4ea06c12016-03-12 17:54:31 -080032using ::aos::input::driver_station::JoystickAxis;
33using ::aos::input::driver_station::POVLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000034
Comran Morshed6c6a0a92016-01-17 12:45:16 +000035namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000036namespace input {
37namespace joysticks {
38
Austin Schuh45d07f62016-03-13 15:33:31 -070039namespace {
40
41constexpr double kMaxIntakeAngleBeforeArmInterference = control_loops::
42 superstructure::CollisionAvoidance::kMaxIntakeAngleBeforeArmInterference;
43
44} // namespace
45
Comran Morshed9a9948c2016-01-16 15:58:04 +000046const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
Campbell Crowley5b27f022016-02-20 16:55:35 -080047const ButtonLocation kShiftHigh(2, 3), kShiftHigh2(2, 2), kShiftLow(2, 1);
Comran Morshed9a9948c2016-01-16 15:58:04 +000048const ButtonLocation kQuickTurn(1, 5);
49
Austin Schuh781cdcc2016-03-12 13:03:12 -080050const ButtonLocation kTurn1(1, 7);
51const ButtonLocation kTurn2(1, 11);
52
Comran Morshed200dd4b2016-02-16 17:54:58 +000053// Buttons on the lexan driver station to get things running on bring-up day.
Austin Schuh4ea06c12016-03-12 17:54:31 -080054const ButtonLocation kIntakeDown(3, 11);
55const POVLocation kFrontLong(3, 180);
56const POVLocation kBackLong(3, 0);
Austin Schuh45d07f62016-03-13 15:33:31 -070057const POVLocation kBackFender(3, 90);
58const POVLocation kFrontFender(3, 270);
Austin Schuh4ea06c12016-03-12 17:54:31 -080059const ButtonLocation kIntakeIn(3, 12);
Austin Schuh4ea06c12016-03-12 17:54:31 -080060const ButtonLocation kFire(3, 3);
Austin Schuh4ea06c12016-03-12 17:54:31 -080061const ButtonLocation kIntakeOut(3, 9);
Austin Schuh843412b2016-03-20 16:48:46 -070062const ButtonLocation kPortcullis(3, 7);
63const ButtonLocation kChevalDeFrise(3, 8);
Comran Morshed200dd4b2016-02-16 17:54:58 +000064
Austin Schuhadd6d792016-03-19 01:20:01 -070065const ButtonLocation kVisionAlign(3, 4);
Austin Schuh18799112016-03-16 22:09:54 -070066
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -070067const ButtonLocation kExpand(3, 6);
68const ButtonLocation kWinch(3, 5);
69
Austin Schuha250b2d2019-05-27 16:14:02 -070070class Reader : public ::aos::input::ActionJoystickInput {
Comran Morshed9a9948c2016-01-16 15:58:04 +000071 public:
Austin Schuh3e45c752019-02-02 12:19:11 -080072 Reader(::aos::EventLoop *event_loop)
Austin Schuha250b2d2019-05-27 16:14:02 -070073 : ::aos::input::ActionJoystickInput(
74 event_loop, control_loops::drivetrain::GetDrivetrainConfig(),
75 ::aos::input::DrivetrainInputReader::InputType::kSteeringWheel, {}),
Austin Schuh1bf8a212019-05-26 22:13:14 -070076 vision_status_fetcher_(
77 event_loop->MakeFetcher<::y2016::vision::VisionStatus>(
78 ".y2016.vision.vision_status")),
Austin Schuh4b652c92019-05-27 13:22:27 -070079 ball_detector_fetcher_(
80 event_loop->MakeFetcher<::y2016::sensors::BallDetector>(
81 ".y2016.sensors.ball_detector")),
Austin Schuhae023fb2019-06-29 17:11:45 -070082 shooter_goal_sender_(
83 event_loop->MakeSender<
84 ::y2016::control_loops::shooter::ShooterQueue::Goal>(
85 ".y2016.control_loops.shooter.shooter_queue.goal")),
Austin Schuh9481d0d2019-06-29 21:56:17 -070086 superstructure_status_fetcher_(
87 event_loop->MakeFetcher<
88 ::y2016::control_loops::SuperstructureQueue::Status>(
89 ".y2016.control_loops.superstructure_queue.status")),
90 superstructure_goal_sender_(
91 event_loop
92 ->MakeSender<::y2016::control_loops::SuperstructureQueue::Goal>(
93 ".y2016.control_loops.superstructure_queue.goal")),
Comran Morshed200dd4b2016-02-16 17:54:58 +000094 intake_goal_(0.0),
95 shoulder_goal_(M_PI / 2.0),
Austin Schuhd52df772016-03-19 15:38:41 -070096 wrist_goal_(0.0),
Austin Schuh1bf8a212019-05-26 22:13:14 -070097 vision_align_action_factory_(
98 actors::VisionAlignActor::MakeFactory(event_loop)),
99 superstructure_action_factory_(
Austin Schuha250b2d2019-05-27 16:14:02 -0700100 actors::SuperstructureActor::MakeFactory(event_loop)) {
101 set_vision_align_fn([this](const ::aos::input::driver_station::Data &data) {
102 return VisionAlign(data);
103 });
104 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000105
Austin Schuha250b2d2019-05-27 16:14:02 -0700106 // Returns true when we are vision aligning
107 bool VisionAlign(const ::aos::input::driver_station::Data &data) {
Austin Schuhadd6d792016-03-19 01:20:01 -0700108 vision_valid_ = false;
109
Austin Schuh1bf8a212019-05-26 22:13:14 -0700110 vision_status_fetcher_.Fetch();
Austin Schuhadd6d792016-03-19 01:20:01 -0700111
Austin Schuh1bf8a212019-05-26 22:13:14 -0700112 if (vision_status_fetcher_.get()) {
113 vision_valid_ = (vision_status_fetcher_->left_image_valid &&
114 vision_status_fetcher_->right_image_valid);
115 last_angle_ = vision_status_fetcher_->horizontal_angle;
Austin Schuhadd6d792016-03-19 01:20:01 -0700116 }
117
Austin Schuh974cf652016-04-20 20:18:13 -0700118 if (data.IsPressed(kVisionAlign)) {
119 if (vision_valid_ && !vision_action_running_) {
120 actors::VisionAlignActionParams params;
Austin Schuha250b2d2019-05-27 16:14:02 -0700121 EnqueueAction(vision_align_action_factory_.Make(params));
Austin Schuh974cf652016-04-20 20:18:13 -0700122 vision_action_running_ = true;
123 LOG(INFO, "Starting vision align\n");
124 } else {
125 if (!vision_valid_) {
126 LOG(INFO, "Vision align but not valid\n");
127 }
128 }
Austin Schuh18799112016-03-16 22:09:54 -0700129 }
130
131 if (data.NegEdge(kVisionAlign)) {
Austin Schuha250b2d2019-05-27 16:14:02 -0700132 CancelAllActions();
Austin Schuh18799112016-03-16 22:09:54 -0700133 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700134 if (!data.IsPressed(kVisionAlign)) {
135 vision_action_running_ = false;
136 }
Austin Schuh18799112016-03-16 22:09:54 -0700137
Austin Schuha250b2d2019-05-27 16:14:02 -0700138 return vision_action_running_;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000139 }
140
Comran Morshed9a9948c2016-01-16 15:58:04 +0000141 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Austin Schuha250b2d2019-05-27 16:14:02 -0700142 if (!data.GetControlBit(ControlBit::kEnabled)) {
143 // If we are not enabled, reset the waiting for zero bit.
144 LOG(DEBUG, "Waiting for zero.\n");
145 waiting_for_zero_ = true;
146 }
147
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700148 float voltage_climber = 0.0;
Austin Schuh45d07f62016-03-13 15:33:31 -0700149 // Default the intake to up.
150 intake_goal_ = constants::Values::kIntakeRange.upper - 0.04;
151
152 bool force_lights_on = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000153 if (!data.GetControlBit(ControlBit::kEnabled)) {
Austin Schuha250b2d2019-05-27 16:14:02 -0700154 CancelAllActions();
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000155 LOG(DEBUG, "Canceling\n");
Comran Morshed9a9948c2016-01-16 15:58:04 +0000156 }
157
Austin Schuh9481d0d2019-06-29 21:56:17 -0700158 superstructure_status_fetcher_.Fetch();
159 if (!superstructure_status_fetcher_.get()) {
Comran Morshed200dd4b2016-02-16 17:54:58 +0000160 LOG(ERROR, "Got no superstructure status packet.\n");
161 }
162
Austin Schuh9481d0d2019-06-29 21:56:17 -0700163 if (superstructure_status_fetcher_.get() &&
164 superstructure_status_fetcher_->zeroed) {
Comran Morshed200dd4b2016-02-16 17:54:58 +0000165 if (waiting_for_zero_) {
Austin Schuh94596dd2016-03-13 21:41:26 -0700166 LOG(DEBUG, "Zeroed! Starting teleop mode.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000167 waiting_for_zero_ = false;
168 }
169 } else {
170 waiting_for_zero_ = true;
171 }
172
Austin Schuhadd6d792016-03-19 01:20:01 -0700173 double intake_when_shooting = kMaxIntakeAngleBeforeArmInterference;
174 bool use_slow_profile = false;
175 if (vision_action_running_) {
176 use_slow_profile = true;
177 if (vision_valid_) {
178 intake_when_shooting -= 0.5;
179 }
180 }
181
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700182 if (data.IsPressed(kFrontLong)) {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800183 // Forwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700184 shoulder_goal_ = M_PI / 2.0 + 0.1;
Austin Schuh6a871ff2016-05-01 12:31:23 -0700185 wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
Austin Schuhb0099642016-04-03 21:37:27 -0700186 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700187 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700188 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800189 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700190 intake_goal_ = intake_when_shooting;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800191 } else if (data.IsPressed(kBackLong)) {
192 // Backwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700193 shoulder_goal_ = M_PI / 2.0 - 0.4;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700194 wrist_goal_ = -0.62 - 0.02;
Austin Schuhb0099642016-04-03 21:37:27 -0700195 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700196 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700197 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800198 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700199 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700200 } else if (data.IsPressed(kBackFender)) {
Adam Snaidera3271fe2016-10-26 21:03:38 -0700201 // Backwards shot no IMU
202 shoulder_goal_ = M_PI / 2.0 - 0.4;
203 wrist_goal_ = -0.62 - 0.02;
204 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700205 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700206 } else if (data.IsPressed(kFrontFender)) {
Adam Snaidera3271fe2016-10-26 21:03:38 -0700207 // Forwards shot no IMU
Austin Schuh6a871ff2016-05-01 12:31:23 -0700208 shoulder_goal_ = M_PI / 2.0 + 0.1;
Adam Snaidera3271fe2016-10-26 21:03:38 -0700209 wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
Austin Schuh6a871ff2016-05-01 12:31:23 -0700210 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700211 intake_goal_ = intake_when_shooting;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700212 } else if (data.IsPressed(kExpand) || data.IsPressed(kWinch)) {
213 // Set the goals to the hanging position so when the actor finishes, we
214 // will still be at the right spot.
215 shoulder_goal_ = 1.2;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700216 wrist_goal_ = 1.0;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700217 intake_goal_ = 0.0;
218 if (data.PosEdge(kExpand)) {
219 is_expanding_ = true;
220 actors::SuperstructureActionParams params;
221 params.partial_angle = 0.3;
222 params.delay_time = 0.7;
223 params.full_angle = shoulder_goal_;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700224 params.shooter_angle = wrist_goal_;
Austin Schuha250b2d2019-05-27 16:14:02 -0700225 EnqueueAction(superstructure_action_factory_.Make(params));
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700226 }
227 if (data.IsPressed(kWinch)) {
228 voltage_climber = 12.0;
229 }
Austin Schuhde802e92016-02-27 14:49:03 -0800230 } else {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800231 wrist_goal_ = 0.0;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800232 shoulder_goal_ = -0.010;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800233 shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000234 }
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700235 if (data.NegEdge(kExpand) || voltage_climber > 1.0) {
236 is_expanding_ = false;
Austin Schuha250b2d2019-05-27 16:14:02 -0700237 CancelAllActions();
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700238 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000239
Comran Morshedaa0573c2016-03-05 19:05:54 +0000240 bool ball_detected = false;
Austin Schuh4b652c92019-05-27 13:22:27 -0700241 ball_detector_fetcher_.Fetch();
242 if (ball_detector_fetcher_.get()) {
243 ball_detected = ball_detector_fetcher_->voltage > 2.5;
Comran Morshedaa0573c2016-03-05 19:05:54 +0000244 }
245 if (data.PosEdge(kIntakeIn)) {
246 saw_ball_when_started_intaking_ = ball_detected;
247 }
248
Austin Schuh45d07f62016-03-13 15:33:31 -0700249 if (data.IsPressed(kIntakeIn)) {
250 is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_);
251 if (ball_detected) {
252 force_lights_on = true;
253 }
254 } else {
255 is_intaking_ = false;
256 }
257
Austin Schuhd52df772016-03-19 15:38:41 -0700258 fire_ = false;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800259 if (data.IsPressed(kFire) && shooter_velocity_ != 0.0) {
Austin Schuhd52df772016-03-19 15:38:41 -0700260 if (data.IsPressed(kVisionAlign)) {
261 // Make sure that we are lined up.
262 drivetrain_queue.status.FetchLatest();
263 drivetrain_queue.goal.FetchLatest();
264 if (drivetrain_queue.status.get() && drivetrain_queue.goal.get()) {
265 const double left_goal = drivetrain_queue.goal->left_goal;
266 const double right_goal = drivetrain_queue.goal->right_goal;
267 const double left_current =
268 drivetrain_queue.status->estimated_left_position;
269 const double right_current =
270 drivetrain_queue.status->estimated_right_position;
271 const double left_velocity =
272 drivetrain_queue.status->estimated_left_velocity;
273 const double right_velocity =
274 drivetrain_queue.status->estimated_right_velocity;
275 if (vision_action_running_ && ::std::abs(last_angle_) < 0.02 &&
276 ::std::abs((left_goal - right_goal) -
277 (left_current - right_current)) /
Austin Schuha250b2d2019-05-27 16:14:02 -0700278 dt_config().robot_radius / 2.0 <
Austin Schuhd52df772016-03-19 15:38:41 -0700279 0.02 &&
280 ::std::abs(left_velocity - right_velocity) < 0.01) {
281 ++ready_to_fire_;
282 } else {
283 ready_to_fire_ = 0;
284 }
Austin Schuh3d79cc02016-03-20 21:08:53 -0700285 if (ready_to_fire_ > 9) {
Austin Schuhd52df772016-03-19 15:38:41 -0700286 fire_ = true;
287 }
288 }
289 } else {
290 fire_ = true;
291 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000292 }
293
Austin Schuh4ea06c12016-03-12 17:54:31 -0800294 is_outtaking_ = data.IsPressed(kIntakeOut);
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800295
Austin Schuhd52df772016-03-19 15:38:41 -0700296 if (is_intaking_ || is_outtaking_) {
297 recently_intaking_accumulator_ = 20;
298 }
299
300 if (data.IsPressed(kIntakeDown)) {
301 if (recently_intaking_accumulator_) {
302 intake_goal_ = 0.1;
303 } else {
304 intake_goal_ = -0.05;
305 }
306 }
307
308 if (recently_intaking_accumulator_ > 0) {
309 --recently_intaking_accumulator_;
310 }
311
Austin Schuh843412b2016-03-20 16:48:46 -0700312 if (data.IsPressed(kPortcullis)) {
313 traverse_unlatched_ = true;
314 traverse_down_ = true;
315 } else if (data.IsPressed(kChevalDeFrise)) {
316 traverse_unlatched_ = false;
317 traverse_down_ = true;
318 } else {
319 traverse_unlatched_ = true;
320 traverse_down_ = false;
321 }
322
Comran Morshed200dd4b2016-02-16 17:54:58 +0000323 if (!waiting_for_zero_) {
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700324 if (!is_expanding_) {
Austin Schuh9481d0d2019-06-29 21:56:17 -0700325 auto new_superstructure_goal =
326 superstructure_goal_sender_.MakeMessage();
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700327 new_superstructure_goal->angle_intake = intake_goal_;
328 new_superstructure_goal->angle_shoulder = shoulder_goal_;
329 new_superstructure_goal->angle_wrist = wrist_goal_;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800330
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700331 new_superstructure_goal->max_angular_velocity_intake = 7.0;
332 new_superstructure_goal->max_angular_velocity_shoulder = 4.0;
333 new_superstructure_goal->max_angular_velocity_wrist = 10.0;
334 if (use_slow_profile) {
335 new_superstructure_goal->max_angular_acceleration_intake = 10.0;
336 } else {
337 new_superstructure_goal->max_angular_acceleration_intake = 40.0;
338 }
339 new_superstructure_goal->max_angular_acceleration_shoulder = 10.0;
340 if (shoulder_goal_ > 1.0) {
341 new_superstructure_goal->max_angular_acceleration_wrist = 45.0;
342 } else {
343 new_superstructure_goal->max_angular_acceleration_wrist = 25.0;
344 }
Austin Schuh3f0b1192016-03-12 13:03:56 -0800345
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700346 // Granny mode
347 /*
348 new_superstructure_goal->max_angular_velocity_intake = 0.2;
349 new_superstructure_goal->max_angular_velocity_shoulder = 0.2;
350 new_superstructure_goal->max_angular_velocity_wrist = 0.2;
351 new_superstructure_goal->max_angular_acceleration_intake = 1.0;
352 new_superstructure_goal->max_angular_acceleration_shoulder = 1.0;
353 new_superstructure_goal->max_angular_acceleration_wrist = 1.0;
354 */
355 if (is_intaking_) {
356 new_superstructure_goal->voltage_top_rollers = 12.0;
357 new_superstructure_goal->voltage_bottom_rollers = 12.0;
358 } else if (is_outtaking_) {
359 new_superstructure_goal->voltage_top_rollers = -12.0;
360 new_superstructure_goal->voltage_bottom_rollers = -7.0;
361 } else {
362 new_superstructure_goal->voltage_top_rollers = 0.0;
363 new_superstructure_goal->voltage_bottom_rollers = 0.0;
364 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000365
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700366 new_superstructure_goal->traverse_unlatched = traverse_unlatched_;
367 new_superstructure_goal->unfold_climber = false;
368 new_superstructure_goal->voltage_climber = voltage_climber;
369 new_superstructure_goal->traverse_down = traverse_down_;
370 new_superstructure_goal->force_intake = true;
Austin Schuh843412b2016-03-20 16:48:46 -0700371
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700372 if (!new_superstructure_goal.Send()) {
373 LOG(ERROR, "Sending superstructure goal failed.\n");
374 } else {
375 LOG(DEBUG, "sending goals: intake: %f, shoulder: %f, wrist: %f\n",
376 intake_goal_, shoulder_goal_, wrist_goal_);
377 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700378 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000379
Austin Schuhae023fb2019-06-29 17:11:45 -0700380 auto shooter_message = shooter_goal_sender_.MakeMessage();
381 shooter_message->angular_velocity = shooter_velocity_;
382 shooter_message->clamp_open = is_intaking_ || is_outtaking_;
383 shooter_message->push_to_shooter = fire_;
384 shooter_message->force_lights_on = force_lights_on;
385 shooter_message->shooting_forwards = wrist_goal_ > 0;
386
387 if (!shooter_message.Send()) {
Austin Schuhadd6d792016-03-19 01:20:01 -0700388 LOG(ERROR, "Sending shooter goal failed.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000389 }
390 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000391 }
392
Comran Morshed9a9948c2016-01-16 15:58:04 +0000393 private:
Austin Schuh1bf8a212019-05-26 22:13:14 -0700394 ::aos::Fetcher<::y2016::vision::VisionStatus> vision_status_fetcher_;
Austin Schuh4b652c92019-05-27 13:22:27 -0700395 ::aos::Fetcher<::y2016::sensors::BallDetector> ball_detector_fetcher_;
Austin Schuhae023fb2019-06-29 17:11:45 -0700396 ::aos::Sender<::y2016::control_loops::shooter::ShooterQueue::Goal>
397 shooter_goal_sender_;
Austin Schuh9481d0d2019-06-29 21:56:17 -0700398 ::aos::Fetcher<::y2016::control_loops::SuperstructureQueue::Status>
399 superstructure_status_fetcher_;
400 ::aos::Sender<::y2016::control_loops::SuperstructureQueue::Goal>
401 superstructure_goal_sender_;
Austin Schuh1bf8a212019-05-26 22:13:14 -0700402
Comran Morshed200dd4b2016-02-16 17:54:58 +0000403 // Whatever these are set to are our default goals to send out after zeroing.
404 double intake_goal_;
405 double shoulder_goal_;
406 double wrist_goal_;
Austin Schuhde802e92016-02-27 14:49:03 -0800407 double shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000408
Austin Schuh843412b2016-03-20 16:48:46 -0700409 bool traverse_unlatched_ = false;
410 bool traverse_down_ = false;
411
Comran Morshed200dd4b2016-02-16 17:54:58 +0000412 // If we're waiting for the subsystems to zero.
413 bool waiting_for_zero_ = true;
414
Comran Morshedaa0573c2016-03-05 19:05:54 +0000415 // If true, the ball was present when the intaking button was pressed.
416 bool saw_ball_when_started_intaking_ = false;
417
Austin Schuhde802e92016-02-27 14:49:03 -0800418 bool is_intaking_ = false;
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800419 bool is_outtaking_ = false;
Austin Schuhde802e92016-02-27 14:49:03 -0800420 bool fire_ = false;
421
Austin Schuhadd6d792016-03-19 01:20:01 -0700422 bool vision_action_running_ = false;
423 bool vision_valid_ = false;
424
Austin Schuhd52df772016-03-19 15:38:41 -0700425 int recently_intaking_accumulator_ = 0;
426 double last_angle_ = 100;
427
428 int ready_to_fire_ = 0;
429
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700430 bool is_expanding_ = false;
431
Austin Schuh1bf8a212019-05-26 22:13:14 -0700432 actors::VisionAlignActor::Factory vision_align_action_factory_;
433 actors::SuperstructureActor::Factory superstructure_action_factory_;
434
Comran Morshed9a9948c2016-01-16 15:58:04 +0000435 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
Austin Schuh61bdc602016-12-04 19:10:10 -0800436 ::aos::util::SimpleLogInterval(::std::chrono::milliseconds(200), WARNING,
Comran Morshed9a9948c2016-01-16 15:58:04 +0000437 "no drivetrain status");
438};
439
440} // namespace joysticks
441} // namespace input
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000442} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000443
444int main() {
445 ::aos::Init(-1);
Austin Schuh3e45c752019-02-02 12:19:11 -0800446 ::aos::ShmEventLoop event_loop;
447 ::y2016::input::joysticks::Reader reader(&event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000448 reader.Run();
449 ::aos::Cleanup();
450}