blob: 1217463c4b96377afee1457aaf2860729b34ca87 [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);
51//const ButtonLocation kFlipRobot(3, 7);
52const JoystickAxis kFlipRobot(3, 3);
53// Truss shot. (3, 1)
Austin Schuh58d23682014-02-23 01:39:50 -080054
Austin Schuh80ff2e12014-03-08 12:06:19 -080055const ButtonLocation kLongShot(3, 7);
56const ButtonLocation kMediumShot(3, 6);
57const ButtonLocation kShortShot(3, 2);
Austin Schuhade6d082014-03-09 00:53:06 -080058const ButtonLocation kTrussShot(3, 1);
Austin Schuh58d23682014-02-23 01:39:50 -080059
60struct ClawGoal {
61 double angle;
62 double separation;
63};
64
Austin Schuh5d8c5e72014-03-07 20:24:34 -080065struct ShotGoal {
66 ClawGoal claw;
67 double shot_power;
68 bool velocity_compensation;
69 double intake_power;
70};
71
Austin Schuh58d23682014-02-23 01:39:50 -080072const ClawGoal kTuckGoal = {-2.273474, -0.749484};
73const ClawGoal kIntakeGoal = {-2.273474, 0.0};
Austin Schuh9cb836e2014-02-23 19:25:55 -080074const ClawGoal kIntakeOpenGoal = {-2.0, 1.2};
Austin Schuh58d23682014-02-23 01:39:50 -080075
Austin Schuh80ff2e12014-03-08 12:06:19 -080076// TODO(austin): Tune these by hand...
77const ClawGoal kFlippedTuckGoal = {2.733474, -0.75};
78const ClawGoal kFlippedIntakeGoal = {2.0, 0.0};
79const ClawGoal kFlippedIntakeOpenGoal = {0.95, 1.0};
80
Austin Schuhade6d082014-03-09 00:53:06 -080081const double kIntakePower = 4.0;
82const double kShootSeparation = 0.11;
Austin Schuh5d8c5e72014-03-07 20:24:34 -080083
Austin Schuhade6d082014-03-09 00:53:06 -080084//const ShotGoal kLongShotGoal = {
85 //{-M_PI / 2.0 + 0.46, kShootSeparation}, 120, false, kIntakePower};
Austin Schuh5d8c5e72014-03-07 20:24:34 -080086const ShotGoal kLongShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080087 {-M_PI / 2.0 + 0.46, kShootSeparation}, 120, false, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080088const ShotGoal kMediumShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080089 {-0.95, kShootSeparation}, 95, true, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080090const ShotGoal kShortShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080091 {-0.670, kShootSeparation}, 71.0, false, kIntakePower};
92const ShotGoal kTrussShotGoal = {
93 {-0.05, kShootSeparation}, 61.0, false, kIntakePower};
Brian Silverman756f9ff2014-01-17 23:40:23 -080094
Austin Schuh80ff2e12014-03-08 12:06:19 -080095const ShotGoal kFlippedLongShotGoal = {
96 {M_PI / 2.0 - 0.43, kShootSeparation}, 145, false, kIntakePower};
97const ShotGoal kFlippedMediumShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -080098 {0.85, kShootSeparation}, 105, true, kIntakePower};
Austin Schuh80ff2e12014-03-08 12:06:19 -080099const ShotGoal kFlippedShortShotGoal = {
Austin Schuhade6d082014-03-09 00:53:06 -0800100 {0.57, kShootSeparation}, 80.0, false, kIntakePower};
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800101
102// Makes a new ShootAction action.
Austin Schuh80ff2e12014-03-08 12:06:19 -0800103::std::unique_ptr<TypedAction< ::frc971::actions::CatchActionGroup>>
104MakeCatchAction() {
105 return ::std::unique_ptr<TypedAction< ::frc971::actions::CatchActionGroup>>(
106 new TypedAction< ::frc971::actions::CatchActionGroup>(
107 &::frc971::actions::catch_action));
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800108}
109
110// A queue which queues Actions and cancels them.
111class ActionQueue {
112 public:
113 // Queues up an action for sending.
114 void QueueAction(::std::unique_ptr<Action> action) {
115 if (current_action_) {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800116 LOG(INFO, "Queueing action, canceling prior\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800117 current_action_->Cancel();
118 next_action_ = ::std::move(action);
119 } else {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800120 LOG(INFO, "Queueing action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800121 current_action_ = ::std::move(action);
122 current_action_->Start();
123 }
124 }
125
126 // Cancels the current action, and runs the next one when the current one has
127 // finished.
128 void CancelCurrentAction() {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800129 LOG(INFO, "Canceling current action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800130 if (current_action_) {
131 current_action_->Cancel();
132 }
133 }
134
135 // Cancels all running actions.
136 void CancelAllActions() {
Brian Silverman101b9642014-03-08 12:45:16 -0800137 LOG(DEBUG, "Cancelling all actions\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800138 if (current_action_) {
139 current_action_->Cancel();
140 }
141 next_action_.reset();
142 }
143
144 // Runs the next action when the current one is finished running.
145 void Tick() {
146 if (current_action_) {
147 if (!current_action_->Running()) {
Austin Schuhc95c2b72014-03-02 11:56:49 -0800148 LOG(INFO, "Action is done.\n");
149 current_action_ = ::std::move(next_action_);
150 if (current_action_) {
151 LOG(INFO, "Running next action\n");
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800152 current_action_->Start();
153 }
154 }
155 }
156 }
157
158 // Returns true if any action is running or could be running.
159 // For a one cycle faster response, call Tick before running this.
160 bool Running() { return (bool)current_action_; }
161
162 private:
163 ::std::unique_ptr<Action> current_action_;
164 ::std::unique_ptr<Action> next_action_;
165};
166
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800167
Brian Silverman756f9ff2014-01-17 23:40:23 -0800168class Reader : public ::aos::input::JoystickInput {
169 public:
Austin Schuh58d23682014-02-23 01:39:50 -0800170 Reader()
171 : is_high_gear_(false),
Austin Schuh9cb836e2014-02-23 19:25:55 -0800172 shot_power_(80.0),
Austin Schuh58d23682014-02-23 01:39:50 -0800173 goal_angle_(0.0),
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800174 separation_angle_(0.0),
175 velocity_compensation_(false),
176 intake_power_(0.0),
177 was_running_(false) {}
Brian Silverman756f9ff2014-01-17 23:40:23 -0800178
179 virtual void RunIteration(const ::aos::input::driver_station::Data &data) {
Brian Silverman756f9ff2014-01-17 23:40:23 -0800180 if (data.GetControlBit(ControlBit::kAutonomous)) {
181 if (data.PosEdge(ControlBit::kEnabled)){
182 LOG(INFO, "Starting auto mode\n");
183 ::frc971::autonomous::autonomous.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800184 .run_auto(true)
185 .Send();
Brian Silverman756f9ff2014-01-17 23:40:23 -0800186 } else if (data.NegEdge(ControlBit::kEnabled)) {
187 LOG(INFO, "Stopping auto mode\n");
188 ::frc971::autonomous::autonomous.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800189 .run_auto(false)
190 .Send();
Brian Silverman756f9ff2014-01-17 23:40:23 -0800191 }
Austin Schuh58d23682014-02-23 01:39:50 -0800192 } else {
193 HandleTeleop(data);
Brian Silverman756f9ff2014-01-17 23:40:23 -0800194 }
195 }
Austin Schuh58d23682014-02-23 01:39:50 -0800196
197 void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
198 bool is_control_loop_driving = false;
199 double left_goal = 0.0;
200 double right_goal = 0.0;
201 const double wheel = -data.GetAxis(kSteeringWheel);
202 const double throttle = -data.GetAxis(kDriveThrottle);
203 const double kThrottleGain = 1.0 / 2.5;
204 if (false && (data.IsPressed(kDriveControlLoopEnable1) ||
205 data.IsPressed(kDriveControlLoopEnable2))) {
206 // TODO(austin): Static sucks!
207 static double distance = 0.0;
208 static double angle = 0.0;
209 static double filtered_goal_distance = 0.0;
210 if (data.PosEdge(kDriveControlLoopEnable1) ||
211 data.PosEdge(kDriveControlLoopEnable2)) {
Brian Silverman6bf0d3c2014-03-08 12:52:54 -0800212 if (drivetrain.position.FetchLatest() && gyro_reading.FetchLatest()) {
Austin Schuh58d23682014-02-23 01:39:50 -0800213 distance = (drivetrain.position->left_encoder +
214 drivetrain.position->right_encoder) /
215 2.0 -
216 throttle * kThrottleGain / 2.0;
Brian Silverman6bf0d3c2014-03-08 12:52:54 -0800217 angle = gyro_reading->angle;
Austin Schuh58d23682014-02-23 01:39:50 -0800218 filtered_goal_distance = distance;
219 }
220 }
221 is_control_loop_driving = true;
222
223 // const double gyro_angle = Gyro.View().angle;
224 const double goal_theta = angle - wheel * 0.27;
225 const double goal_distance = distance + throttle * kThrottleGain;
226 const double robot_width = 22.0 / 100.0 * 2.54;
227 const double kMaxVelocity = 0.6;
228 if (goal_distance > kMaxVelocity * 0.02 + filtered_goal_distance) {
229 filtered_goal_distance += kMaxVelocity * 0.02;
230 } else if (goal_distance <
231 -kMaxVelocity * 0.02 + filtered_goal_distance) {
232 filtered_goal_distance -= kMaxVelocity * 0.02;
233 } else {
234 filtered_goal_distance = goal_distance;
235 }
236 left_goal = filtered_goal_distance - robot_width * goal_theta / 2.0;
237 right_goal = filtered_goal_distance + robot_width * goal_theta / 2.0;
238 is_high_gear_ = false;
239
240 LOG(DEBUG, "Left goal %f Right goal %f\n", left_goal, right_goal);
241 }
242 if (!drivetrain.goal.MakeWithBuilder()
243 .steering(wheel)
244 .throttle(throttle)
245 .highgear(is_high_gear_)
246 .quickturn(data.IsPressed(kQuickTurn))
247 .control_loop_driving(is_control_loop_driving)
248 .left_goal(left_goal)
249 .right_goal(right_goal)
250 .Send()) {
251 LOG(WARNING, "sending stick values failed\n");
252 }
253 if (data.PosEdge(kShiftHigh)) {
254 is_high_gear_ = false;
255 }
256 if (data.PosEdge(kShiftLow)) {
257 is_high_gear_ = true;
258 }
259 }
260
261 void SetGoal(ClawGoal goal) {
262 goal_angle_ = goal.angle;
263 separation_angle_ = goal.separation;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800264 velocity_compensation_ = false;
265 intake_power_ = 0.0;
266 }
267
268 void SetGoal(ShotGoal goal) {
269 goal_angle_ = goal.claw.angle;
270 separation_angle_ = goal.claw.separation;
271 shot_power_ = goal.shot_power;
272 velocity_compensation_ = goal.velocity_compensation;
273 intake_power_ = goal.intake_power;
Austin Schuh58d23682014-02-23 01:39:50 -0800274 }
275
276 void HandleTeleop(const ::aos::input::driver_station::Data &data) {
277 HandleDrivetrain(data);
Austin Schuhc95c2b72014-03-02 11:56:49 -0800278 if (!data.GetControlBit(ControlBit::kEnabled)) {
279 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800280 LOG(DEBUG, "Canceling\n");
Austin Schuhc95c2b72014-03-02 11:56:49 -0800281 }
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800282 if (data.IsPressed(kRollersIn) || data.IsPressed(kRollersOut)) {
283 intake_power_ = 0.0;
284 }
Austin Schuh58d23682014-02-23 01:39:50 -0800285
Austin Schuh80ff2e12014-03-08 12:06:19 -0800286 if (data.GetAxis(kFlipRobot) < 0.5) {
287 if (data.IsPressed(kIntakeOpenPosition)) {
288 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800289 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800290 SetGoal(kFlippedIntakeOpenGoal);
291 } else if (data.IsPressed(kIntakePosition)) {
292 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800293 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800294 SetGoal(kFlippedIntakeGoal);
295 } else if (data.IsPressed(kTuck)) {
296 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800297 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800298 SetGoal(kFlippedTuckGoal);
299 } else if (data.PosEdge(kLongShot)) {
300 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800301 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800302 SetGoal(kFlippedLongShotGoal);
303 } else if (data.PosEdge(kMediumShot)) {
304 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800305 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800306 SetGoal(kFlippedMediumShotGoal);
307 } else if (data.PosEdge(kShortShot)) {
308 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800309 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800310 SetGoal(kFlippedShortShotGoal);
Austin Schuhade6d082014-03-09 00:53:06 -0800311 } else if (data.PosEdge(kTrussShot)) {
312 action_queue_.CancelAllActions();
313 LOG(DEBUG, "Canceling\n");
314 SetGoal(kTrussShotGoal);
Austin Schuh80ff2e12014-03-08 12:06:19 -0800315 }
316 } else {
317 if (data.IsPressed(kIntakeOpenPosition)) {
318 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800319 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800320 SetGoal(kIntakeOpenGoal);
321 } else if (data.IsPressed(kIntakePosition)) {
322 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800323 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800324 SetGoal(kIntakeGoal);
325 } else if (data.IsPressed(kTuck)) {
326 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800327 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800328 SetGoal(kTuckGoal);
329 } else if (data.PosEdge(kLongShot)) {
330 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800331 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800332 SetGoal(kLongShotGoal);
333 } else if (data.PosEdge(kMediumShot)) {
334 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800335 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800336 SetGoal(kMediumShotGoal);
337 } else if (data.PosEdge(kShortShot)) {
338 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800339 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800340 SetGoal(kShortShotGoal);
Austin Schuhade6d082014-03-09 00:53:06 -0800341 } else if (data.PosEdge(kTrussShot)) {
342 action_queue_.CancelAllActions();
343 LOG(DEBUG, "Canceling\n");
344 SetGoal(kTrussShotGoal);
Austin Schuh80ff2e12014-03-08 12:06:19 -0800345 }
Austin Schuh58d23682014-02-23 01:39:50 -0800346 }
347
Austin Schuhade6d082014-03-09 00:53:06 -0800348 /*
Austin Schuh80ff2e12014-03-08 12:06:19 -0800349 if (data.PosEdge(kCatch)) {
350 auto catch_action = MakeCatchAction();
351 catch_action->GetGoal()->catch_angle = goal_angle_;
352 action_queue_.QueueAction(::std::move(catch_action));
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800353 }
Austin Schuhade6d082014-03-09 00:53:06 -0800354 */
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800355
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800356 if (data.PosEdge(kFire)) {
Austin Schuh80ff2e12014-03-08 12:06:19 -0800357 action_queue_.QueueAction(actions::MakeShootAction());
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800358 }
359
360 action_queue_.Tick();
Austin Schuhc95c2b72014-03-02 11:56:49 -0800361 if (data.IsPressed(kUnload) || data.IsPressed(kReload)) {
362 action_queue_.CancelAllActions();
Austin Schuhade6d082014-03-09 00:53:06 -0800363 LOG(DEBUG, "Canceling\n");
Austin Schuh80ff2e12014-03-08 12:06:19 -0800364 intake_power_ = 0.0;
365 velocity_compensation_ = false;
Austin Schuhc95c2b72014-03-02 11:56:49 -0800366 }
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800367
368 // Send out the claw and shooter goals if no actions are running.
369 if (!action_queue_.Running()) {
Austin Schuh80ff2e12014-03-08 12:06:19 -0800370 // If the action just ended, turn the intake off and stop velocity
371 // compensating.
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800372 if (was_running_) {
373 intake_power_ = 0.0;
374 velocity_compensation_ = false;
375 }
376
377 control_loops::drivetrain.status.FetchLatest();
Austin Schuhade6d082014-03-09 00:53:06 -0800378 double goal_angle =
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800379 goal_angle_ +
380 (velocity_compensation_
381 ? SpeedToAngleOffset(
382 control_loops::drivetrain.status->robot_speed)
383 : 0.0);
Austin Schuhade6d082014-03-09 00:53:06 -0800384 double separation_angle = separation_angle_;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800385
Austin Schuhade6d082014-03-09 00:53:06 -0800386 if (data.IsPressed(kCatch)) {
387 const double kCatchSeparation = 1.0;
388 goal_angle -= kCatchSeparation / 2.0;
389 separation_angle = kCatchSeparation;
390 }
391
392 bool intaking =
393 data.IsPressed(kRollersIn) || data.IsPressed(kIntakePosition) ||
394 data.IsPressed(kIntakeOpenPosition) || data.IsPressed(kCatch);
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800395 if (!control_loops::claw_queue_group.goal.MakeWithBuilder()
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800396 .bottom_angle(goal_angle)
Austin Schuhade6d082014-03-09 00:53:06 -0800397 .separation_angle(separation_angle)
Austin Schuh80ff2e12014-03-08 12:06:19 -0800398 .intake(intaking ? 12.0
399 : (data.IsPressed(kRollersOut) ? -12.0
400 : intake_power_))
401 .centering(intaking ? 12.0 : 0.0)
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800402 .Send()) {
403 LOG(WARNING, "sending claw goal failed\n");
404 }
405
406 if (!control_loops::shooter_queue_group.goal.MakeWithBuilder()
407 .shot_power(shot_power_)
408 .shot_requested(data.IsPressed(kFire))
409 .unload_requested(data.IsPressed(kUnload))
410 .load_requested(data.IsPressed(kReload))
411 .Send()) {
412 LOG(WARNING, "sending shooter goal failed\n");
413 }
Austin Schuh58d23682014-02-23 01:39:50 -0800414 }
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800415 was_running_ = action_queue_.Running();
416 }
417
418 double SpeedToAngleOffset(double speed) {
419 const frc971::constants::Values &values = frc971::constants::GetValues();
420 // scale speed to a [0.0-1.0] on something close to the max
421 // TODO(austin): Change the scale factor for different shots.
Austin Schuhade6d082014-03-09 00:53:06 -0800422 return (speed / values.drivetrain_max_speed) * 0.2;
Austin Schuh58d23682014-02-23 01:39:50 -0800423 }
424
Austin Schuh01c652b2014-02-21 23:13:42 -0800425 private:
Austin Schuh58d23682014-02-23 01:39:50 -0800426 bool is_high_gear_;
427 double shot_power_;
428 double goal_angle_;
429 double separation_angle_;
Austin Schuh5d8c5e72014-03-07 20:24:34 -0800430 bool velocity_compensation_;
431 double intake_power_;
432 bool was_running_;
Austin Schuhb7dfabc2014-03-01 18:57:42 -0800433
434 ActionQueue action_queue_;
Brian Silverman756f9ff2014-01-17 23:40:23 -0800435};
436
437} // namespace joysticks
438} // namespace input
439} // namespace frc971
440
441int main() {
442 ::aos::Init();
443 ::frc971::input::joysticks::Reader reader;
444 reader.Run();
445 ::aos::Cleanup();
446}