bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
cosim_participant.h
Go to the documentation of this file.
1#ifndef BITSIM_COSIM_COSIM_PARTICIPANT_H
2#define BITSIM_COSIM_COSIM_PARTICIPANT_H
3
9
10#include <boost/noncopyable.hpp>
11
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace bitsim
17{
18namespace cosim
19{
20
29
43class CoSimParticipant : private boost::noncopyable
44{
45 public:
54 CoSimParticipant(CouplingLayout layout, const std::string &name, CoSimSubsystem &subsystem,
55 distributed::Transport &transport, const CouplingConfig &coupling = {},
56 const CoSimParticipantConfig &config = {});
57
59
63 void initialise(real_t t0 = 0.0);
64
69
73 void leave();
74
75 real_t time() const noexcept { return t_; }
76
80 const std::vector<real_t> &inputs() const { return state_.inputs.at(me_); }
81
85 const std::vector<real_t> &inputs(const std::string &name) const
86 {
87 return state_.inputs.at(layout_.index(name));
88 }
89
90 const distributed::Synchroniser &synchroniser() const noexcept { return *sync_; }
91
92 uint_t total_iterations() const noexcept { return total_iterations_; }
93
94 uint_t n_not_converged() const noexcept { return n_not_converged_; }
95
96 private:
97 // send my outputs, return everybody's, in the order of the layout
98 std::vector<std::vector<real_t>> exchange_(const std::vector<real_t> &mine);
99
100 CouplingLayout layout_;
101 uint_t me_;
102 CoSimSubsystem &subsystem_;
103 CouplingConfig coupling_;
104 std::unique_ptr<distributed::Synchroniser> sync_;
105 CouplingState state_;
106 real_t t_{0.0};
107 uint_t round_{0};
108 bool initialised_{false};
109 uint_t total_iterations_{0};
110 uint_t n_not_converged_{0};
111};
112
113} // namespace cosim
114} // namespace bitsim
115
116#endif // BITSIM_COSIM_COSIM_PARTICIPANT_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
const std::vector< real_t > & inputs(const std::string &name) const
The inputs of subsystem name at the present time: every participant knows them.
Definition cosim_participant.h:85
void leave()
Tell the others that this participant stops.
Definition cosim_participant.cpp:107
uint_t n_not_converged() const noexcept
Definition cosim_participant.h:94
const std::vector< real_t > & inputs() const
The inputs of this participant's subsystem at the present time.
Definition cosim_participant.h:80
void initialise(real_t t0=0.0)
Find the inputs at time t0, with the others.
Definition cosim_participant.cpp:67
const distributed::Synchroniser & synchroniser() const noexcept
Definition cosim_participant.h:90
real_t time() const noexcept
Definition cosim_participant.h:75
uint_t total_iterations() const noexcept
Definition cosim_participant.h:92
CoSimParticipant(CouplingLayout layout, const std::string &name, CoSimSubsystem &subsystem, distributed::Transport &transport, const CouplingConfig &coupling={}, const CoSimParticipantConfig &config={})
Definition cosim_participant.cpp:11
MacroStepResult step(real_t H)
Advance by H, with the others.
Definition cosim_participant.cpp:76
A part of a coupled system that a co-simulation steps on its own: a robot, a trailer,...
Definition cosim_subsystem.h:29
The subsystems of a co-simulation, their sizes, and which output feeds which input.
Definition coupling.h:35
Keeps the participants of a distributed simulation in step.
Definition synchroniser.h:99
How the participants of a distributed simulation reach each other: everything one publishes,...
Definition transport.h:34
Definition co_simulation.cpp:9
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
The settings of CoSimParticipant.
Definition cosim_participant.h:25
real_t timeout
how long a try waits for the others [s]
Definition cosim_participant.h:26
real_t resend_period
how often a waiting try sends its outputs again [s]
Definition cosim_participant.h:27
How a co-simulation couples its subsystems.
Definition coupling.h:102
The inputs of every subsystem at the present time, and at the time before.
Definition coupling.h:118
What one macro step did.
Definition coupling.h:128