blob: 89f89a0a0863c5d066cb8d3d5090847084513329 [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 +000033void SpinUp() {
34 LOG(INFO, "Tricking shooter into running at full power...\n");
35 control_loops::shooter.position.MakeWithBuilder().velocity(0).Send();
James Kuszmaule63ef652013-11-06 20:35:32 -080036}
37
Daniel Petti96c1b572013-11-12 05:47:16 +000038bool ShooterReady() {
39 bool ready = control_loops::shooter.status.FetchNextBlocking() && control_loops::shooter.status->ready;
40 LOG(DEBUG, "Shooter ready: %d\n", ready);
41 return ready;
42}
43
Daniel Petti1f448512013-10-19 19:35:55 +000044void HandleAuto() {
Daniel Petti96c1b572013-11-12 05:47:16 +000045 double shooter_velocity = 500.0;
46 bool first_accl = true;
James Kuszmaule63ef652013-11-06 20:35:32 -080047 while (!ShouldExitAuto()) {
48 SetShooter(shooter_velocity, false);
Daniel Petti96c1b572013-11-12 05:47:16 +000049 if (first_accl) {
50 ::aos::time::SleepFor(::aos::time::Time::InSeconds(3.0));
51 first_accl = false;
52 }
James Kuszmaule63ef652013-11-06 20:35:32 -080053 if (ShouldExitAuto()) return;
54 SetShooter(shooter_velocity, true);
Daniel Petti96c1b572013-11-12 05:47:16 +000055 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
James Kuszmaule63ef652013-11-06 20:35:32 -080056 SetShooter(shooter_velocity, false);
Daniel Petti96c1b572013-11-12 05:47:16 +000057 // We just shot, trick it into spinning back up.
58 SpinUp();
59 ::aos::time::SleepFor(::aos::time::Time::InSeconds(2.0));
James Kuszmaule63ef652013-11-06 20:35:32 -080060 }
61 return;
Daniel Petti1f448512013-10-19 19:35:55 +000062}
63
64} // namespace autonomous
65} // namespace bot3