blob: 859a77b5e1006dfab03a09f8712b5643df5e1ba1 [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
6#include "aos/linux_code/init.h"
7#include "aos/input/joystick_input.h"
8#include "aos/common/input/driver_station_data.h"
9#include "aos/common/logging/logging.h"
10#include "aos/common/util/log_interval.h"
11#include "aos/common/time.h"
12#include "aos/common/actions/actions.h"
13
14#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000015#include "y2016/control_loops/shooter/shooter.q.h"
16#include "y2016/control_loops/superstructure/superstructure.q.h"
Austin Schuh45d07f62016-03-13 15:33:31 -070017#include "y2016/control_loops/superstructure/superstructure.h"
Comran Morshedaa0573c2016-03-05 19:05:54 +000018#include "y2016/queues/ball_detector.q.h"
Austin Schuhadd6d792016-03-19 01:20:01 -070019#include "y2016/vision/vision.q.h"
Comran Morshed200dd4b2016-02-16 17:54:58 +000020
Comran Morshed6c6a0a92016-01-17 12:45:16 +000021#include "y2016/constants.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000022#include "frc971/queues/gyro.q.h"
23#include "frc971/autonomous/auto.q.h"
Comran Morshede68e3732016-03-12 14:12:11 +000024#include "y2016/actors/autonomous_actor.h"
Austin Schuh18799112016-03-16 22:09:54 -070025#include "y2016/actors/vision_align_actor.h"
Austin Schuhd52df772016-03-19 15:38:41 -070026#include "y2016/control_loops/drivetrain/drivetrain_base.h"
Comran Morshed9a9948c2016-01-16 15:58:04 +000027
28using ::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);
Austin Schuh4105ac82016-03-26 19:44:43 -070058const ButtonLocation kHigherFrontLong(3, 6);
Austin Schuh4ea06c12016-03-12 17:54:31 -080059const POVLocation kBackLong(3, 0);
Austin Schuh45d07f62016-03-13 15:33:31 -070060const POVLocation kBackFender(3, 90);
61const POVLocation kFrontFender(3, 270);
Austin Schuh4ea06c12016-03-12 17:54:31 -080062const ButtonLocation kIntakeIn(3, 12);
Austin Schuh4ea06c12016-03-12 17:54:31 -080063const ButtonLocation kFire(3, 3);
Austin Schuh4ea06c12016-03-12 17:54:31 -080064const ButtonLocation kIntakeOut(3, 9);
Austin Schuh843412b2016-03-20 16:48:46 -070065const ButtonLocation kPortcullis(3, 7);
66const ButtonLocation kChevalDeFrise(3, 8);
Comran Morshed200dd4b2016-02-16 17:54:58 +000067
Austin Schuhadd6d792016-03-19 01:20:01 -070068const ButtonLocation kVisionAlign(3, 4);
Austin Schuh18799112016-03-16 22:09:54 -070069
Comran Morshed9a9948c2016-01-16 15:58:04 +000070class Reader : public ::aos::input::JoystickInput {
71 public:
72 Reader()
Austin Schuh94596dd2016-03-13 21:41:26 -070073 : is_high_gear_(true),
Comran Morshed200dd4b2016-02-16 17:54:58 +000074 intake_goal_(0.0),
75 shoulder_goal_(M_PI / 2.0),
Austin Schuhd52df772016-03-19 15:38:41 -070076 wrist_goal_(0.0),
77 dt_config_(control_loops::drivetrain::GetDrivetrainConfig()) {}
Comran Morshed9a9948c2016-01-16 15:58:04 +000078
79 void RunIteration(const ::aos::input::driver_station::Data &data) override {
80 bool last_auto_running = auto_running_;
81 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
82 data.GetControlBit(ControlBit::kEnabled);
83 if (auto_running_ != last_auto_running) {
84 if (auto_running_) {
85 StartAuto();
86 } else {
87 StopAuto();
88 }
89 }
90
Austin Schuh94596dd2016-03-13 21:41:26 -070091 if (!data.GetControlBit(ControlBit::kEnabled)) {
92 // If we are not enabled, reset the waiting for zero bit.
93 LOG(DEBUG, "Waiting for zero.\n");
94 waiting_for_zero_ = true;
95 is_high_gear_ = true;
96 }
97
Austin Schuhadd6d792016-03-19 01:20:01 -070098 vision_valid_ = false;
99
100 ::y2016::vision::vision_status.FetchLatest();
101
102 if (::y2016::vision::vision_status.get()) {
103 vision_valid_ = (::y2016::vision::vision_status->left_image_valid &&
104 ::y2016::vision::vision_status->right_image_valid);
Austin Schuhd52df772016-03-19 15:38:41 -0700105 last_angle_ = ::y2016::vision::vision_status->horizontal_angle;
Austin Schuhadd6d792016-03-19 01:20:01 -0700106 }
107
Austin Schuh94596dd2016-03-13 21:41:26 -0700108 if (!auto_running_) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000109 HandleDrivetrain(data);
110 HandleTeleop(data);
111 }
Austin Schuh81d71db2016-03-15 20:56:24 -0700112
113 // Process any pending actions.
114 action_queue_.Tick();
115 was_running_ = action_queue_.Running();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000116 }
117
118 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
119 bool is_control_loop_driving = false;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800120 static double left_goal = 0.0;
121 static double right_goal = 0.0;
122
Comran Morshed9a9948c2016-01-16 15:58:04 +0000123 const double wheel = -data.GetAxis(kSteeringWheel);
124 const double throttle = -data.GetAxis(kDriveThrottle);
Austin Schuhb0099642016-04-03 21:37:27 -0700125 drivetrain_queue.status.FetchLatest();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000126
Austin Schuh974cf652016-04-20 20:18:13 -0700127 if (data.IsPressed(kVisionAlign)) {
128 if (vision_valid_ && !vision_action_running_) {
129 actors::VisionAlignActionParams params;
130 action_queue_.EnqueueAction(actors::MakeVisionAlignAction(params));
131 vision_action_running_ = true;
132 LOG(INFO, "Starting vision align\n");
133 } else {
134 if (!vision_valid_) {
135 LOG(INFO, "Vision align but not valid\n");
136 }
137 }
Austin Schuh18799112016-03-16 22:09:54 -0700138 }
139
140 if (data.NegEdge(kVisionAlign)) {
141 action_queue_.CancelAllActions();
142 }
Austin Schuhadd6d792016-03-19 01:20:01 -0700143 if (!data.IsPressed(kVisionAlign)) {
144 vision_action_running_ = false;
145 }
Austin Schuh18799112016-03-16 22:09:54 -0700146
147 // Don't do any normal drivetrain stuff if vision is in charge.
148 if (was_running_) {
149 return;
150 }
151
Austin Schuh781cdcc2016-03-12 13:03:12 -0800152 if (data.PosEdge(kTurn1) || data.PosEdge(kTurn2)) {
Austin Schuh781cdcc2016-03-12 13:03:12 -0800153 if (drivetrain_queue.status.get()) {
Austin Schuh45d07f62016-03-13 15:33:31 -0700154 left_goal = drivetrain_queue.status->estimated_left_position;
155 right_goal = drivetrain_queue.status->estimated_right_position;
Austin Schuh781cdcc2016-03-12 13:03:12 -0800156 }
157 }
158 if (data.IsPressed(kTurn1) || data.IsPressed(kTurn2)) {
159 is_control_loop_driving = true;
160 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000161 if (!drivetrain_queue.goal.MakeWithBuilder()
162 .steering(wheel)
163 .throttle(throttle)
164 .highgear(is_high_gear_)
165 .quickturn(data.IsPressed(kQuickTurn))
166 .control_loop_driving(is_control_loop_driving)
Austin Schuh45d07f62016-03-13 15:33:31 -0700167 .left_goal(left_goal - wheel * 0.5 + throttle * 0.3)
168 .right_goal(right_goal + wheel * 0.5 + throttle * 0.3)
Comran Morshed9a9948c2016-01-16 15:58:04 +0000169 .left_velocity_goal(0)
170 .right_velocity_goal(0)
171 .Send()) {
172 LOG(WARNING, "sending stick values failed\n");
173 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000174
Campbell Crowley5b27f022016-02-20 16:55:35 -0800175 if (data.PosEdge(kShiftLow)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000176 is_high_gear_ = false;
177 }
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000178
Campbell Crowley5b27f022016-02-20 16:55:35 -0800179 if (data.PosEdge(kShiftHigh) || data.PosEdge(kShiftHigh2)) {
Comran Morshed9a9948c2016-01-16 15:58:04 +0000180 is_high_gear_ = true;
181 }
182 }
183
Comran Morshed9a9948c2016-01-16 15:58:04 +0000184 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
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
Austin Schuh4105ac82016-03-26 19:44:43 -0700218 if (data.IsPressed(kHigherFrontLong)) {
219 // Forwards shot
220 shoulder_goal_ = M_PI / 2.0 + 0.1;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700221 wrist_goal_ = M_PI + 0.43 + 0.02;
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 Schuh4105ac82016-03-26 19:44:43 -0700225 shooter_velocity_ = 640.0;
226 intake_goal_ = intake_when_shooting;
227 } else if (data.IsPressed(kFrontLong)) {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800228 // Forwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700229 shoulder_goal_ = M_PI / 2.0 + 0.1;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700230 wrist_goal_ = M_PI + 0.41 + 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 Schuh4ea06c12016-03-12 17:54:31 -0800236 } else if (data.IsPressed(kBackLong)) {
237 // Backwards shot
Austin Schuh3d79cc02016-03-20 21:08:53 -0700238 shoulder_goal_ = M_PI / 2.0 - 0.4;
Austin Schuhe153c5a2016-04-20 20:18:42 -0700239 wrist_goal_ = -0.62 - 0.02;
Austin Schuhb0099642016-04-03 21:37:27 -0700240 if (drivetrain_queue.status.get()) {
Austin Schuh889fee82016-04-13 22:16:36 -0700241 wrist_goal_ += drivetrain_queue.status->ground_angle;
Austin Schuhb0099642016-04-03 21:37:27 -0700242 }
Austin Schuh4ea06c12016-03-12 17:54:31 -0800243 shooter_velocity_ = 640.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700244 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700245 } else if (data.IsPressed(kBackFender)) {
246 // Fender shot back
247 shoulder_goal_ = 0.65;
Austin Schuh214164b2016-03-20 16:50:09 -0700248 wrist_goal_ = -1.20;
Austin Schuh45d07f62016-03-13 15:33:31 -0700249 shooter_velocity_ = 550.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700250 intake_goal_ = intake_when_shooting;
Austin Schuh45d07f62016-03-13 15:33:31 -0700251 } else if (data.IsPressed(kFrontFender)) {
252 // Fender shot back
253 shoulder_goal_ = 1.45;
254 wrist_goal_ = 2.5 + 1.7;
255 shooter_velocity_ = 550.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700256 intake_goal_ = intake_when_shooting;
Austin Schuhde802e92016-02-27 14:49:03 -0800257 } else {
Austin Schuh4ea06c12016-03-12 17:54:31 -0800258 wrist_goal_ = 0.0;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800259 shoulder_goal_ = -0.010;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800260 shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000261 }
262
Comran Morshedaa0573c2016-03-05 19:05:54 +0000263 bool ball_detected = false;
264 ::y2016::sensors::ball_detector.FetchLatest();
265 if (::y2016::sensors::ball_detector.get()) {
266 ball_detected = ::y2016::sensors::ball_detector->voltage > 2.5;
267 }
268 if (data.PosEdge(kIntakeIn)) {
269 saw_ball_when_started_intaking_ = ball_detected;
270 }
271
Austin Schuh45d07f62016-03-13 15:33:31 -0700272 if (data.IsPressed(kIntakeIn)) {
273 is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_);
274 if (ball_detected) {
275 force_lights_on = true;
276 }
277 } else {
278 is_intaking_ = false;
279 }
280
Austin Schuhd52df772016-03-19 15:38:41 -0700281 fire_ = false;
Austin Schuh4ea06c12016-03-12 17:54:31 -0800282 if (data.IsPressed(kFire) && shooter_velocity_ != 0.0) {
Austin Schuhd52df772016-03-19 15:38:41 -0700283 if (data.IsPressed(kVisionAlign)) {
284 // Make sure that we are lined up.
285 drivetrain_queue.status.FetchLatest();
286 drivetrain_queue.goal.FetchLatest();
287 if (drivetrain_queue.status.get() && drivetrain_queue.goal.get()) {
288 const double left_goal = drivetrain_queue.goal->left_goal;
289 const double right_goal = drivetrain_queue.goal->right_goal;
290 const double left_current =
291 drivetrain_queue.status->estimated_left_position;
292 const double right_current =
293 drivetrain_queue.status->estimated_right_position;
294 const double left_velocity =
295 drivetrain_queue.status->estimated_left_velocity;
296 const double right_velocity =
297 drivetrain_queue.status->estimated_right_velocity;
298 if (vision_action_running_ && ::std::abs(last_angle_) < 0.02 &&
299 ::std::abs((left_goal - right_goal) -
300 (left_current - right_current)) /
301 dt_config_.robot_radius / 2.0 <
302 0.02 &&
303 ::std::abs(left_velocity - right_velocity) < 0.01) {
304 ++ready_to_fire_;
305 } else {
306 ready_to_fire_ = 0;
307 }
Austin Schuh3d79cc02016-03-20 21:08:53 -0700308 if (ready_to_fire_ > 9) {
Austin Schuhd52df772016-03-19 15:38:41 -0700309 fire_ = true;
310 }
311 }
312 } else {
313 fire_ = true;
314 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000315 }
316
Austin Schuh4ea06c12016-03-12 17:54:31 -0800317 is_outtaking_ = data.IsPressed(kIntakeOut);
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800318
Austin Schuhd52df772016-03-19 15:38:41 -0700319 if (is_intaking_ || is_outtaking_) {
320 recently_intaking_accumulator_ = 20;
321 }
322
323 if (data.IsPressed(kIntakeDown)) {
324 if (recently_intaking_accumulator_) {
325 intake_goal_ = 0.1;
326 } else {
327 intake_goal_ = -0.05;
328 }
329 }
330
331 if (recently_intaking_accumulator_ > 0) {
332 --recently_intaking_accumulator_;
333 }
334
Austin Schuh843412b2016-03-20 16:48:46 -0700335 if (data.IsPressed(kPortcullis)) {
336 traverse_unlatched_ = true;
337 traverse_down_ = true;
338 } else if (data.IsPressed(kChevalDeFrise)) {
339 traverse_unlatched_ = false;
340 traverse_down_ = true;
341 } else {
342 traverse_unlatched_ = true;
343 traverse_down_ = false;
344 }
345
Comran Morshed200dd4b2016-02-16 17:54:58 +0000346 if (!waiting_for_zero_) {
Austin Schuhadd6d792016-03-19 01:20:01 -0700347 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
348 new_superstructure_goal->angle_intake = intake_goal_;
349 new_superstructure_goal->angle_shoulder = shoulder_goal_;
350 new_superstructure_goal->angle_wrist = wrist_goal_;
Austin Schuh3f0b1192016-03-12 13:03:56 -0800351
Austin Schuhadd6d792016-03-19 01:20:01 -0700352 new_superstructure_goal->max_angular_velocity_intake = 7.0;
353 new_superstructure_goal->max_angular_velocity_shoulder = 4.0;
354 new_superstructure_goal->max_angular_velocity_wrist = 10.0;
355 if (use_slow_profile) {
356 new_superstructure_goal->max_angular_acceleration_intake = 10.0;
357 } else {
Austin Schuh3f0b1192016-03-12 13:03:56 -0800358 new_superstructure_goal->max_angular_acceleration_intake = 40.0;
Austin Schuhadd6d792016-03-19 01:20:01 -0700359 }
360 new_superstructure_goal->max_angular_acceleration_shoulder = 10.0;
Austin Schuhb0099642016-04-03 21:37:27 -0700361 if (shoulder_goal_ > 1.0) {
362 new_superstructure_goal->max_angular_acceleration_wrist = 45.0;
363 } else {
364 new_superstructure_goal->max_angular_acceleration_wrist = 25.0;
365 }
Austin Schuh3f0b1192016-03-12 13:03:56 -0800366
Austin Schuhadd6d792016-03-19 01:20:01 -0700367 // Granny mode
368 /*
369 new_superstructure_goal->max_angular_velocity_intake = 0.2;
370 new_superstructure_goal->max_angular_velocity_shoulder = 0.2;
371 new_superstructure_goal->max_angular_velocity_wrist = 0.2;
372 new_superstructure_goal->max_angular_acceleration_intake = 1.0;
373 new_superstructure_goal->max_angular_acceleration_shoulder = 1.0;
374 new_superstructure_goal->max_angular_acceleration_wrist = 1.0;
375 */
376 if (is_intaking_) {
377 new_superstructure_goal->voltage_top_rollers = 12.0;
378 new_superstructure_goal->voltage_bottom_rollers = 12.0;
379 } else if (is_outtaking_) {
380 new_superstructure_goal->voltage_top_rollers = -12.0;
381 new_superstructure_goal->voltage_bottom_rollers = -7.0;
382 } else {
383 new_superstructure_goal->voltage_top_rollers = 0.0;
384 new_superstructure_goal->voltage_bottom_rollers = 0.0;
385 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000386
Austin Schuh843412b2016-03-20 16:48:46 -0700387 new_superstructure_goal->traverse_unlatched = traverse_unlatched_;
388 new_superstructure_goal->traverse_down = traverse_down_;
Austin Schuh1defd262016-04-03 16:13:32 -0700389 new_superstructure_goal->force_intake = true;
Austin Schuh843412b2016-03-20 16:48:46 -0700390
Austin Schuhadd6d792016-03-19 01:20:01 -0700391 if (!new_superstructure_goal.Send()) {
392 LOG(ERROR, "Sending superstructure goal failed.\n");
393 } else {
394 LOG(DEBUG, "sending goals: intake: %f, shoulder: %f, wrist: %f\n",
395 intake_goal_, shoulder_goal_, wrist_goal_);
396 }
Comran Morshed200dd4b2016-02-16 17:54:58 +0000397
Austin Schuhadd6d792016-03-19 01:20:01 -0700398 if (!shooter_queue.goal.MakeWithBuilder()
399 .angular_velocity(shooter_velocity_)
400 .clamp_open(is_intaking_ || is_outtaking_)
401 .push_to_shooter(fire_)
402 .force_lights_on(force_lights_on)
Austin Schuhb2c33382016-04-03 16:09:17 -0700403 .shooting_forwards(wrist_goal_ > 0)
Austin Schuhadd6d792016-03-19 01:20:01 -0700404 .Send()) {
405 LOG(ERROR, "Sending shooter goal failed.\n");
Comran Morshed200dd4b2016-02-16 17:54:58 +0000406 }
407 }
Comran Morshed9a9948c2016-01-16 15:58:04 +0000408 }
409
Comran Morshed9a9948c2016-01-16 15:58:04 +0000410 private:
411 void StartAuto() {
412 LOG(INFO, "Starting auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000413
414 actors::AutonomousActionParams params;
Brian Silverman68cb5c22016-03-20 18:11:14 -0700415 actors::auto_mode.FetchLatest();
416 if (actors::auto_mode.get() != nullptr) {
417 params.mode = actors::auto_mode->mode;
418 } else {
419 LOG(WARNING, "no auto mode values\n");
420 params.mode = 0;
421 }
Comran Morshede68e3732016-03-12 14:12:11 +0000422 action_queue_.EnqueueAction(actors::MakeAutonomousAction(params));
Comran Morshed9a9948c2016-01-16 15:58:04 +0000423 }
424
425 void StopAuto() {
426 LOG(INFO, "Stopping auto mode\n");
Comran Morshede68e3732016-03-12 14:12:11 +0000427 action_queue_.CancelAllActions();
Comran Morshed9a9948c2016-01-16 15:58:04 +0000428 }
429
430 bool is_high_gear_;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000431 // Whatever these are set to are our default goals to send out after zeroing.
432 double intake_goal_;
433 double shoulder_goal_;
434 double wrist_goal_;
Austin Schuhde802e92016-02-27 14:49:03 -0800435 double shooter_velocity_ = 0.0;
Comran Morshed200dd4b2016-02-16 17:54:58 +0000436
437 bool was_running_ = false;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000438 bool auto_running_ = false;
439
Austin Schuh843412b2016-03-20 16:48:46 -0700440 bool traverse_unlatched_ = false;
441 bool traverse_down_ = false;
442
Comran Morshed200dd4b2016-02-16 17:54:58 +0000443 // If we're waiting for the subsystems to zero.
444 bool waiting_for_zero_ = true;
445
Comran Morshedaa0573c2016-03-05 19:05:54 +0000446 // If true, the ball was present when the intaking button was pressed.
447 bool saw_ball_when_started_intaking_ = false;
448
Austin Schuhde802e92016-02-27 14:49:03 -0800449 bool is_intaking_ = false;
Austin Schuh5a6db4d2016-02-28 22:02:42 -0800450 bool is_outtaking_ = false;
Austin Schuhde802e92016-02-27 14:49:03 -0800451 bool fire_ = false;
452
Austin Schuhadd6d792016-03-19 01:20:01 -0700453 bool vision_action_running_ = false;
454 bool vision_valid_ = false;
455
Austin Schuhd52df772016-03-19 15:38:41 -0700456 int recently_intaking_accumulator_ = 0;
457 double last_angle_ = 100;
458
459 int ready_to_fire_ = 0;
460
Comran Morshed9a9948c2016-01-16 15:58:04 +0000461 ::aos::common::actions::ActionQueue action_queue_;
462
Austin Schuhd52df772016-03-19 15:38:41 -0700463 const ::frc971::control_loops::drivetrain::DrivetrainConfig dt_config_;
464
Comran Morshed9a9948c2016-01-16 15:58:04 +0000465 ::aos::util::SimpleLogInterval no_drivetrain_status_ =
466 ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
467 "no drivetrain status");
468};
469
470} // namespace joysticks
471} // namespace input
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000472} // namespace y2016
Comran Morshed9a9948c2016-01-16 15:58:04 +0000473
474int main() {
475 ::aos::Init(-1);
Comran Morshed6c6a0a92016-01-17 12:45:16 +0000476 ::y2016::input::joysticks::Reader reader;
Comran Morshed9a9948c2016-01-16 15:58:04 +0000477 reader.Run();
478 ::aos::Cleanup();
479}