|
bitsim
Model, simulate, estimate and control robots in C++
|
Keeps the participants of a distributed simulation in step. More...
#include <synchroniser.h>


Public Member Functions | |
| Synchroniser (Transport &transport, const std::string &participant, const SynchroniserConfig &config) | |
| ~Synchroniser () | |
| Leaves, if leave() was not called. | |
| const std::vector< PeerState > & | exchange (uint_t step, const std::vector< BodyState > &bodies, const std::vector< real_t > &values={}) |
| Send the state of this participant's bodies at step, and get the others'. | |
| void | leave () |
| Tell the others that this participant stops after the last step it exchanged. | |
| real_t | time_of (uint_t step) const noexcept |
| const std::string & | participant () const noexcept |
| const SynchroniserConfig & | config () const noexcept |
| uint_t | n_sent () const noexcept |
| uint_t | n_received () const noexcept |
| uint_t | n_resent () const noexcept |
| uint_t | n_overruns () const noexcept |
| wall-clock: the steps that started more than a sync period late | |
| real_t | max_wait () const noexcept |
| lockstep: the longest exchange() waited [s]; wall-clock: the latest a step started | |
Keeps the participants of a distributed simulation in step.
Every participant simulates its own robots and calls exchange() every sync_period of simulated time with the state of its bodies. exchange() sends them to the others through the transport and returns what this participant knows of the others, which it then uses to place ghosts of their bodies in its world, to sense them and to avoid them.
In lockstep (SyncMode::LOCKSTEP) exchange() returns once every peer has sent the same step. While it waits it sends its last two steps again every resend_period, so that a peer that connected late, or lost a message, still gets them; no participant can be more than a step ahead of another, so two are enough. A peer that leave()s is no longer waited for after its last step.
In wall-clock mode (SyncMode::WALL_CLOCK) exchange() first waits until the wall clock reaches the step, step * sync_period / real_time_factor after the first call, or counts an overrun if it is already late, then sends and returns the newest state of every peer, moved forward with its velocities by its age if extrapolate is set.
| bitsim::distributed::Synchroniser::Synchroniser | ( | Transport & | transport, |
| const std::string & | participant, | ||
| const SynchroniserConfig & | config ) |
| bitsim::distributed::Synchroniser::~Synchroniser | ( | ) |
Leaves, if leave() was not called.
|
inlinenoexcept |
| const std::vector< PeerState > & bitsim::distributed::Synchroniser::exchange | ( | uint_t | step, |
| const std::vector< BodyState > & | bodies, | ||
| const std::vector< real_t > & | values = {} ) |
Send the state of this participant's bodies at step, and get the others'.
| step | the step, counted from 0; every participant exchanges every step |
| bodies | the state of this participant's bodies at the step |
| values | numbers to send with the bodies, see StateMessage; they are not extrapolated |
| std::runtime_error | in lockstep if a peer has not sent the step within timeout |
| void bitsim::distributed::Synchroniser::leave | ( | ) |
Tell the others that this participant stops after the last step it exchanged.
|
inlinenoexcept |
lockstep: the longest exchange() waited [s]; wall-clock: the latest a step started
|
inlinenoexcept |
wall-clock: the steps that started more than a sync period late
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |