blob: 01cf0e3d4c321846cd33c47ed1b9f37d6446f42f [file] [log] [blame]
Daniel Petti1f448512013-10-19 19:35:55 +00001#include "stdio.h"
2
3#include "aos/common/control_loop/Timing.h"
4#include "aos/common/time.h"
5#include "aos/common/util/trapezoid_profile.h"
6#include "aos/common/messages/RobotState.q.h"
7#include "aos/common/logging/logging.h"
8
9#include "bot3/autonomous/auto.q.h"
James Kuszmaule63ef652013-11-06 20:35:32 -080010#include "bot3/control_loops/shooter/shooter_motor.q.h"
Daniel Petti1f448512013-10-19 19:35:55 +000011#include "frc971/constants.h"
12
13using ::aos::time::Time;
14
15namespace bot3 {
16namespace autonomous {
17
James Kuszmaule63ef652013-11-06 20:35:32 -080018bool ShouldExitAuto() {
19 ::bot3::autonomous::autonomous.FetchLatest();
20 bool ans = !::bot3::autonomous::autonomous->run_auto;
21 if (ans) {
22 LOG(INFO, "Time to exit auto mode\n");
23 }
24 return ans;
25}
26
27void SetShooter(double velocity, bool push) {
28 LOG(INFO, "Setting shooter velocity to %f\n", velocity);
Daniel Petti96c1b572013-11-12 05:47:16 +000029 control_loops::shooter.goal.MakeWithBuilder().intake(0)
James Kuszmaule63ef652013-11-06 20:35:32 -080030 .velocity(velocity).push(push).Send();
31}
32
Daniel Petti96c1b572013-11-12 05:47:16 +000033bool ShooterReady() {
34 bool ready = control_loops::shooter.status.FetchNextBlocking() && control_loops::shooter.status->ready;
35 LOG(DEBUG, "Shooter ready: %d\n", ready);
36 return ready;
37}
38
Daniel Petti1f448512013-10-19 19:35:55 +000039void HandleAuto() {
Daniel Petti96c1b572013-11-12 05:47:16 +000040 double shooter_velocity = 500.0;
41 bool first_accl = true;
James Kuszmaule63ef652013-11-06 20:35:32 -080042 while (!ShouldExitAuto()) {
43 SetShooter(shooter_velocity, false);
Daniel Petti96c1b572013-11-12 05:47:16 +000044 if (first_accl) {
45 ::aos::time::SleepFor(::aos::time::Time::InSeconds(3.0));
46 first_accl = false;
47 }
James Kuszmaule63ef652013-11-06 20:35:32 -080048 if (ShouldExitAuto()) return;
49 SetShooter(shooter_velocity, true);
Daniel Petti96c1b572013-11-12 05:47:16 +000050 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
James Kuszmaule63ef652013-11-06 20:35:32 -080051 SetShooter(shooter_velocity, false);
Daniel Petti96c1b572013-11-12 05:47:16 +000052 ::aos::time::SleepFor(::aos::time::Time::InSeconds(2.0));
James Kuszmaule63ef652013-11-06 20:35:32 -080053 }
54 return;
Daniel Petti1f448512013-10-19 19:35:55 +000055}
56
57} // namespace autonomous
58} // namespace bot3