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" |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 10 | #include "bot3/control_loops/shooter/shooter_motor.q.h" |
Daniel Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 11 | #include "frc971/constants.h" |
| 12 | |
| 13 | using ::aos::time::Time; |
| 14 | |
| 15 | namespace bot3 { |
| 16 | namespace autonomous { |
| 17 | |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 18 | bool 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 | |
| 27 | void SetShooter(double velocity, bool push) { |
| 28 | LOG(INFO, "Setting shooter velocity to %f\n", velocity); |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 29 | control_loops::shooter.goal.MakeWithBuilder().intake(0) |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 30 | .velocity(velocity).push(push).Send(); |
| 31 | } |
| 32 | |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 33 | void SpinUp() { |
| 34 | LOG(INFO, "Tricking shooter into running at full power...\n"); |
| 35 | control_loops::shooter.position.MakeWithBuilder().velocity(0).Send(); |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 38 | bool 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 Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 44 | void HandleAuto() { |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 45 | double shooter_velocity = 500.0; |
| 46 | bool first_accl = true; |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 47 | while (!ShouldExitAuto()) { |
| 48 | SetShooter(shooter_velocity, false); |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 49 | if (first_accl) { |
| 50 | ::aos::time::SleepFor(::aos::time::Time::InSeconds(3.0)); |
| 51 | first_accl = false; |
| 52 | } |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 53 | if (ShouldExitAuto()) return; |
| 54 | SetShooter(shooter_velocity, true); |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 55 | ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25)); |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 56 | SetShooter(shooter_velocity, false); |
Daniel Petti | 96c1b57 | 2013-11-12 05:47:16 +0000 | [diff] [blame] | 57 | // We just shot, trick it into spinning back up. |
| 58 | SpinUp(); |
| 59 | ::aos::time::SleepFor(::aos::time::Time::InSeconds(2.0)); |
James Kuszmaul | e63ef65 | 2013-11-06 20:35:32 -0800 | [diff] [blame] | 60 | } |
| 61 | return; |
Daniel Petti | 1f44851 | 2013-10-19 19:35:55 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace autonomous |
| 65 | } // namespace bot3 |