FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SampledSensor Class Reference

#include <SampledSensor.h>

Public Member Functions

 SampledSensor (ISimObjectCreator *creator, std::string kind, std::string name)
 
 SampledSensor (std::string kind, std::string name, const double mountOffset[3], const double mountDirection[3], double period, unsigned int seed)
 
void SetSamplePeriod (double period)
 
bool HasPorts () const
 True when built by the creator, so the ports exist and the sensor runs.
 
unsigned int Seed () const
 The random seed; zero is deterministic and noise free.
 
environment::EnvironmentProvider * SetUpEnvironment (ISimObjectCreator *creator)
 
environment::EnvironmentProvider * Environment () const
 The environment found by SetUpEnvironment, or null.
 
template<typename Measure >
int ForEachDueSample (const double t, Measure &&measure)
 
const SensorFrame & Frame () const
 The mounting geometry.
 
SensorNoise & Noise ()
 The random draws.
 
const SensorNoise & Noise () const
 The random draws.
 
double NextSampleTime () const
 The time of the next sample, s.
 
const std::string & Name () const
 The name of the owning SimObject.
 
std::string Label () const
 The message prefix, e.g. "SensorCtd 'Ctd'".
 
void Warn (const std::string &text) const
 Writes a warning to the host logger, if there is one.
 
void Info (const std::string &text) const
 Writes an information line to the host logger, if there is one.
 

Detailed Description

Owns what every fixed-rate AUV sensor needs around its measurement.

A sampled sensor is a SimObject that takes a measurement at fixed instants of the accepted simulation time, at a point rigidly mounted on a moving body, with portable random imperfections. The CTD, the SilCam and the echosounder each own one SampledSensor member and supply only the measurement.

The member holds:

  • the SensorFrame (the Pos and Quater inports and the mounting parameters);
  • the SampleClock that decides when a sample is due;
  • the SensorNoise, seeded by the NoiseSeed parameter (FISH-0027);
  • the host logger, null under headless and mock hosts;
  • the shared Environment, found once and only when the sensor has ports.

There are two constructors, as on the sensors. The creator one registers the ports and reads the parameters; it leaves no sample due until SetSamplePeriod, because each sensor reads its rate under its own parameter name. The port-free one exists so the sensors can be unit tested without a host: it has no ports, no logger and no environment.

Note
This is a helper, not a SimObject, so it has no @group block and appears in no model list.

Constructor & Destructor Documentation

◆ SampledSensor() [1/2]

SampledSensor::SampledSensor ( ISimObjectCreator *  creator,
std::string  kind,
std::string  name 
)

Registers the body ports, reads NoiseSeed and finds the host logger.

Parameters
creatorThe creator of the owning SimObject.
kindThe sensor's class name, e.g. "SensorCtd", used in messages.
nameThe name of the owning SimObject.

◆ SampledSensor() [2/2]

SampledSensor::SampledSensor ( std::string  kind,
std::string  name,
const double  mountOffset[3],
const double  mountDirection[3],
double  period,
unsigned int  seed 
)

Constructs a sensor with no ports, for unit tests.

Parameters
kindThe sensor's class name, used in messages.
nameThe name of the owning object.
mountOffsetThe sensor position in the body frame, m.
mountDirectionThe beam direction in the body frame.
periodThe time between samples, s; must be positive.
seedThe random seed; zero is deterministic and noise free.

Member Function Documentation

◆ ForEachDueSample()

template<typename Measure >
int SampledSensor::ForEachDueSample ( const double  t,
Measure &&  measure 
)
inline

Calls measure once for every sample due at time t.

A loop and not an if, so a long accepted step does not silently drop samples.

Parameters
tThe current simulation time, s.
measureTakes one sample; called with no arguments.
Returns
The number of samples taken, which may be zero or more than one.

◆ SetSamplePeriod()

void SampledSensor::SetSamplePeriod ( double  period)

Restarts the clock at time zero with the given period.

Parameters
periodThe time between samples, s; must be positive.

◆ SetUpEnvironment()

environment::EnvironmentProvider * SampledSensor::SetUpEnvironment ( ISimObjectCreator *  creator)

Finds the shared environment once.

Parameters
creatorThe creator of the owning SimObject.
Returns
The environment, or null on the port-free path or when it is missing, in which case FindEnvironment has reported the error.

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