Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame^] | 1 | #include "stdio.h" |
| 2 | |
| 3 | #include "aos/aos_core.h" |
| 4 | #include "aos/common/control_loop/Timing.h" |
| 5 | #include "aos/common/time.h" |
| 6 | #include "frc971/autonomous/auto.q.h" |
| 7 | #include "frc971/control_loops/DriveTrain.q.h" |
| 8 | #include "frc971/control_loops/wrist/wrist_motor.q.h" |
| 9 | #include "frc971/control_loops/index/index_motor.q.h" |
| 10 | #include "frc971/control_loops/shooter/shooter_motor.q.h" |
| 11 | #include "frc971/control_loops/angle_adjust/angle_adjust_motor.q.h" |
| 12 | |
| 13 | using ::aos::time::Time; |
| 14 | |
| 15 | namespace frc971 { |
| 16 | namespace autonomous { |
| 17 | |
| 18 | void SetShooterVelocity(double velocity) { |
| 19 | control_loops::shooter.goal.MakeWithBuilder() |
| 20 | .velocity(velocity).Send(); |
| 21 | } |
| 22 | |
| 23 | void StartIntake() { |
| 24 | control_loops::intake.goal.MakeWithBuilder() |
| 25 | .goal_state(2).Send(); |
| 26 | } |
| 27 | |
| 28 | void PreloadIntake() { |
| 29 | control_loops::intake.goal.MakeWithBuilder() |
| 30 | .goal_state(3).Send(); |
| 31 | } |
| 32 | |
| 33 | void ShootIntake() { |
| 34 | control_loops::intake.goal.MakeWithBuilder() |
| 35 | .goal_state(4).Send(); |
| 36 | } |
| 37 | |
| 38 | void WaitForShooter() { |
| 39 | control_loops::shooter.status.FetchLatest(); |
| 40 | while (!control_loops::shooter.status->ready) { |
| 41 | control_loops::shooter.status.FetchNextBlocking(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // TODO(aschuh): Send the number of discs shot in the status message. |
| 46 | void ShootNDiscs(int n) { |
| 47 | control_loops::intake.status.FetchLatest(); |
| 48 | while (!control_loops::intake.status->ready) { |
| 49 | control_loops::intake.status.FetchNextBlocking(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | bool ShouldExitAuto() { |
| 54 | ::frc971::autonomous::autonomous.FetchLatest(); |
| 55 | return !::frc971::autonomous::autonomous->run_auto; |
| 56 | } |
| 57 | |
| 58 | // TODO(aschuh): Drivetrain needs a profile somewhere. |
| 59 | // Here isn't the best spot. It should be in another thread/process |
| 60 | |
| 61 | void HandleAuto() { |
| 62 | SetShooterVelocity(200.0); |
| 63 | PreloadIntake(); |
| 64 | |
| 65 | WaitForShooter(); |
| 66 | ShootIntake(); |
| 67 | |
| 68 | // Wait for the wrist and angle adjust to finish zeroing before shooting. |
| 69 | // Sigh, constants go where? |
| 70 | |
| 71 | control_loops::drivetrain.goal.MakeWithBuilder() |
| 72 | .control_loop_driving(true) |
| 73 | .left_goal(0.0) |
| 74 | .right_goal(0.0).Send(); |
| 75 | } |
| 76 | |
| 77 | } // namespace autonomous |
| 78 | } // namespace frc971 |