$darkmode
cloe::Simulator Class Referenceabstract

#include <simulator.hpp>

Inheritance diagram for cloe::Simulator:
Collaboration diagram for cloe::Simulator:

Public Member Functions

virtual size_t num_vehicles () const =0
 
virtual std::shared_ptr< Vehicleget_vehicle (size_t i) const =0
 
virtual std::shared_ptr< Vehicleget_vehicle (const std::string &key) const =0
 
Duration process (const Sync &) override=0
 
- 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 connect ()
 
virtual void disconnect ()
 
virtual void enroll (Registrar &)
 
virtual void start (const Sync &)
 
virtual void pause (const Sync &)
 
virtual void resume (const Sync &)
 
virtual void stop (const Sync &)
 
virtual void reset ()
 
virtual void abort ()
 
 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)
 

Additional Inherited Members

- Protected Member Functions inherited from cloe::Entity
virtual Logger logger () const
 
- 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

The Simulator interface provides a model of the world.

This class binds Cloe to the a simulator, such as VTD or Minimator. In particular, it...

  • provides access to available vehicles
  • updates the vehicle's sensed state and world
  • sends vehicle actuation to the simulator
  • keeps the simulator synchronized

A Simulator is not expected to survive for more than one simulation. However, it should be able to connect and disconnect to a simulation, so that more than one Simulator instance can exist at any point in time.

Inherited Methods

Make sure to implement the following methods from the Model interface:

See the documentation for the Model class for information on when these methods are called in a simulation.

The majority of the step-for-step work occurs in the process method. After each simulator binding has processed, the vehicles will be processed. Since under-the-hood, each vehicle is provided by one of the simulators, consider that vehicle-specific work does not need to be done in the simulator process method.

See also
cloe/model.hpp

Special Methods

The following methods are specific to the Simulator interface:

Member Function Documentation

◆ get_vehicle() [1/2]

virtual std::shared_ptr<Vehicle> cloe::Simulator::get_vehicle ( const std::string &  key) const
pure virtual

Return a pointer to a Vehicle.

  • If a vehicle does not exist with the key, nullptr is returned.
  • Same conditions apply as for get_vehicle(size_t).

Implemented in cloe::simulator::NopSimulator, minimator::MinimatorSimulator, and vtd::VtdBinding.

◆ get_vehicle() [2/2]

virtual std::shared_ptr<Vehicle> cloe::Simulator::get_vehicle ( size_t  i) const
pure virtual

Return a pointer to a Vehicle.

  • The argument i should be between [0, n), where n = num_vehicles().
  • If a vehicle index is accessed that is out-of-bounds, behaviour is undefined.
  • The simulator binding must manage the memory of the Vehicle.
  • The pointer to the vehicle is guaranteed to be valid for the duration of the simulation.
  • After the simulation has disconnected, the pointer is no longer guaranteed to be valid.
  • The vehicle may be modified and these modifications will be preserved for the validity of the pointer. In particular, the sensor and actuator interfaces may be replaced by proxies.

Implemented in cloe::simulator::NopSimulator, minimator::MinimatorSimulator, and vtd::VtdBinding.

◆ num_vehicles()

virtual size_t cloe::Simulator::num_vehicles ( ) const
pure virtual

Return the number of vehicles that the simulator binding has access to.

  • It may throw an exception or return 0 if the simulator is not connected.

Implemented in cloe::simulator::NopSimulator, minimator::MinimatorSimulator, and vtd::VtdBinding.

◆ process()

Duration cloe::Simulator::process ( const Sync )
overridepure virtual

Send vehicle actuations to the simulator and retrieve the new world state.

  1. For each vehicle, actuation is sent first, to make clear that these actuations are based on the sensor information from the previous step. The new world state, at the time point where the actuations are sent is then retrieved and made available to each vehicle. Essentially, they are sent and received in parallel.
  2. The simulator is instructed to complete the next simulation cycle, if possible asynchronously.
  • This function can throw an exception, which causes the simulation to be aborted.
See also
Model::process

Implements cloe::Model.

Implemented in cloe::simulator::NopSimulator, minimator::MinimatorSimulator, and vtd::VtdBinding.


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