$darkmode
vtd::VtdBinding Class Reference
Inheritance diagram for vtd::VtdBinding:
Collaboration diagram for vtd::VtdBinding:

Public Member Functions

 VtdBinding (const std::string &name, const VtdConfiguration &config)
 
void abort () final
 
void connect () final
 
void disconnect () final
 
void connect_and_configure (size_t)
 
void enroll (cloe::Registrar &r) final
 
void clear ()
 
void reset () final
 
size_t num_vehicles () const final
 
std::shared_ptr< cloe::Vehicleget_vehicle (size_t i) const final
 
std::shared_ptr< cloe::Vehicleget_vehicle (const std::string &key) const final
 
void start (const cloe::Sync &) final
 
cloe::Duration process (const cloe::Sync &sync) final
 
void stop (const cloe::Sync &) final
 
- 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 pause (const Sync &)
 
virtual void resume (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< VtdVehicleget_vehicle_by_id (uint64_t id) const
 
std::shared_ptr< VtdVehicleget_vehicle_by_name (const std::string &name) const
 
void init_camera_position (const std::string &name)
 
void readall_scp ()
 
void scp_try_read_until (std::function< bool(void)> pred)
 
void apply_scp (const std::string &scp_message)
 
void apply_scp_rdb (boost::property_tree::ptree &xml)
 
void apply_scp_set (boost::property_tree::ptree &xml)
 
void apply_scp_init_done (boost::property_tree::ptree &xml)
 
void apply_scp_run (boost::property_tree::ptree &)
 
void apply_scp_restart (boost::property_tree::ptree &)
 
void apply_scp_stop (boost::property_tree::ptree &)
 
void apply_scenario_filename (boost::property_tree::ptree &xml)
 
void apply_scp_scenario_response (boost::property_tree::ptree &xml)
 
fs::path relative_scenario_path (const fs::path &p)
 
- Protected Member Functions inherited from cloe::Entity
virtual Logger logger () const
 

Friends

void to_json (cloe::Json &j, const VtdBinding &b)
 

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_
 

Member Function Documentation

◆ abort()

void vtd::VtdBinding::abort ( )
inlinefinalvirtual

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.

◆ apply_scp()

void vtd::VtdBinding::apply_scp ( const std::string &  scp_message)
inlineprotected

Parse selected VTD SCP messages and call the relevant apply methods.

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

◆ apply_scp_set()

void vtd::VtdBinding::apply_scp_set ( boost::property_tree::ptree &  xml)
inlineprotected

Create a new vehicle if one with the given ID does not already exist.

We get this before "SimCtrl.Run" arrives. However, users may use the Set command, and therefore these are only processed while VTD is not running.

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

◆ clear()

void vtd::VtdBinding::clear ( )
inline

Clear internal data-structures so that we can configure() again.

Here is the caller graph for this function:

◆ connect()

void vtd::VtdBinding::connect ( )
inlinefinalvirtual

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:

  • enroll(Registrar&)
  • start(const Sync&)

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:

◆ connect_and_configure()

void vtd::VtdBinding::connect_and_configure ( size_t  )
inline

Connect to and configure VTD.

Reads SCP bus and collects VTD state information until VTD initialization is completed.

Here is the caller graph for this function:

◆ disconnect()

void vtd::VtdBinding::disconnect ( )
inlinefinalvirtual

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:
Here is the caller graph for this function:

◆ enroll()

void vtd::VtdBinding::enroll ( cloe::Registrar )
inlinefinalvirtual

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.

◆ get_vehicle() [1/2]

std::shared_ptr<cloe::Vehicle> vtd::VtdBinding::get_vehicle ( const std::string &  key) const
inlinefinalvirtual

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

Implements cloe::Simulator.

Here is the call graph for this function:

◆ get_vehicle() [2/2]

std::shared_ptr<cloe::Vehicle> vtd::VtdBinding::get_vehicle ( size_t  i) const
inlinefinalvirtual

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.

Implements cloe::Simulator.

◆ get_vehicle_by_name()

std::shared_ptr<VtdVehicle> vtd::VtdBinding::get_vehicle_by_name ( const std::string &  name) const
inlineprotected

Return a VtdVehicle with the given name, or nullptr if it doesn't exist.

Thus, this function can be used to also check if a vehicle has a particular name:

if (this->get_vtd_vehicle(name)) { // ... }

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

◆ init_camera_position()

void vtd::VtdBinding::init_camera_position ( const std::string &  name)
inlineprotected

Set the initial camera position on the vehicle with the given name.

Here is the call graph for this function:

◆ num_vehicles()

size_t vtd::VtdBinding::num_vehicles ( ) const
inlinefinalvirtual

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.

Implements cloe::Simulator.

◆ process()

cloe::Duration vtd::VtdBinding::process ( const cloe::Sync sync)
inlinefinalvirtual

Synchronize with VTD and trigger the next VTD frame calculation.

It performs the following steps:

  • It sends vehicle actuations.
  • It retrieves the new world state.
  • It updates the vehicles.
  • It triggers VTD to perform the next frame calculation.

Implements cloe::Simulator.

Here is the call graph for this function:

◆ readall_scp()

void vtd::VtdBinding::readall_scp ( )
inlineprotected

Read as many SCP messages as the client currently has in the buffer and apply them, one after another.

This can result in pretty much any change in the binding, including:

  • Starting, stopping, resetting the binding
  • Creating vehicles

Note: currently there is no need to read a "single" scp message, so there is no read_scp function anymore.

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

◆ reset()

void vtd::VtdBinding::reset ( )
inlinefinalvirtual

Restart VTD and reset the essential parts of the binding.

This is not a true reset as some state VTD will remain (e.g. sensor configuration). But the simulation time together with all objects of the scenario will start over from 0.

Reimplemented from cloe::Model.

◆ start()

void vtd::VtdBinding::start ( const cloe::Sync )
inlinefinalvirtual

Perform model setup for the simulation.

The passed Sync interface should return a step and time of zero.

  • This will be called once per simulation, before process(const Sync&) is called.
  • It may throw an exception.
  • Method is_operational() should return true after this.

Reimplemented from cloe::Model.

◆ stop()

void vtd::VtdBinding::stop ( const cloe::Sync )
inlinefinalvirtual

Perform final work that may throw an exception.

This is called after the last process call when the simulation is through. It is possible after a call to stop, that a reset will be called, followed by a further start. Nominally, however, it will be followed by a disconnect.

Reimplemented from cloe::Model.


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