blob: 32ab317bc46652e5c11c8868435b2a74837b74da [file] [log] [blame]
Brian Silverman756f9ff2014-01-17 23:40:23 -08001#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/prime/input/joystick_input.h"
Austin Schuh06cbbf12014-02-22 02:07:31 -08008#include "aos/common/input/driver_station_data.h"
Brian Silverman756f9ff2014-01-17 23:40:23 -08009#include "aos/common/logging/logging.h"
10
11#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh5d8c5e72014-03-07 20:24:34 -080012#include "frc971/constants.h"
Brian Silverman6bf0d3c2014-03-08 12:52:54 -080013#include "frc971/queues/other_sensors.q.h"
Brian Silverman756f9ff2014-01-17 23:40:23 -080014#include "frc971/autonomous/auto.q.h"
Brian Silvermanfac5c292014-02-17 15:26:57 -080015#include "frc971/control_loops/claw/claw.q.h"
16#include "frc971/control_loops/shooter/shooter.q.h"
Ben Fredricksonaa450452014-03-01 09:41:18 +000017#include "frc971/actions/shoot_action.q.h"
Austin Schuh80ff2e12014-03-08 12:06:19 -080018#include "frc971/actions/action_client.h"
19#include "frc971/actions/catch_action.q.h"
20#include "frc971/actions/shoot_action.h"
Brian Silverman756f9ff2014-01-17 23:40:23 -080021
22using ::frc971::control_loops::drivetrain;
Brian Silverman6bf0d3c2014-03-08 12:52:54 -080023using ::frc971::sensors::gyro_reading;
Brian Silverman756f9ff2014-01-17 23:40:23 -080024
25using ::aos::input::driver_station::ButtonLocation;
26using ::aos::input::driver_station::JoystickAxis;
27using ::aos::input::driver_station::ControlBit;
28
29namespace frc971 {
30namespace input {
31namespace joysticks {
32
33const ButtonLocation kDriveControlLoopEnable1(1, 7),
34 kDriveControlLoopEnable2(1, 11);
35const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2);
36const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3);
37const ButtonLocation kQuickTurn(1, 5);
Austin Schuh58d23682014-02-23 01:39:50 -080038
Austin Schuh80ff2e12014-03-08 12:06:19 -080039const ButtonLocation kCatch(3, 10);
40
41const ButtonLocation kFire(3, 9);
Austin Schuh9cb836e2014-02-23 19:25:55 -080042const ButtonLocation kUnload(2, 11);
43const ButtonLocation kReload(2, 6);
Austin Schuh58d23682014-02-23 01:39:50 -080044
Austin Schuh80ff2e12014-03-08 12:06:19 -080045const ButtonLocation kRollersOut(3, 8);
46const ButtonLocation kRollersIn(3, 3);
Austin Schuh58d23682014-02-23 01:39:50 -080047
Austin Schuh80ff2e12014-03-08 12:06:19 -080048const ButtonLocation kTuck(3, 4);
49const ButtonLocation kIntakePosition(3, 5);
50const ButtonLocation kIntakeOpenPosition(3, 11);
Austin Schuh80ff2e12014-03-08 12:06:19 -080051const JoystickAxis kFlipRobot(3, 3);
Austin Schuh58d23682014-02-23 01:39:50 -080052
Austin Schuh80ff2e12014-03-08 12:06:19 -080053const ButtonLocation kLongShot(3, 7);
54const ButtonLocation kMediumShot(3, 6);
55const ButtonLocation kShortShot(3, 2);
Austin Schuhade6d082014-03-09 00:53:06 -080056const ButtonLocation kTrussShot(3, 1);
Austin Schuh58d23682014-02-23 01:39:50 -080057
58struct ClawGoal {
59 double angle;
60 double separation;
61};
62
Austin Schuh5d8c5e72014-03-07 20:24:34 -080063struct ShotGoal {
64 ClawGoal claw;
65 double shot_power;
66 bool velocity_compensation;
67 double intake_power;
68};
69
Austin Schuh58d23682014-02-23 01:39:50 -080070const ClawGoal kTuckGoal = {-2.273474, -0.749484};
71const ClawGoal kIntakeGoal = {-2.273474, 0.0};
Austin Schuh9cb836e2014-02-23 19:25:55 -080072const ClawGoal kIntakeOpenGoal = {-2.0, 1.2};
Austin Schuh58d23682014-02-23 01:39:50 -080073
Austin Schuh80ff2e12014-03-08 12:06:19 -080074// TODO(austin): Tune these by hand...
75const ClawGoal kFlippedTuckGoal = {2.733474, -0.75};
76const ClawGoal kFlippedIntakeGoal = {2.0, 0.0};
77const ClawGoal kFlippedIntakeOpenGoal = {0.95, 1.0};
78
Austin Schuhade6d082014-03-09 00:53:06 -080079const double kIntakePower = 4.0;
80const double kShootSeparation = 0.11;
Austin Schuh5d8c5e72014-03-07 20:24:34 -080081
Austin Schuhade6d082014-03-09 00:53:06 -080082//const ShotGoal kLongShotGoal = {
83 //{-M_PI / 2.0 + 0.46, kShootSeparation}, 120, false, kIntakePower};
Austin Schuh5d8c5e72014-03-07 20:24:34 -080084const ShotGoal kLongShotGoal = {
Austin Schuh5f4944e2014-03-09 16:40:39 -070085 {-0.60, kShootSeparation}, 80, false, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080086const ShotGoal kMediumShotGoal = {
Austin Schuh5f4944e2014-03-09 16:40:39 -070087 {-0.90, kShootSeparation}, 105, true, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080088const ShotGoal kShortShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080089 {-0.670, kShootSeparation}, 71.0, false, kIntakePower};
90const ShotGoal kTrussShotGoal = {
91 {-0.05, kShootSeparation}, 61.0, false, kIntakePower};
Brian Silverman756f9ff2014-01-17 23:40:23 -080092
Austin Schuh80ff2e12014-03-08 12:06:19 -080093const ShotGoal kFlippedLongShotGoal = {
Austin Schuh5f4944e2014-03-09 16:40:39 -070094 {0.55, kShootSeparation}, 80, false, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080095const ShotGoal kFlippedMediumShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080096 {0.85, kShootSeparation}, 105, true, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080097const ShotGoal kFlippedShortShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080098 {0.57, kShootSeparation}, 80.0, false, kIntakePower};
Austin Schuhb7dfabc2014-03-01 18:57:42 -080099
100// Makes a new ShootAction action.
Austin Schuh80ff2e12014-03-08 12:06:19 -0800101::std::unique_ptr<TypedAction< ::frc971::actions::CatchActionGroup>>
102MakeCatchAction() {
103 return ::std::unique_ptr<TypedAction< ::frc971::actions::CatchActionGroup>>(
104 new TypedAction< ::frc971::actions::CatchActionGroup>(
105 &::frc971::actions::catch_action));
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800106}
107
108// A queue which queues Actions and cancels them.
109class ActionQueue {
110 public:
111 // Queues up an action for sending.
112 void QueueAction(::std::unique_ptr<Action> action) {
113 if (current_action_) {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800114 LOG(INFO, "Queueing action, canceling prior\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800115 current_action_->Cancel();
116 next_action_ = ::std::move(action);
117 } else {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800118 LOG(INFO, "Queueing action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800119 current_action_ = ::std::move(action);
120 current_action_->Start();
121 }
122 }
123
124 // Cancels the current action, and runs the next one when the current one has
125 // finished.
126 void CancelCurrentAction() {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800127 LOG(INFO, "Canceling current action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800128 if (current_action_) {
129 current_action_->Cancel();
130 }
131 }
132
133 // Cancels all running actions.
134 void CancelAllActions() {
Brian Silverman101b9642014-03-08 12:45:16 -0800135 LOG(DEBUG, "Cancelling all actions\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800136 if (current_action_) {
137 current_action_->Cancel();
138 }
139 next_action_.reset();
140 }
141
142 // Runs the next action when the current one is finished running.
143 void Tick() {
144 if (current_action_) {
145 if (!current_action_->Running()) {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800146 LOG(INFO, "Action is done.\n");
147 current_action_ = ::std::move(next_action_);
148 if (current_action_) {
149 LOG(INFO, "Running next action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800150 current_action_->Start();
151 }
152 }
153 }
154 }
155
156 // Returns true if any action is running or could be running.
157 // For a one cycle faster response, call Tick before running this.
158 bool Running() { return (bool)current_action_; }
159
160 private:
161 ::std::unique_ptr<Action> current_action_;
162 ::std::unique_ptr<Action> next_action_;
163};
164
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800165
Brian Silverman756f9ff2014-01-17 23:40:23 -0800166class Reader : public ::aos::input::JoystickInput {
167 public:
Austin Schuh58d23682014-02-23 01:39:50 -0800168 Reader()
169 : is_high_gear_(false),
Austin Schuh9cb836e2014-02-23 19:25:55 -0800170 shot_power_(80.0),
Austin Schuh58d23682014-02-23 01:39:50 -0800171 goal_angle_(0.0),
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800172 separation_angle_(0.0),
173 velocity_compensation_(false),
174 intake_power_(0.0),
175 was_running_(false) {}
Brian Silverman756f9ff2014-01-17 23:40:23 -0800176
177 virtual void RunIteration(const ::aos::input::driver_station::Data &data) {
Brian Silverman756f9ff2014-01-17 23:40:23 -0800178 if (data.GetControlBit(ControlBit::kAutonomous)) {
179 if (data.PosEdge(ControlBit::kEnabled)){
180 LOG(INFO, "Starting auto mode\n");
181 ::frc971::autonomous::autonomous.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800182 .run_auto(true)
183 .Send();
Brian Silverman756f9ff2014-01-17 23:40:23 -0800184 } else if (data.NegEdge(ControlBit::kEnabled)) {
185 LOG(INFO, "Stopping auto mode\n");
186 ::frc971::autonomous::autonomous.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800187 .run_auto(false)
188 .Send();
Brian Silverman756f9ff2014-01-17 23:40:23 -0800189 }
Austin Schuh58d23682014-02-23 01:39:50 -0800190 } else {
191 HandleTeleop(data);
Brian Silverman756f9ff2014-01-17 23:40:23 -0800192 }
193 }
Austin Schuh58d23682014-02-23 01:39:50 -0800194
195 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
196 bool is_control_loop_driving = false;
197 double left_goal = 0.0;
198 double right_goal = 0.0;
199 const double wheel = -data.GetAxis(kSteeringWheel);
200 const double throttle = -data.GetAxis(kDriveThrottle);
201 const double kThrottleGain = 1.0 / 2.5;
202 if (false && (data.IsPressed(kDriveControlLoopEnable1) ||
203 data.IsPressed(kDriveControlLoopEnable2))) {
204 // TODO(austin): Static sucks!
205 static double distance = 0.0;
206 static double angle = 0.0;
207 static double filtered_goal_distance = 0.0;
208 if (data.PosEdge(kDriveControlLoopEnable1) ||
209 data.PosEdge(kDriveControlLoopEnable2)) {
Brian Silverman6bf0d3c2014-03-08 12:52:54 -0800210 if (drivetrain.position.FetchLatest() && gyro_reading.FetchLatest()) {
Austin Schuh58d23682014-02-23 01:39:50 -0800211 distance = (drivetrain.position->left_encoder +
212 drivetrain.position->right_encoder) /
213 2.0 -
214 throttle * kThrottleGain / 2.0;
Brian Silverman6bf0d3c2014-03-08 12:52:54 -0800215 angle = gyro_reading->angle;
Austin Schuh58d23682014-02-23 01:39:50 -0800216 filtered_goal_distance = distance;
217 }
218 }
219 is_control_loop_driving = true;
220
221 // const double gyro_angle = Gyro.View().angle;
222 const double goal_theta = angle - wheel * 0.27;
223 const double goal_distance = distance + throttle * kThrottleGain;
224 const double robot_width = 22.0 / 100.0 * 2.54;
225 const double kMaxVelocity = 0.6;
226 if (goal_distance > kMaxVelocity * 0.02 + filtered_goal_distance) {
227 filtered_goal_distance += kMaxVelocity * 0.02;
228 } else if (goal_distance <
229 -kMaxVelocity * 0.02 + filtered_goal_distance) {
230 filtered_goal_distance -= kMaxVelocity * 0.02;
231 } else {
232 filtered_goal_distance = goal_distance;
233 }
234 left_goal = filtered_goal_distance - robot_width * goal_theta / 2.0;
235 right_goal = filtered_goal_distance + robot_width * goal_theta / 2.0;
236 is_high_gear_ = false;
237
238 LOG(DEBUG, "Left goal %f Right goal %f\n", left_goal, right_goal);
239 }
240 if (!drivetrain.goal.MakeWithBuilder()
241 .steering(wheel)
242 .throttle(throttle)
243 .highgear(is_high_gear_)
244 .quickturn(data.IsPressed(kQuickTurn))
245 .control_loop_driving(is_control_loop_driving)
246 .left_goal(left_goal)
247 .right_goal(right_goal)
248 .Send()) {
249 LOG(WARNING, "sending stick values failed\n");
250 }
251 if (data.PosEdge(kShiftHigh)) {
252 is_high_gear_ = false;
253 }
254 if (data.PosEdge(kShiftLow)) {
255 is_high_gear_ = true;
256 }
257 }
258
259 void SetGoal(ClawGoal goal) {
260 goal_angle_ = goal.angle;
261 separation_angle_ = goal.separation;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800262 velocity_compensation_ = false;
263 intake_power_ = 0.0;
264 }
265
266 void SetGoal(ShotGoal goal) {
267 goal_angle_ = goal.claw.angle;
268 separation_angle_ = goal.claw.separation;
269 shot_power_ = goal.shot_power;
270 velocity_compensation_ = goal.velocity_compensation;
271 intake_power_ = goal.intake_power;
Austin Schuh58d23682014-02-23 01:39:50 -0800272 }
273
274 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
275 HandleDrivetrain(data);
Austin Schuhc95c2b72014-03-02 11:56:49 -0800276 if (!data.GetControlBit(ControlBit::kEnabled)) {
277 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800278 LOG(DEBUG, "Canceling\n");
Austin Schuhc95c2b72014-03-02 11:56:49 -0800279 }
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800280 if (data.IsPressed(kRollersIn) || data.IsPressed(kRollersOut)) {
281 intake_power_ = 0.0;
Austin Schuh5f4944e2014-03-09 16:40:39 -0700282 separation_angle_ = 0.0;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800283 }
Austin Schuh58d23682014-02-23 01:39:50 -0800284
Austin Schuh80ff2e12014-03-08 12:06:19 -0800285 if (data.GetAxis(kFlipRobot) < 0.5) {
286 if (data.IsPressed(kIntakeOpenPosition)) {
287 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800288 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800289 SetGoal(kFlippedIntakeOpenGoal);
290 } else if (data.IsPressed(kIntakePosition)) {
291 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800292 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800293 SetGoal(kFlippedIntakeGoal);
294 } else if (data.IsPressed(kTuck)) {
295 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800296 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800297 SetGoal(kFlippedTuckGoal);
298 } else if (data.PosEdge(kLongShot)) {
299 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800300 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800301 SetGoal(kFlippedLongShotGoal);
302 } else if (data.PosEdge(kMediumShot)) {
303 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800304 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800305 SetGoal(kFlippedMediumShotGoal);
306 } else if (data.PosEdge(kShortShot)) {
307 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800308 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800309 SetGoal(kFlippedShortShotGoal);
Austin Schuhade6d082014-03-09 00:53:06 -0800310 } else if (data.PosEdge(kTrussShot)) {
311 action_queue_.CancelAllActions();
312 LOG(DEBUG, "Canceling\n");
313 SetGoal(kTrussShotGoal);
Austin Schuh80ff2e12014-03-08 12:06:19 -0800314 }
315 } else {
316 if (data.IsPressed(kIntakeOpenPosition)) {
317 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800318 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800319 SetGoal(kIntakeOpenGoal);
320 } else if (data.IsPressed(kIntakePosition)) {
321 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800322 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800323 SetGoal(kIntakeGoal);
324 } else if (data.IsPressed(kTuck)) {
325 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800326 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800327 SetGoal(kTuckGoal);
328 } else if (data.PosEdge(kLongShot)) {
329 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800330 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800331 SetGoal(kLongShotGoal);
332 } else if (data.PosEdge(kMediumShot)) {
333 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800334 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800335 SetGoal(kMediumShotGoal);
336 } else if (data.PosEdge(kShortShot)) {
337 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800338 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800339 SetGoal(kShortShotGoal);
Austin Schuhade6d082014-03-09 00:53:06 -0800340 } else if (data.PosEdge(kTrussShot)) {
341 action_queue_.CancelAllActions();
342 LOG(DEBUG, "Canceling\n");
343 SetGoal(kTrussShotGoal);
Austin Schuh80ff2e12014-03-08 12:06:19 -0800344 }
Austin Schuh58d23682014-02-23 01:39:50 -0800345 }
346
Austin Schuhade6d082014-03-09 00:53:06 -0800347 /*
Austin Schuh80ff2e12014-03-08 12:06:19 -0800348 if (data.PosEdge(kCatch)) {
349 auto catch_action = MakeCatchAction();
350 catch_action->GetGoal()->catch_angle = goal_angle_;
351 action_queue_.QueueAction(::std::move(catch_action));
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800352 }
Austin Schuhade6d082014-03-09 00:53:06 -0800353 */
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800354
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800355 if (data.PosEdge(kFire)) {
Austin Schuh80ff2e12014-03-08 12:06:19 -0800356 action_queue_.QueueAction(actions::MakeShootAction());
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800357 }
358
359 action_queue_.Tick();
Austin Schuhc95c2b72014-03-02 11:56:49 -0800360 if (data.IsPressed(kUnload) || data.IsPressed(kReload)) {
361 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800362 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800363 intake_power_ = 0.0;
364 velocity_compensation_ = false;
Austin Schuhc95c2b72014-03-02 11:56:49 -0800365 }
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800366
367 // Send out the claw and shooter goals if no actions are running.
368 if (!action_queue_.Running()) {
Austin Schuh80ff2e12014-03-08 12:06:19 -0800369 // If the action just ended, turn the intake off and stop velocity
370 // compensating.
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800371 if (was_running_) {
372 intake_power_ = 0.0;
373 velocity_compensation_ = false;
374 }
375
376 control_loops::drivetrain.status.FetchLatest();
Austin Schuhade6d082014-03-09 00:53:06 -0800377 double goal_angle =
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800378 goal_angle_ +
379 (velocity_compensation_
380 ? SpeedToAngleOffset(
381 control_loops::drivetrain.status->robot_speed)
382 : 0.0);
Austin Schuhade6d082014-03-09 00:53:06 -0800383 double separation_angle = separation_angle_;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800384
Austin Schuhade6d082014-03-09 00:53:06 -0800385 if (data.IsPressed(kCatch)) {
386 const double kCatchSeparation = 1.0;
387 goal_angle -= kCatchSeparation / 2.0;
388 separation_angle = kCatchSeparation;
389 }
390
391 bool intaking =
392 data.IsPressed(kRollersIn) || data.IsPressed(kIntakePosition) ||
393 data.IsPressed(kIntakeOpenPosition) || data.IsPressed(kCatch);
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800394 if (!control_loops::claw_queue_group.goal.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800395 .bottom_angle(goal_angle)
Austin Schuhade6d082014-03-09 00:53:06 -0800396 .separation_angle(separation_angle)
Austin Schuh80ff2e12014-03-08 12:06:19 -0800397 .intake(intaking ? 12.0
398 : (data.IsPressed(kRollersOut) ? -12.0
399 : intake_power_))
400 .centering(intaking ? 12.0 : 0.0)
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800401 .Send()) {
402 LOG(WARNING, "sending claw goal failed\n");
403 }
404
405 if (!control_loops::shooter_queue_group.goal.MakeWithBuilder()
406 .shot_power(shot_power_)
407 .shot_requested(data.IsPressed(kFire))
408 .unload_requested(data.IsPressed(kUnload))
409 .load_requested(data.IsPressed(kReload))
410 .Send()) {
411 LOG(WARNING, "sending shooter goal failed\n");
412 }
Austin Schuh58d23682014-02-23 01:39:50 -0800413 }
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800414 was_running_ = action_queue_.Running();
415 }
416
417 double SpeedToAngleOffset(double speed) {
418 const frc971::constants::Values &values = frc971::constants::GetValues();
419 // scale speed to a [0.0-1.0] on something close to the max
420 // TODO(austin): Change the scale factor for different shots.
Austin Schuhade6d082014-03-09 00:53:06 -0800421 return (speed / values.drivetrain_max_speed) * 0.2;
Austin Schuh58d23682014-02-23 01:39:50 -0800422 }
423
Austin Schuh01c652b2014-02-21 23:13:42 -0800424 private:
Austin Schuh58d23682014-02-23 01:39:50 -0800425 bool is_high_gear_;
426 double shot_power_;
427 double goal_angle_;
428 double separation_angle_;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800429 bool velocity_compensation_;
430 double intake_power_;
431 bool was_running_;
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800432
433 ActionQueue action_queue_;
Brian Silverman756f9ff2014-01-17 23:40:23 -0800434};
435
436} // namespace joysticks
437} // namespace input
438} // namespace frc971
439
440int main() {
441 ::aos::Init();
442 ::frc971::input::joysticks::Reader reader;
443 reader.Run();
444 ::aos::Cleanup();
445}