bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::distributed::Synchroniser Class Reference

Keeps the participants of a distributed simulation in step. More...

#include <synchroniser.h>

Inheritance diagram for bitsim::distributed::Synchroniser:
Collaboration diagram for bitsim::distributed::Synchroniser:

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ Synchroniser()

bitsim::distributed::Synchroniser::Synchroniser ( Transport & transport,
const std::string & participant,
const SynchroniserConfig & config )

◆ ~Synchroniser()

bitsim::distributed::Synchroniser::~Synchroniser ( )

Leaves, if leave() was not called.

Member Function Documentation

◆ config()

const SynchroniserConfig & bitsim::distributed::Synchroniser::config ( ) const
inlinenoexcept

◆ exchange()

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'.

Parameters
stepthe step, counted from 0; every participant exchanges every step
bodiesthe state of this participant's bodies at the step
valuesnumbers to send with the bodies, see StateMessage; they are not extrapolated
Returns
the peers, sorted by name
Exceptions
std::runtime_errorin lockstep if a peer has not sent the step within timeout

◆ leave()

void bitsim::distributed::Synchroniser::leave ( )

Tell the others that this participant stops after the last step it exchanged.

◆ max_wait()

real_t bitsim::distributed::Synchroniser::max_wait ( ) const
inlinenoexcept

lockstep: the longest exchange() waited [s]; wall-clock: the latest a step started

◆ n_overruns()

uint_t bitsim::distributed::Synchroniser::n_overruns ( ) const
inlinenoexcept

wall-clock: the steps that started more than a sync period late

◆ n_received()

uint_t bitsim::distributed::Synchroniser::n_received ( ) const
inlinenoexcept

◆ n_resent()

uint_t bitsim::distributed::Synchroniser::n_resent ( ) const
inlinenoexcept

◆ n_sent()

uint_t bitsim::distributed::Synchroniser::n_sent ( ) const
inlinenoexcept

◆ participant()

const std::string & bitsim::distributed::Synchroniser::participant ( ) const
inlinenoexcept

◆ time_of()

real_t bitsim::distributed::Synchroniser::time_of ( uint_t step) const
inlinenoexcept

The documentation for this class was generated from the following files: