FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SampledSensor.h
1#pragma once
2
11#include "SampleClock.h"
12#include "SensorFrame.h"
13#include "SensorNoise.h"
14
15#include <fhsim/simobject/SimObject.h>
16#include <string>
17
18class PrintDuringExec;
19
20namespace environment
21{
22class EnvironmentProvider;
23}
24
49{
50public:
57 SampledSensor(ISimObjectCreator* creator, std::string kind, std::string name);
58
68 SampledSensor(std::string kind, std::string name, const double mountOffset[3], const double mountDirection[3],
69 double period, unsigned int seed);
70
75 void SetSamplePeriod(double period);
76
78 bool HasPorts() const { return m_hasPorts; }
79
81 unsigned int Seed() const { return m_seed; }
82
89 environment::EnvironmentProvider* SetUpEnvironment(ISimObjectCreator* creator);
90
92 environment::EnvironmentProvider* Environment() const { return m_environment; }
93
102 template<typename Measure>
103 int ForEachDueSample(const double t, Measure&& measure)
104 {
105 int samples = 0;
106 while (m_clock.Due(t)) {
107 measure();
108 samples++;
109 }
110 return samples;
111 }
112
114 const SensorFrame& Frame() const { return m_frame; }
115
117 SensorNoise& Noise() { return m_noise; }
118
120 const SensorNoise& Noise() const { return m_noise; }
121
123 double NextSampleTime() const { return m_clock.NextSampleTime(); }
124
126 const std::string& Name() const { return m_name; }
127
129 std::string Label() const { return m_kind + " '" + m_name + "'"; }
130
132 void Warn(const std::string& text) const;
133
135 void Info(const std::string& text) const;
136
137private:
138 std::string m_kind;
139 std::string m_name;
140 SensorFrame m_frame;
141 SampleClock m_clock;
142 unsigned int m_seed = 0;
143 SensorNoise m_noise;
144 PrintDuringExec* m_print = nullptr;
145 bool m_hasPorts = false;
146
147 environment::EnvironmentProvider* m_environment = nullptr;
148};
Definition SampleClock.h:40
bool Due(const double t)
Definition SampleClock.h:65
double NextSampleTime() const
The time at which the next sample is due, s.
Definition SampleClock.h:76
Definition SampledSensor.h:49
bool HasPorts() const
True when built by the creator, so the ports exist and the sensor runs.
Definition SampledSensor.h:78
const std::string & Name() const
The name of the owning SimObject.
Definition SampledSensor.h:126
void Warn(const std::string &text) const
Writes a warning to the host logger, if there is one.
unsigned int Seed() const
The random seed; zero is deterministic and noise free.
Definition SampledSensor.h:81
void SetSamplePeriod(double period)
const SensorFrame & Frame() const
The mounting geometry.
Definition SampledSensor.h:114
SampledSensor(ISimObjectCreator *creator, std::string kind, std::string name)
void Info(const std::string &text) const
Writes an information line to the host logger, if there is one.
int ForEachDueSample(const double t, Measure &&measure)
Definition SampledSensor.h:103
std::string Label() const
The message prefix, e.g. "SensorCtd 'Ctd'".
Definition SampledSensor.h:129
environment::EnvironmentProvider * SetUpEnvironment(ISimObjectCreator *creator)
const SensorNoise & Noise() const
The random draws.
Definition SampledSensor.h:120
environment::EnvironmentProvider * Environment() const
The environment found by SetUpEnvironment, or null.
Definition SampledSensor.h:92
SampledSensor(std::string kind, std::string name, const double mountOffset[3], const double mountDirection[3], double period, unsigned int seed)
double NextSampleTime() const
The time of the next sample, s.
Definition SampledSensor.h:123
SensorNoise & Noise()
The random draws.
Definition SampledSensor.h:117
Definition SensorFrame.h:36
Definition SensorNoise.h:39