Ticker.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2023 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 
9 #include <mc_rtc/log/FlatLog.h>
10 
11 #include <mc_rtc/config.h>
12 #include <mc_rtc/logging.h>
13 #include <mc_rtc/version.h>
14 
15 namespace mc_control
16 {
17 
31 {
34  {
36  std::string mc_rtc_configuration = "";
38  bool step_by_step = false;
40  double run_for = std::numeric_limits<double>::infinity();
42  bool no_sync = false;
44  double sync_ratio = 1.0;
46  struct Replay
47  {
49  std::string log = "";
51  bool with_inputs = true;
53  bool with_gui_inputs = true;
56  std::string with_datastore_config = "";
58  bool with_outputs = false;
60  bool stop_after_log = true;
62  bool exit_after_log = false;
63  };
64  Replay replay_configuration = {};
65  };
66 
68  Ticker(const Configuration & config);
69 
74  void reset();
75 
80  bool step();
81 
83  void run();
84 
86  inline double elapsed_time() const noexcept { return static_cast<double>(iters_) * gc_.timestep(); }
87 
89  inline const mc_control::MCGlobalController & controller() const noexcept { return gc_; }
90 
92  inline mc_control::MCGlobalController & controller() noexcept { return gc_; }
93 
94 protected:
97  std::shared_ptr<mc_rtc::log::FlatLog> log_;
98 
100  size_t iters_ = 0;
101 
103  double sim_real_ratio_ = 1.0;
104 
106  std::atomic<bool> do_reset_ = false;
107 
109  bool running_ = true;
110 
112  bool replay_done_ = false;
113 
115  int64_t rem_steps_ = 0;
116 
118 
119  void setup_gui();
120 
121  void set_time(double t);
122 };
123 
124 } // namespace mc_control
#define MC_CONTROL_DLLAPI
Definition: api.h:50
Definition: CompletionCriteria.h:11
Definition: mc_global_controller.h:23
Definition: Ticker.h:34
Definition: Ticker.h:31
mc_control::MCGlobalController gc_
Definition: Ticker.h:96
std::shared_ptr< mc_rtc::log::FlatLog > log_
Definition: Ticker.h:97
mc_control::MCGlobalController & controller() noexcept
Definition: Ticker.h:92
Ticker(const Configuration &config)
void set_time(double t)
Configuration config_
Definition: Ticker.h:95
double elapsed_time() const noexcept
Definition: Ticker.h:86
const mc_control::MCGlobalController & controller() const noexcept
Definition: Ticker.h:89