34 const std::string Component::defaultName =
"LaserScannerTimestampTest";
43 properties.topicName,
"TopicName",
"Name of the laserscanner topic to report to.");
45 def->component(laserScanUnitListenerPrx);
48 def->optional(properties.useTopic,
"useTopic",
"If enabled, will send data via topic.");
50 def->required(properties.frame,
"frame",
"Coordinate frame of the laserscanner.");
52 def->required(properties.freq,
54 "Default frequency of newly generated and published laser scans [Hz]");
59 "Smallest allowed offset of wrong timestamps [ms]. May be negative. Offset for wrong "
60 "generated timestamp randomly chosen from interval [minOffset,maxOffset]");
64 "Greatest allowed offset of wrong timestamps [ms]. May be negative. Offset for wrong "
65 "generated timestamp randomly chosen from interval [minOffset,maxOffset]");
68 properties.correctBatchSize,
69 "MaxCorrectBatchSize",
70 "Maximum size of consecutive generated correct timestamps. Batch size of correct "
71 "timestamps is randomly chosen from interval [1,MaxCorrectBatchSize]");
72 def->required(properties.wrongBatchSize,
74 "Maximum size of consecutive generated wrong timestamps. Batch size of wrong "
75 "timestamps is randomly chosen from interval [1,MaxWrongBatchSize");
85 if (properties.min >= properties.max)
87 ARMARX_ERROR <<
"following statement should be false but is not: min >= max";
90 if (properties.correctBatchSize < 1)
92 ARMARX_ERROR <<
"following statement should be false but is not: correctBatchSize < 1";
95 if (properties.wrongBatchSize < 1)
97 ARMARX_ERROR <<
"following statement should be false but is not: wrongBatchSize < 1";
101 if (properties.useTopic)
112 if (properties.useTopic)
114 getTopic(laserScanUnitListenerTopic, properties.topicName);
126 int scansUntilToggle = randInRange(1, properties.correctBatchSize);
127 bool correctScans =
true;
132 constexpr std::size_t nSamples = 1000;
134 armarx::LaserScan scanData;
135 for (std::size_t i = 0; i < nSamples; i++)
137 scanData.emplace_back(armarx::LaserScanStep{2 *
M_PI / nSamples, 2500.0F, 1.0f});
143 armarx::Duration scanOffset =
145 scanTime += scanOffset;
152 if (laserScanUnitListenerTopic)
154 laserScanUnitListenerTopic->reportSensorValues(
155 properties.frame, properties.frame, scanData, scanT);
164 if (scansUntilToggle <= 0)
168 scansUntilToggle = randInRange(1, properties.wrongBatchSize);
173 scansUntilToggle = randInRange(1, properties.correctBatchSize);
176 correctScans = !correctScans;
179 metronome.waitForNextTick();
184 Component::randInRange(
int min,
int max)
186 int size = (
max + 1) -
min;
187 int rand = std::rand();
189 return (rand % size) +
min;
206 return Component::defaultName;
212 return Component::defaultName;
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
static std::string GetDefaultName()
Get the component's default name.
void onExitComponent() override
std::string getDefaultName() const override
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
static Frequency Hertz(std::int64_t hertz)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
This file is part of ArmarX.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr