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
81 void StartClockAt(double tStart);
82
84 bool HasPorts() const { return m_hasPorts; }
85
87 unsigned int Seed() const { return m_seed; }
88
95 environment::EnvironmentProvider* SetUpEnvironment(ISimObjectCreator* creator);
96
98 environment::EnvironmentProvider* Environment() const { return m_environment; }
99
108 template<typename Measure>
109 int ForEachDueSample(const double t, Measure&& measure)
110 {
111 int samples = 0;
112 while (m_clock.Due(t)) {
113 measure();
114 samples++;
115 }
116 return samples;
117 }
118
120 const SensorFrame& Frame() const { return m_frame; }
121
123 SensorNoise& Noise() { return m_noise; }
124
126 const SensorNoise& Noise() const { return m_noise; }
127
129 double NextSampleTime() const { return m_clock.NextSampleTime(); }
130
132 const std::string& Name() const { return m_name; }
133
135 std::string Label() const { return m_kind + " '" + m_name + "'"; }
136
138 void Warn(const std::string& text) const;
139
141 void Info(const std::string& text) const;
142
143private:
144 std::string m_kind;
145 std::string m_name;
146 SensorFrame m_frame;
147 SampleClock m_clock;
148 unsigned int m_seed = 0;
149 SensorNoise m_noise;
150 PrintDuringExec* m_print = nullptr;
151 bool m_hasPorts = false;
152
153 environment::EnvironmentProvider* m_environment = nullptr;
154};
Definition SampleClock.h:43
bool Due(const double t)
Definition SampleClock.h:90
double NextSampleTime() const
The time at which the next sample is due, s.
Definition SampleClock.h:101
Definition SampledSensor.h:49
bool HasPorts() const
True when built by the creator, so the ports exist and the sensor runs.
Definition SampledSensor.h:84
const std::string & Name() const
The name of the owning SimObject.
Definition SampledSensor.h:132
void StartClockAt(double tStart)
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:87
void SetSamplePeriod(double period)
const SensorFrame & Frame() const
The mounting geometry.
Definition SampledSensor.h:120
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:109
std::string Label() const
The message prefix, e.g. "SensorCtd 'Ctd'".
Definition SampledSensor.h:135
environment::EnvironmentProvider * SetUpEnvironment(ISimObjectCreator *creator)
const SensorNoise & Noise() const
The random draws.
Definition SampledSensor.h:126
environment::EnvironmentProvider * Environment() const
The environment found by SetUpEnvironment, or null.
Definition SampledSensor.h:98
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:129
SensorNoise & Noise()
The random draws.
Definition SampledSensor.h:123
Definition SensorFrame.h:36
Definition SensorNoise.h:43