blob: 58ad109cdc03858b3b4539e5a65347d8b4b82e9f [file] [log] [blame]
Theo Bafrali3274a182019-02-17 20:01:38 -08001#ifndef Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_VACUUM_H_
2#define Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_VACUUM_H_
3
Alex Perrycb7da4b2019-08-28 19:35:56 -07004#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 Bafrali3274a182019-02-17 20:01:38 -08009
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080010namespace y2019::control_loops::superstructure {
Theo Bafrali3274a182019-02-17 20:01:38 -080011
12class Vacuum {
13 public:
14 Vacuum() {}
15 void Iterate(const SuctionGoal *unsafe_goal, float suction_pressure,
Alex Perrycb7da4b2019-08-28 19:35:56 -070016 OutputT *output, bool *has_piece, aos::EventLoop *event_loop);
Theo Bafrali3274a182019-02-17 20:01:38 -080017
Theo Bafrali3274a182019-02-17 20:01:38 -080018 // Voltage to the vaccum pump when we are attempting to acquire a piece
Austin Schuhc2ee66b2019-02-19 13:37:46 -080019 static constexpr double kPumpVoltage = 8.0;
Theo Bafrali3274a182019-02-17 20:01:38 -080020
21 // Voltage to the vaccum pump when we have a piece
Austin Schuh47bb88d2019-02-19 16:49:44 -080022 static constexpr double kPumpHasPieceVoltage = 2.25;
Theo Bafrali3274a182019-02-17 20:01:38 -080023
24 // Time to continue at the higher pump voltage after getting a gamepiece
25 static constexpr aos::monotonic_clock::duration kTimeAtHigherVoltage =
Austin Schuhc2ee66b2019-02-19 13:37:46 -080026 std::chrono::milliseconds(100);
Theo Bafrali3274a182019-02-17 20:01:38 -080027
Tyler Chatow7db827f2019-02-24 00:10:13 -080028 // Time required for the game piece to be released from a vacuum
29 static constexpr aos::monotonic_clock::duration kReleaseTime =
30 std::chrono::milliseconds(250);
Theo Bafrali3274a182019-02-17 20:01:38 -080031
32 private:
33 bool had_piece_ = false;
Tyler Chatow7db827f2019-02-24 00:10:13 -080034 aos::monotonic_clock::time_point last_release_time_ =
Theo Bafrali3274a182019-02-17 20:01:38 -080035 aos::monotonic_clock::epoch();
Austin Schuh54629412019-04-14 19:53:59 -070036 // Time since the last time we had a game piece while disabled.
37 aos::monotonic_clock::time_point last_disable_has_piece_time_ =
38 aos::monotonic_clock::min_time;
Theo Bafrali3274a182019-02-17 20:01:38 -080039 aos::monotonic_clock::time_point time_at_last_acquisition_ =
40 aos::monotonic_clock::epoch();
41 double filtered_pressure_ = 1.0;
42
Austin Schuh54629412019-04-14 19:53:59 -070043 bool filtered_had_piece_near_disabled_ = false;
44
45 static constexpr double kVacuumOnThreshold = 0.70;
46 static constexpr double kVacuumOffThreshold = 0.85;
Theo Bafrali3274a182019-02-17 20:01:38 -080047
48 static constexpr double kFilterTimeConstant = 0.1;
49 static constexpr double dt = .00505;
50 static constexpr double kSuctionAlpha =
51 dt * (1 - kFilterTimeConstant) / (kFilterTimeConstant);
52
53 DISALLOW_COPY_AND_ASSIGN(Vacuum);
54};
55
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080056} // namespace y2019::control_loops::superstructure
Theo Bafrali3274a182019-02-17 20:01:38 -080057
58#endif // Y2019_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_