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});
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;