Daniel Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 1 | #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 Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame^] | 11 | #include "bot3/control_loops/shooter/shooter_motor.q.h" |
Daniel Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 12 | #include "frc971/constants.h" |
| 13 | |
| 14 | using ::aos::time::Time; |
| 15 | |
| 16 | namespace bot3 { |
| 17 | namespace autonomous { |
| 18 | |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame^] | 19 | bool 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 | |
| 28 | void 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 | |
| 34 | bool ShooterReady() { |
| 35 | control_loops::shooter.status.FetchLatest(); |
| 36 | return control_loops::shooter.status->ready; |
| 37 | } |
| 38 | |
Daniel Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 39 | // start with N discs in the indexer |
| 40 | void HandleAuto() { |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame^] | 41 | 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 Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } // namespace autonomous |
| 57 | } // namespace bot3 |