$darkmode
cloe::Vehicle Class Reference

#include <vehicle.hpp>

Inheritance diagram for cloe::Vehicle:
Collaboration diagram for cloe::Vehicle:

Public Member Functions

 Vehicle (uint64_t id, const std::string &name)
 
std::shared_ptr< Vehicleclone (uint64_t id, const std::string &name)
 
uint64_t id () const
 
size_t size () const
 
bool has (const std::string &key) const
 
template<typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
bool has (Enum c) const
 
template<typename T >
std::shared_ptr< const T > get (const std::string &key) const
 
template<typename T >
std::shared_ptr< T > get (const std::string &key)
 
template<typename T , typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
std::shared_ptr< const T > get (Enum c) const
 
template<typename T , typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
std::shared_ptr< T > get (Enum c)
 
template<typename... Arguments>
void new_component (Component *ptr, const Arguments &... aliases)
 
template<typename First , typename... Arguments>
void add_component (std::shared_ptr< Component > sp, const First &alias, const Arguments &... aliases)
 
template<typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
void add_component (std::shared_ptr< Component > sp, Enum c)
 
void add_component (std::shared_ptr< Component > sp, const std::string &alias)
 
template<typename First , typename... Arguments>
void emplace_component (std::shared_ptr< Component > sp, const First &alias, const Arguments &... aliases)
 
template<typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
void emplace_component (std::shared_ptr< Component > sp, Enum c)
 
void emplace_component (std::shared_ptr< Component > sp, const std::string &alias)
 
void set_component (const std::string &key, std::shared_ptr< Component > component)
 
Duration process (const Sync &sync) override
 
void connect () override
 
void disconnect () override
 
void enroll (Registrar &r) override
 
void reset () override
 
void abort () override
 
- Public Member Functions inherited from cloe::Model
virtual ~Model () noexcept=default
 
virtual Duration resolution () const
 
virtual bool is_connected () const
 
virtual bool is_operational () const
 
virtual void start (const Sync &)
 
virtual void pause (const Sync &)
 
virtual void resume (const Sync &)
 
virtual void stop (const Sync &)
 
 Entity (std::string name)
 
 Entity (std::string name, std::string desc)
 
- Public Member Functions inherited from cloe::Entity
 Entity (std::string name)
 
 Entity (std::string name, std::string desc)
 
const std::string & name () const
 
void set_name (std::string name)
 
const std::string & description () const
 
void set_description (std::string desc)
 

Protected Member Functions

std::shared_ptr< const Componentat (const std::string &key) const
 
std::shared_ptr< Componentat (const std::string &key)
 
- Protected Member Functions inherited from cloe::Entity
virtual Logger logger () const
 

Friends

void to_json (Json &j, const Vehicle &v)
 

Additional Inherited Members

- Protected Attributes inherited from cloe::Model
bool connected_ {false}
 
bool operational_ {false}
 
- Protected Attributes inherited from cloe::Entity
std::string name_
 
std::string desc_
 

Detailed Description

A Vehicle is a collection of sensor and actuator components.

Some of the components are sensors, and some are actuators. From the perspective of a controller, a sensor can be thought of as a read-only device, while an actuator can be thought of as a read-write device. The simulator will have a reversed perspectice, as it supplies data to or through sensor components and reads from actuators.

The initial set of components that are part of a Vehicle are supplied by a simulator. A simulator binding may derive from the Vehicle class and provide its own components that are (encouraged to derive from Cloe standard) sensors and actuators.

Through runtime configuration, the initial set of components may be extended or modified. It is therefore important that simulator bindings maintain an internal list of components which are read and written.

Member Function Documentation

◆ abort()

void cloe::Vehicle::abort ( )
overridevirtual

Signal an abort to model processing.

This method is called asynchronously. It is highly recommended to make use of a std::atomic_bool for purposes of making the abortion request known to other parts of the model. This method is called when the user requests the simulation to be aborted, e.g., by sending the SIGINT signal.

An abort will be followed by a stop if the simulation was started.

The default implementation will throw an error. This will be caught and possibly ignored. Otherwise, the simulation will be killed.

See also
cloe/core/abort.hpp

Reimplemented from cloe::Model.

◆ at()

std::shared_ptr< const Component > cloe::Vehicle::at ( const std::string &  key) const
protected

Return the component with the given name or throw an Error that is actually helpful.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clone()

std::shared_ptr< Vehicle > cloe::Vehicle::clone ( uint64_t  id,
const std::string &  name 
)

Return a clone of a vehicle with the given ID and name.

This retains all the components that the vehicle has and allows the cloned vehicle to be modified without affecting the original vehicle.

Here is the call graph for this function:

◆ connect()

void cloe::Vehicle::connect ( )
overridevirtual

Initiate a connection to the model, including any initialization.

  • It should block until the connection is successfully established.
  • It should throw an exception if an unrecoverable error occurs.
  • It should react to an abort() called on the model.
  • It may throw an error if already connected.

After a successful connection, the following methods shall be callable:

When implementing this method, e.g. via override or final, make sure to call this method:

void MySuperModel::connect() final { // Your connection code Model::connect(); }

Reimplemented from cloe::Model.

Here is the call graph for this function:

◆ disconnect()

void cloe::Vehicle::disconnect ( )
overridevirtual

Tear down the connection to the model.

  • It should block until the connection is successfully closed.
  • It should throw an exception if an unrecoverable error occurs.
  • It should not throw an exception if called when not connected.

After successful disconnection, it is not expected that the model should be able to connect again.

When implementing this method, e.g. via override or final, make sure to call this method:

void MySuperModel::disconnect() final { // Your disconnection code Model::disconnect(); }

Reimplemented from cloe::Model.

Here is the call graph for this function:

◆ enroll()

void cloe::Vehicle::enroll ( Registrar )
overridevirtual

Register any events, actions, or handlers with the registrar.

  • This may exhibit different behavior when called in a disconnected state, in order to provide the possibility for verification of triggers in offline mode.
  • It may throw an exception.

Reimplemented from cloe::Model.

Here is the call graph for this function:

◆ get() [1/2]

template<typename T >
std::shared_ptr<const T> cloe::Vehicle::get ( const std::string &  key) const
inline

Return the component associated with the key.

This may throw one of:

Here is the call graph for this function:

◆ get() [2/2]

template<typename T , typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
std::shared_ptr<const T> cloe::Vehicle::get ( Enum  c) const
inline

Return the component associated with the enum value.

Under-the-hood, the enum is translated to a string, which is used to fetch the correct component.

◆ has() [1/2]

bool cloe::Vehicle::has ( const std::string &  key) const
inline

Return whether the vehicle has a component with the given name.

Here is the caller graph for this function:

◆ has() [2/2]

template<typename Enum , std::enable_if_t< std::is_enum< Enum >::value, int > = 0>
bool cloe::Vehicle::has ( Enum  c) const
inline

Return whether the vehicle has the component as identified by the enum value.

Here is the call graph for this function:

◆ process()

Duration cloe::Vehicle::process ( const Sync sync)
overridevirtual

Process all components.

This primarily consists of clearing the cache and updating internal state.

Note

This may occur multiple times for each component, even if a component only exists once in a vehicle. For example, if a component exists in a vehicle, but then is wrapped by two different filters; the original sensor may not be directly reachable, but two different components will update it.

Implements cloe::Model.

Here is the call graph for this function:

◆ reset()

void cloe::Vehicle::reset ( )
overridevirtual

Reset the model state.

This is called when Cloe is asked to reset the whole simulation to time 0. This can be the case when the simulator or a controller asks us to recover from a temporary problem without repeating the whole simulation setup.

The default implementation will raise an error. So if your model is not able to re-initialize, the simulation will be aborted.

Reimplemented from cloe::Model.

◆ size()

size_t cloe::Vehicle::size ( ) const
inline

Return the number of components in the vehicle.


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