blob: 19cd065d3daedb558b9c3c7565bad6982b155726 [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
John Park398c74a2018-10-20 21:17:39 -07006#include "aos/init.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +00007#include "aos/input/joystick_input.h"
John Park33858a32018-09-28 23:05:48 -07008#include "aos/input/driver_station_data.h"
9#include "aos/logging/logging.h"
10#include "aos/util/log_interval.h"
11#include "aos/time/time.h"
12#include "aos/actions/actions.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 Morshed200dd4b2016-02-16 17:54:58 +000029using ::y2016::control_loops::shooter::shooter_queue;
30using ::y2016::control_loops::superstructure_queue;
Comran Morshed9a9948c2016-01-16 15:58:04 +000031
32using ::aos::input::driver_station::ButtonLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000033using ::aos::input::driver_station::ControlBit;
Austin Schuh4ea06c12016-03-12 17:54:31 -080034using ::aos::input::driver_station::JoystickAxis;
35using ::aos::input::driver_station::POVLocation;
Comran Morshed9a9948c2016-01-16 15:58:04 +000036
Comran Morshed6c6a0a92016-01-17 12:45:16 +000037namespace y2016 {
Comran Morshed9a9948c2016-01-16 15:58:04 +000038namespace input {
39namespace joysticks {
40
Austin Schuh45d07f62016-03-13 15:33:31 -070041namespace {
42
43constexpr double kMaxIntakeAngleBeforeArmInterference = control_loops::
44 superstructure::CollisionAvoidance::kMaxIntakeAngleBeforeArmInterference;
45
46} // namespace
47
Comran Morshed9a9948c2016-01-16 15:58:04 +000048const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
Campbell Crowley5b27f022016-02-20 16:55:35 -080049const ButtonLocation kShiftHigh(2, 3), kShiftHigh2(2, 2), kShiftLow(2, 1);
Comran Morshed9a9948c2016-01-16 15:58:04 +000050const ButtonLocation kQuickTurn(1, 5);
51
Austin Schuh781cdcc2016-03-12 13:03:12 -080052const ButtonLocation kTurn1(1, 7);
53const ButtonLocation kTurn2(1, 11);
54
Comran Morshed200dd4b2016-02-16 17:54:58 +000055// Buttons on the lexan driver station to get things running on bring-up day.
Austin Schuh4ea06c12016-03-12 17:54:31 -080056const ButtonLocation kIntakeDown(3, 11);
57const POVLocation kFrontLong(3, 180);
58const POVLocation kBackLong(3, 0);
Austin Schuh45d07f62016-03-13 15:33:31 -070059const POVLocation kBackFender(3, 90);
60const POVLocation kFrontFender(3, 270);
Austin Schuh4ea06c12016-03-12 17:54:31 -080061const ButtonLocation kIntakeIn(3, 12);
Austin Schuh4ea06c12016-03-12 17:54:31 -080062const ButtonLocation kFire(3, 3);
Austin Schuh4ea06c12016-03-12 17:54:31 -080063const ButtonLocation kIntakeOut(3, 9);
Austin Schuh843412b2016-03-20 16:48:46 -070064const ButtonLocation kPortcullis(3, 7);
65const ButtonLocation kChevalDeFrise(3, 8);
Comran Morshed200dd4b2016-02-16 17:54:58 +000066
Austin Schuhadd6d792016-03-19 01:20:01 -070067const ButtonLocation kVisionAlign(3, 4);
Austin Schuh18799112016-03-16 22:09:54 -070068
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -070069const ButtonLocation kExpand(3, 6);
70const ButtonLocation kWinch(3, 5);
71
Comran Morshed9a9948c2016-01-16 15:58:04 +000072class Reader : public ::aos::input::JoystickInput {
73 public:
Austin Schuh3e45c752019-02-02 12:19:11 -080074 Reader(::aos::EventLoop *event_loop)
75 : ::aos::input::JoystickInput(event_loop),
76 is_high_gear_(true),
Comran Morshed200dd4b2016-02-16 17:54:58 +000077 intake_goal_(0.0),
78 shoulder_goal_(M_PI / 2.0),
Austin Schuhd52df772016-03-19 15:38:41 -070079 wrist_goal_(0.0),
80 dt_config_(control_loops::drivetrain::GetDrivetrainConfig()) {}
Comran Morshed9a9948c2016-01-16 15:58:04 +000081
82 void RunIteration(const ::aos::input::driver_station::Data &data) override {
83 bool last_auto_running = auto_running_;
84 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
85 data.GetControlBit(ControlBit::kEnabled);
86 if (auto_running_ != last_auto_running) {
87 if (auto_running_) {
88 StartAuto();
89 } else {
90 StopAuto();
91 }
92 }
93
Austin Schuh94596dd2016-03-13 21:41:26 -070094 if (!data.GetControlBit(ControlBit::kEnabled)) {
95 // If we are not enabled, reset the waiting for zero bit.
96 LOG(DEBUG, "Waiting for zero.\n");
97 waiting_for_zero_ = true;
98 is_high_gear_ = true;
99 }
100
Austin Schuhadd6d792016-03-19 01:20:01 -0700101 vision_valid_ = false;
102
103 ::y2016::vision::vision_status.FetchLatest();
104
105 if (::y2016::vision::vision_status.get()) {
106 vision_valid_ = (::y2016::vision::vision_status->left_image_valid &&
107 ::y2016::vision::vision_status->right_image_valid);
Austin Schuhd52df772016-03-19 15:38:41 -0700108 last_angle_ = ::y2016::vision::vision_status->horizontal_angle;
Austin Schuhadd6d792016-03-19 01:20:01 -0700109 }
110
Austin Schuh94596dd2016-03-13 21:41:26 -0700111 if (!auto_running_) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000112 HandleDrivetrain(data);
113 HandleTeleop(data);
114 }
Austin Schuh81d71db2016-03-15 20:56:24 -0700115
116 // Process any pending actions.
117 action_queue_.Tick();
118 was_running_ = action_queue_.Running();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000119 }
120
121 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
122 bool is_control_loop_driving = false;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800123
Comran Morshed9a9948c2016-01-16 15:58:04 +0000124 const double wheel = -data.GetAxis(kSteeringWheel);
125 const double throttle = -data.GetAxis(kDriveThrottle);
Austin Schuhb0099642016-04-03 21:37:27 -0700126 drivetrain_queue.status.FetchLatest();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000127
Austin Schuh974cf652016-04-20 20:18:13 -0700128 if (data.IsPressed(kVisionAlign)) {
129 if (vision_valid_ && !vision_action_running_) {
130 actors::VisionAlignActionParams params;
131 action_queue_.EnqueueAction(actors::MakeVisionAlignAction(params));
132 vision_action_running_ = true;
133 LOG(INFO, "Starting vision align\n");
134 } else {
135 if (!vision_valid_) {
136 LOG(INFO, "Vision align but not valid\n");
137 }
138 }
Austin Schuh18799112016-03-16 22:09:54 -0700139 }
140
141 if (data.NegEdge(kVisionAlign)) {
142 action_queue_.CancelAllActions();
143 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700144 if (!data.IsPressed(kVisionAlign)) {
145 vision_action_running_ = false;
146 }
Austin Schuh18799112016-03-16 22:09:54 -0700147
148 // Don't do any normal drivetrain stuff if vision is in charge.
Austin Schuhfef64ac2016-04-24 19:08:01 -0700149 if (vision_action_running_) {
Austin Schuh18799112016-03-16 22:09:54 -0700150 return;
151 }
152
Austin Schuh781cdcc2016-03-12 13:03:12 -0800153 if (data.PosEdge(kTurn1) || data.PosEdge(kTurn2)) {
Austin Schuh781cdcc2016-03-12 13:03:12 -0800154 if (drivetrain_queue.status.get()) {
Adam Snaider418bd822016-11-26 14:49:23 -0800155 left_goal_ = drivetrain_queue.status->estimated_left_position;
156 right_goal_ = drivetrain_queue.status->estimated_right_position;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800157 }
158 }
159 if (data.IsPressed(kTurn1) || data.IsPressed(kTurn2)) {
160 is_control_loop_driving = true;
161 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000162 if (!drivetrain_queue.goal.MakeWithBuilder()
Austin Schuh2b1fce02018-03-02 20:05:20 -0800163 .wheel(wheel)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000164 .throttle(throttle)
165 .highgear(is_high_gear_)
166 .quickturn(data.IsPressed(kQuickTurn))
Austin Schuh78379ea2019-01-04 20:39:45 -0800167 .controller_type(is_control_loop_driving ? 1 : 0)
Adam Snaider418bd822016-11-26 14:49:23 -0800168 .left_goal(left_goal_ - wheel * 0.5 + throttle * 0.3)
169 .right_goal(right_goal_ + wheel * 0.5 + throttle * 0.3)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000170 .Send()) {
171 LOG(WARNING, "sending stick values failed\n");
172 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000173
Campbell Crowley5b27f022016-02-20 16:55:35 -0800174 if (data.PosEdge(kShiftLow)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000175 is_high_gear_ = false;
176 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000177
Campbell Crowley5b27f022016-02-20 16:55:35 -0800178 if (data.PosEdge(kShiftHigh) || data.PosEdge(kShiftHigh2)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000179 is_high_gear_ = true;
180 }
181 }
182
Comran Morshed9a9948c2016-01-16 15:58:04 +0000183 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700184 float voltage_climber = 0.0;
Austin Schuh45d07f62016-03-13 15:33:31 -0700185 // Default the intake to up.
186 intake_goal_ = constants::Values::kIntakeRange.upper - 0.04;
187
188 bool force_lights_on = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000189 if (!data.GetControlBit(ControlBit::kEnabled)) {
190 action_queue_.CancelAllActions();
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000191 LOG(DEBUG, "Canceling\n");
Comran Morshed9a9948c2016-01-16 15:58:04 +0000192 }
193
Comran Morshed200dd4b2016-02-16 17:54:58 +0000194 superstructure_queue.status.FetchLatest();
195 if (!superstructure_queue.status.get()) {
196 LOG(ERROR, "Got no superstructure status packet.\n");
197 }
198
199 if (superstructure_queue.status.get() &&
200 superstructure_queue.status->zeroed) {
201 if (waiting_for_zero_) {
Austin Schuh94596dd2016-03-13 21:41:26 -0700202 LOG(DEBUG, "Zeroed! Starting teleop mode.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000203 waiting_for_zero_ = false;
204 }
205 } else {
206 waiting_for_zero_ = true;
207 }
208
Austin Schuhadd6d792016-03-19 01:20:01 -0700209 double intake_when_shooting = kMaxIntakeAngleBeforeArmInterference;
210 bool use_slow_profile = false;
211 if (vision_action_running_) {
212 use_slow_profile = true;
213 if (vision_valid_) {
214 intake_when_shooting -= 0.5;
215 }
216 }
217
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700218 if (data.IsPressed(kFrontLong)) {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800219 // Forwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700220 shoulder_goal_ = M_PI / 2.0 + 0.1;
Austin Schuh6a871ff2016-05-01 12:31:23 -0700221 wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
Austin Schuhb0099642016-04-03 21:37:27 -0700222 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700223 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700224 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800225 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700226 intake_goal_ = intake_when_shooting;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800227 } else if (data.IsPressed(kBackLong)) {
228 // Backwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700229 shoulder_goal_ = M_PI / 2.0 - 0.4;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700230 wrist_goal_ = -0.62 - 0.02;
Austin Schuhb0099642016-04-03 21:37:27 -0700231 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700232 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700233 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800234 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700235 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700236 } else if (data.IsPressed(kBackFender)) {
Adam Snaidera3271fe2016-10-26 21:03:38 -0700237 // Backwards shot no IMU
238 shoulder_goal_ = M_PI / 2.0 - 0.4;
239 wrist_goal_ = -0.62 - 0.02;
240 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700241 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700242 } else if (data.IsPressed(kFrontFender)) {
Adam Snaidera3271fe2016-10-26 21:03:38 -0700243 // Forwards shot no IMU
Austin Schuh6a871ff2016-05-01 12:31:23 -0700244 shoulder_goal_ = M_PI / 2.0 + 0.1;
Adam Snaidera3271fe2016-10-26 21:03:38 -0700245 wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
Austin Schuh6a871ff2016-05-01 12:31:23 -0700246 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700247 intake_goal_ = intake_when_shooting;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700248 } else if (data.IsPressed(kExpand) || data.IsPressed(kWinch)) {
249 // Set the goals to the hanging position so when the actor finishes, we
250 // will still be at the right spot.
251 shoulder_goal_ = 1.2;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700252 wrist_goal_ = 1.0;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700253 intake_goal_ = 0.0;
254 if (data.PosEdge(kExpand)) {
255 is_expanding_ = true;
256 actors::SuperstructureActionParams params;
257 params.partial_angle = 0.3;
258 params.delay_time = 0.7;
259 params.full_angle = shoulder_goal_;
Austin Schuhfef64ac2016-04-24 19:08:01 -0700260 params.shooter_angle = wrist_goal_;
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700261 action_queue_.EnqueueAction(actors::MakeSuperstructureAction(params));
262 }
263 if (data.IsPressed(kWinch)) {
264 voltage_climber = 12.0;
265 }
Austin Schuhde802e92016-02-27 14:49:03 -0800266 } else {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800267 wrist_goal_ = 0.0;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800268 shoulder_goal_ = -0.010;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800269 shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000270 }
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700271 if (data.NegEdge(kExpand) || voltage_climber > 1.0) {
272 is_expanding_ = false;
273 action_queue_.CancelAllActions();
274 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000275
Comran Morshedaa0573c2016-03-05 19:05:54 +0000276 bool ball_detected = false;
277 ::y2016::sensors::ball_detector.FetchLatest();
278 if (::y2016::sensors::ball_detector.get()) {
279 ball_detected = ::y2016::sensors::ball_detector->voltage > 2.5;
280 }
281 if (data.PosEdge(kIntakeIn)) {
282 saw_ball_when_started_intaking_ = ball_detected;
283 }
284
Austin Schuh45d07f62016-03-13 15:33:31 -0700285 if (data.IsPressed(kIntakeIn)) {
286 is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_);
287 if (ball_detected) {
288 force_lights_on = true;
289 }
290 } else {
291 is_intaking_ = false;
292 }
293
Austin Schuhd52df772016-03-19 15:38:41 -0700294 fire_ = false;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800295 if (data.IsPressed(kFire) && shooter_velocity_ != 0.0) {
Austin Schuhd52df772016-03-19 15:38:41 -0700296 if (data.IsPressed(kVisionAlign)) {
297 // Make sure that we are lined up.
298 drivetrain_queue.status.FetchLatest();
299 drivetrain_queue.goal.FetchLatest();
300 if (drivetrain_queue.status.get() && drivetrain_queue.goal.get()) {
301 const double left_goal = drivetrain_queue.goal->left_goal;
302 const double right_goal = drivetrain_queue.goal->right_goal;
303 const double left_current =
304 drivetrain_queue.status->estimated_left_position;
305 const double right_current =
306 drivetrain_queue.status->estimated_right_position;
307 const double left_velocity =
308 drivetrain_queue.status->estimated_left_velocity;
309 const double right_velocity =
310 drivetrain_queue.status->estimated_right_velocity;
311 if (vision_action_running_ && ::std::abs(last_angle_) < 0.02 &&
312 ::std::abs((left_goal - right_goal) -
313 (left_current - right_current)) /
314 dt_config_.robot_radius / 2.0 <
315 0.02 &&
316 ::std::abs(left_velocity - right_velocity) < 0.01) {
317 ++ready_to_fire_;
318 } else {
319 ready_to_fire_ = 0;
320 }
Austin Schuh3d79cc02016-03-20 21:08:53 -0700321 if (ready_to_fire_ > 9) {
Austin Schuhd52df772016-03-19 15:38:41 -0700322 fire_ = true;
323 }
324 }
325 } else {
326 fire_ = true;
327 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000328 }
329
Austin Schuh4ea06c12016-03-12 17:54:31 -0800330 is_outtaking_ = data.IsPressed(kIntakeOut);
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800331
Austin Schuhd52df772016-03-19 15:38:41 -0700332 if (is_intaking_ || is_outtaking_) {
333 recently_intaking_accumulator_ = 20;
334 }
335
336 if (data.IsPressed(kIntakeDown)) {
337 if (recently_intaking_accumulator_) {
338 intake_goal_ = 0.1;
339 } else {
340 intake_goal_ = -0.05;
341 }
342 }
343
344 if (recently_intaking_accumulator_ > 0) {
345 --recently_intaking_accumulator_;
346 }
347
Austin Schuh843412b2016-03-20 16:48:46 -0700348 if (data.IsPressed(kPortcullis)) {
349 traverse_unlatched_ = true;
350 traverse_down_ = true;
351 } else if (data.IsPressed(kChevalDeFrise)) {
352 traverse_unlatched_ = false;
353 traverse_down_ = true;
354 } else {
355 traverse_unlatched_ = true;
356 traverse_down_ = false;
357 }
358
Comran Morshed200dd4b2016-02-16 17:54:58 +0000359 if (!waiting_for_zero_) {
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700360 if (!is_expanding_) {
361 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
362 new_superstructure_goal->angle_intake = intake_goal_;
363 new_superstructure_goal->angle_shoulder = shoulder_goal_;
364 new_superstructure_goal->angle_wrist = wrist_goal_;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800365
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700366 new_superstructure_goal->max_angular_velocity_intake = 7.0;
367 new_superstructure_goal->max_angular_velocity_shoulder = 4.0;
368 new_superstructure_goal->max_angular_velocity_wrist = 10.0;
369 if (use_slow_profile) {
370 new_superstructure_goal->max_angular_acceleration_intake = 10.0;
371 } else {
372 new_superstructure_goal->max_angular_acceleration_intake = 40.0;
373 }
374 new_superstructure_goal->max_angular_acceleration_shoulder = 10.0;
375 if (shoulder_goal_ > 1.0) {
376 new_superstructure_goal->max_angular_acceleration_wrist = 45.0;
377 } else {
378 new_superstructure_goal->max_angular_acceleration_wrist = 25.0;
379 }
Austin Schuh3f0b1192016-03-12 13:03:56 -0800380
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700381 // Granny mode
382 /*
383 new_superstructure_goal->max_angular_velocity_intake = 0.2;
384 new_superstructure_goal->max_angular_velocity_shoulder = 0.2;
385 new_superstructure_goal->max_angular_velocity_wrist = 0.2;
386 new_superstructure_goal->max_angular_acceleration_intake = 1.0;
387 new_superstructure_goal->max_angular_acceleration_shoulder = 1.0;
388 new_superstructure_goal->max_angular_acceleration_wrist = 1.0;
389 */
390 if (is_intaking_) {
391 new_superstructure_goal->voltage_top_rollers = 12.0;
392 new_superstructure_goal->voltage_bottom_rollers = 12.0;
393 } else if (is_outtaking_) {
394 new_superstructure_goal->voltage_top_rollers = -12.0;
395 new_superstructure_goal->voltage_bottom_rollers = -7.0;
396 } else {
397 new_superstructure_goal->voltage_top_rollers = 0.0;
398 new_superstructure_goal->voltage_bottom_rollers = 0.0;
399 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000400
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700401 new_superstructure_goal->traverse_unlatched = traverse_unlatched_;
402 new_superstructure_goal->unfold_climber = false;
403 new_superstructure_goal->voltage_climber = voltage_climber;
404 new_superstructure_goal->traverse_down = traverse_down_;
405 new_superstructure_goal->force_intake = true;
Austin Schuh843412b2016-03-20 16:48:46 -0700406
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700407 if (!new_superstructure_goal.Send()) {
408 LOG(ERROR, "Sending superstructure goal failed.\n");
409 } else {
410 LOG(DEBUG, "sending goals: intake: %f, shoulder: %f, wrist: %f\n",
411 intake_goal_, shoulder_goal_, wrist_goal_);
412 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700413 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000414
Austin Schuhadd6d792016-03-19 01:20:01 -0700415 if (!shooter_queue.goal.MakeWithBuilder()
416 .angular_velocity(shooter_velocity_)
417 .clamp_open(is_intaking_ || is_outtaking_)
418 .push_to_shooter(fire_)
419 .force_lights_on(force_lights_on)
Austin Schuhb2c33382016-04-03 16:09:17 -0700420 .shooting_forwards(wrist_goal_ > 0)
Austin Schuhadd6d792016-03-19 01:20:01 -0700421 .Send()) {
422 LOG(ERROR, "Sending shooter goal failed.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000423 }
424 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000425 }
426
Comran Morshed9a9948c2016-01-16 15:58:04 +0000427 private:
428 void StartAuto() {
429 LOG(INFO, "Starting auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000430
Philipp Schrader4bd29b12017-02-22 04:42:27 +0000431 ::frc971::autonomous::AutonomousActionParams params;
432 ::frc971::autonomous::auto_mode.FetchLatest();
433 if (::frc971::autonomous::auto_mode.get() != nullptr) {
434 params.mode = ::frc971::autonomous::auto_mode->mode;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700435 } else {
436 LOG(WARNING, "no auto mode values\n");
437 params.mode = 0;
438 }
Philipp Schrader4bd29b12017-02-22 04:42:27 +0000439 action_queue_.EnqueueAction(
440 ::frc971::autonomous::MakeAutonomousAction(params));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000441 }
442
443 void StopAuto() {
444 LOG(INFO, "Stopping auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000445 action_queue_.CancelAllActions();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000446 }
447
448 bool is_high_gear_;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000449 // Whatever these are set to are our default goals to send out after zeroing.
450 double intake_goal_;
451 double shoulder_goal_;
452 double wrist_goal_;
Austin Schuhde802e92016-02-27 14:49:03 -0800453 double shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000454
Adam Snaidera3271fe2016-10-26 21:03:38 -0700455 // Turning goals
Adam Snaider418bd822016-11-26 14:49:23 -0800456 double left_goal_;
457 double right_goal_;
Adam Snaidera3271fe2016-10-26 21:03:38 -0700458
Comran Morshed200dd4b2016-02-16 17:54:58 +0000459 bool was_running_ = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000460 bool auto_running_ = false;
461
Austin Schuh843412b2016-03-20 16:48:46 -0700462 bool traverse_unlatched_ = false;
463 bool traverse_down_ = false;
464
Comran Morshed200dd4b2016-02-16 17:54:58 +0000465 // If we're waiting for the subsystems to zero.
466 bool waiting_for_zero_ = true;
467
Comran Morshedaa0573c2016-03-05 19:05:54 +0000468 // If true, the ball was present when the intaking button was pressed.
469 bool saw_ball_when_started_intaking_ = false;
470
Austin Schuhde802e92016-02-27 14:49:03 -0800471 bool is_intaking_ = false;
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800472 bool is_outtaking_ = false;
Austin Schuhde802e92016-02-27 14:49:03 -0800473 bool fire_ = false;
474
Austin Schuhadd6d792016-03-19 01:20:01 -0700475 bool vision_action_running_ = false;
476 bool vision_valid_ = false;
477
Austin Schuhd52df772016-03-19 15:38:41 -0700478 int recently_intaking_accumulator_ = 0;
479 double last_angle_ = 100;
480
481 int ready_to_fire_ = 0;
482
Comran Morshed9a9948c2016-01-16 15:58:04 +0000483 ::aos::common::actions::ActionQueue action_queue_;
484
Austin Schuhbcce26a2018-03-26 23:41:24 -0700485 const ::frc971::control_loops::drivetrain::DrivetrainConfig<double> dt_config_;
Austin Schuhd52df772016-03-19 15:38:41 -0700486
Diana Vandenberg9cc9ab62016-04-20 21:27:47 -0700487 bool is_expanding_ = false;
488
Comran Morshed9a9948c2016-01-16 15:58:04 +0000489 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
Austin Schuh61bdc602016-12-04 19:10:10 -0800490 ::aos::util::SimpleLogInterval(::std::chrono::milliseconds(200), WARNING,
Comran Morshed9a9948c2016-01-16 15:58:04 +0000491 "no drivetrain status");
492};
493
494} // namespace joysticks
495} // namespace input
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000496} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000497
498int main() {
499 ::aos::Init(-1);
Austin Schuh3e45c752019-02-02 12:19:11 -0800500 ::aos::ShmEventLoop event_loop;
501 ::y2016::input::joysticks::Reader reader(&event_loop);
Comran Morshed9a9948c2016-01-16 15:58:04 +0000502 reader.Run();
503 ::aos::Cleanup();
504}