Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <deque>
7 : #include <pup.h>
8 : #include <unordered_map>
9 : #include <utility>
10 :
11 : #include "ControlSystem/ControlErrors/Size/Info.hpp"
12 : #include "ControlSystem/ControlErrors/Size/State.hpp"
13 :
14 : namespace control_system::size {
15 : /*!
16 : * \brief A struct for holding a history of control errors for each state in the
17 : * `control_system::Systems::Size` control system.
18 : */
19 1 : struct StateHistory {
20 0 : StateHistory();
21 :
22 : /// \brief Only keep `num_times_to_store` entries in the state_history
23 1 : StateHistory(size_t num_times_to_store);
24 :
25 : /*!
26 : * \brief Store the control errors for all `control_system::size::State`s.
27 : *
28 : * \param time Time to store control errors at
29 : * \param info `control_system::size::Info`
30 : * \param control_error_args `control_system::size::ControlErrorArgs`
31 : */
32 1 : void store(double time, const Info& info,
33 : const ControlErrorArgs& control_error_args);
34 :
35 : /*!
36 : * \brief Return a const reference to the stored control errors from all the
37 : * states.
38 : *
39 : * \param state_number `size_t` corresponding to the
40 : * `control_system::size::State::number()` of a state.
41 : * \return std::deque<std::pair<double, double>> The `std::pair` holds
42 : * the time and control error, respectively. The `std::deque` is ordered with
43 : * earlier times at the "front" and later times at the "back". This is to make
44 : * iteration over the deque easier as we typically want to start with earlier
45 : * times.
46 : */
47 1 : const std::deque<std::pair<double, double>>& state_history(
48 : size_t state_number) const;
49 :
50 : // NOLINTNEXTLINE(google-runtime-references)
51 0 : void pup(PUP::er& p);
52 :
53 0 : friend bool operator==(const StateHistory& lhs, const StateHistory& rhs);
54 0 : friend bool operator!=(const StateHistory& lhs, const StateHistory& rhs);
55 :
56 : private:
57 0 : void initialize_stored_control_errors();
58 :
59 0 : size_t num_times_to_store_{};
60 : std::unordered_map<size_t, std::deque<std::pair<double, double>>>
61 0 : stored_control_errors_{};
62 : };
63 : } // namespace control_system::size
|