blob: 7a3393bd0636dcd70c514cdcb9e3cd254b981d9d [file] [log] [blame]
Sabina Davisedf89472020-02-17 15:27:37 -08001#ifndef Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_
2#define Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_
3
James Kuszmaul61750662021-06-21 21:32:33 -07004#include "frc971/control_loops/control_loop.h"
Sabina Davisedf89472020-02-17 15:27:37 -08005#include "frc971/control_loops/state_feedback_loop.h"
6#include "y2020/control_loops/superstructure/shooter/flywheel_controller.h"
7#include "y2020/control_loops/superstructure/superstructure_goal_generated.h"
8#include "y2020/control_loops/superstructure/superstructure_output_generated.h"
9#include "y2020/control_loops/superstructure/superstructure_position_generated.h"
10#include "y2020/control_loops/superstructure/superstructure_status_generated.h"
11
12namespace y2020 {
13namespace control_loops {
14namespace superstructure {
15namespace shooter {
16
17// Handles all flywheels together.
18class Shooter {
19 public:
milind-u78f21b72021-10-10 13:47:28 -070020 static constexpr double kVelocityToleranceFinisher = 3.0;
21 static constexpr double kVelocityToleranceAccelerator = 4.0;
22
Sabina Davisedf89472020-02-17 15:27:37 -080023 Shooter();
24
25 flatbuffers::Offset<ShooterStatus> RunIteration(
26 const ShooterGoal *goal, const ShooterPosition *position,
Sabina Davis0f31d3f2020-02-20 20:41:00 -080027 flatbuffers::FlatBufferBuilder *fbb, OutputT *output,
28 const aos::monotonic_clock::time_point position_timestamp);
29
30 bool ready() { return ready_; }
Sabina Davisedf89472020-02-17 15:27:37 -080031
Austin Schuh263dead2021-04-04 21:19:19 -070032 float finisher_goal() const { return finisher_.goal(); }
33 float accelerator_goal() const { return accelerator_left_.goal(); }
34
Sabina Davisedf89472020-02-17 15:27:37 -080035 private:
milind-u7baf7342021-08-25 18:31:26 -070036 // Minumum difference between the last local maximum finisher angular velocity
37 // and the current finisher angular velocity when we have a ball in the
38 // flywheel, in radians/s. This arises because the flywheel slows down when
39 // there is a ball in it. We can use this to determine when a ball is in the
40 // flywheel and when it gets shot.
41 static constexpr double kMinFinisherVelocityDipWithBall = 5.0;
42
Sabina Davisedf89472020-02-17 15:27:37 -080043 FlywheelController finisher_, accelerator_left_, accelerator_right_;
44
Sabina Davis0f31d3f2020-02-20 20:41:00 -080045 bool UpToSpeed(const ShooterGoal *goal);
46 bool ready_ = false;
47
milind-u7baf7342021-08-25 18:31:26 -070048 int balls_shot_ = 0;
49 bool finisher_goal_changed_ = false;
50 bool ball_in_finisher_ = false;
51 // Last local maximum in the finisher angular velocity
52 double last_finisher_velocity_max_ = 0.0;
53 // True if the finisher's average acceleration over the last dt is positive
54 bool finisher_accelerating_ = false;
55
Sabina Davisedf89472020-02-17 15:27:37 -080056 DISALLOW_COPY_AND_ASSIGN(Shooter);
57};
58
59} // namespace shooter
60} // namespace superstructure
61} // namespace control_loops
62} // namespace y2020
63
64#endif // Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_