blob: 8a3c1adec41c7aebe00f540cafca335db09d3f63 [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"
10#include "bot3/control_loops/drivetrain/drivetrain.q.h"
James Kuszmaule63ef652013-11-06 20:35:32 -080011#include "bot3/control_loops/shooter/shooter_motor.q.h"
Daniel Petti1f448512013-10-19 19:35:55 +000012#include "frc971/constants.h"
13
14using ::aos::time::Time;
15
16namespace bot3 {
17namespace autonomous {
18
James Kuszmaule63ef652013-11-06 20:35:32 -080019bool ShouldExitAuto() {
20 ::bot3::autonomous::autonomous.FetchLatest();
21 bool ans = !::bot3::autonomous::autonomous->run_auto;
22 if (ans) {
23 LOG(INFO, "Time to exit auto mode\n");
24 }
25 return ans;
26}
27
28void SetShooter(double velocity, bool push) {
29 LOG(INFO, "Setting shooter velocity to %f\n", velocity);
30 control_loops::shooter.goal.MakeWithBuilder()
31 .velocity(velocity).push(push).Send();
32}
33
34bool ShooterReady() {
35 control_loops::shooter.status.FetchLatest();
36 return control_loops::shooter.status->ready;
37}
38
Daniel Petti1f448512013-10-19 19:35:55 +000039// start with N discs in the indexer
40void HandleAuto() {
James Kuszmaule63ef652013-11-06 20:35:32 -080041 double shooter_velocity = 250.0;
42 while (!ShouldExitAuto()) {
43 SetShooter(shooter_velocity, false);
44 while (!ShouldExitAuto() && !ShooterReady());
45 if (ShouldExitAuto()) return;
46 SetShooter(shooter_velocity, true);
47 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
48 SetShooter(shooter_velocity, false);
49 // Waits because, until we have feedback,
50 // the shooter will always think it's ready.
51 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
52 }
53 return;
Daniel Petti1f448512013-10-19 19:35:55 +000054}
55
56} // namespace autonomous
57} // namespace bot3