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 
117  void simulate_sensors();
118 
119  void setup_gui();
120 
121  void set_time(double t);
122 };
123 
124 } // namespace mc_control
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_control::Ticker::log_
std::shared_ptr< mc_rtc::log::FlatLog > log_
Definition: Ticker.h:97
MC_CONTROL_DLLAPI
#define MC_CONTROL_DLLAPI
Definition: api.h:50
mc_control::Ticker
Definition: Ticker.h:30
mc_control::Ticker::Configuration
Definition: Ticker.h:33
mc_control::Ticker::Configuration::Replay
Definition: Ticker.h:46
mc_control::MCGlobalController
Definition: mc_global_controller.h:22
mc_control::Ticker::gc_
mc_control::MCGlobalController gc_
Definition: Ticker.h:96
mc_control::Ticker::elapsed_time
double elapsed_time() const noexcept
Definition: Ticker.h:86
FlatLog.h
mc_global_controller.h
logging.h
mc_control
Definition: CompletionCriteria.h:10
mc_control::Ticker::controller
const mc_control::MCGlobalController & controller() const noexcept
Definition: Ticker.h:89
mc_control::Ticker::controller
mc_control::MCGlobalController & controller() noexcept
Definition: Ticker.h:92
mc_control::Ticker::config_
Configuration config_
Definition: Ticker.h:95