Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 1 | #ifndef Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_VACUUM_H_ |
| 2 | #define Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_VACUUM_H_ |
| 3 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 4 | #include "aos/events/event_loop.h" |
| 5 | #include "frc971/control_loops/control_loops_generated.h" |
| 6 | #include "frc971/control_loops/profiled_subsystem_generated.h" |
| 7 | #include "y2019/control_loops/superstructure/superstructure_goal_generated.h" |
| 8 | #include "y2019/control_loops/superstructure/superstructure_output_generated.h" |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 9 | |
| 10 | namespace y2019 { |
| 11 | namespace control_loops { |
| 12 | namespace superstructure { |
| 13 | |
| 14 | class Vacuum { |
| 15 | public: |
| 16 | Vacuum() {} |
| 17 | void Iterate(const SuctionGoal *unsafe_goal, float suction_pressure, |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 18 | OutputT *output, bool *has_piece, aos::EventLoop *event_loop); |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 19 | |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 20 | // Voltage to the vaccum pump when we are attempting to acquire a piece |
Austin Schuh | c2ee66b | 2019-02-19 13:37:46 -0800 | [diff] [blame] | 21 | static constexpr double kPumpVoltage = 8.0; |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 22 | |
| 23 | // Voltage to the vaccum pump when we have a piece |
Austin Schuh | 47bb88d | 2019-02-19 16:49:44 -0800 | [diff] [blame] | 24 | static constexpr double kPumpHasPieceVoltage = 2.25; |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 25 | |
| 26 | // Time to continue at the higher pump voltage after getting a gamepiece |
| 27 | static constexpr aos::monotonic_clock::duration kTimeAtHigherVoltage = |
Austin Schuh | c2ee66b | 2019-02-19 13:37:46 -0800 | [diff] [blame] | 28 | std::chrono::milliseconds(100); |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 29 | |
Tyler Chatow | 7db827f | 2019-02-24 00:10:13 -0800 | [diff] [blame] | 30 | // Time required for the game piece to be released from a vacuum |
| 31 | static constexpr aos::monotonic_clock::duration kReleaseTime = |
| 32 | std::chrono::milliseconds(250); |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | bool had_piece_ = false; |
Tyler Chatow | 7db827f | 2019-02-24 00:10:13 -0800 | [diff] [blame] | 36 | aos::monotonic_clock::time_point last_release_time_ = |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 37 | aos::monotonic_clock::epoch(); |
Austin Schuh | 5462941 | 2019-04-14 19:53:59 -0700 | [diff] [blame] | 38 | // Time since the last time we had a game piece while disabled. |
| 39 | aos::monotonic_clock::time_point last_disable_has_piece_time_ = |
| 40 | aos::monotonic_clock::min_time; |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 41 | aos::monotonic_clock::time_point time_at_last_acquisition_ = |
| 42 | aos::monotonic_clock::epoch(); |
| 43 | double filtered_pressure_ = 1.0; |
| 44 | |
Austin Schuh | 5462941 | 2019-04-14 19:53:59 -0700 | [diff] [blame] | 45 | bool filtered_had_piece_near_disabled_ = false; |
| 46 | |
| 47 | static constexpr double kVacuumOnThreshold = 0.70; |
| 48 | static constexpr double kVacuumOffThreshold = 0.85; |
Theo Bafrali | 3274a18 | 2019-02-17 20:01:38 -0800 | [diff] [blame] | 49 | |
| 50 | static constexpr double kFilterTimeConstant = 0.1; |
| 51 | static constexpr double dt = .00505; |
| 52 | static constexpr double kSuctionAlpha = |
| 53 | dt * (1 - kFilterTimeConstant) / (kFilterTimeConstant); |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(Vacuum); |
| 56 | }; |
| 57 | |
| 58 | } // namespace superstructure |
| 59 | } // namespace control_loops |
| 60 | } // namespace y2019 |
| 61 | |
| 62 | #endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |