LaserScannerSimulation.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXSimulation::ArmarXObjects::LaserScannerSimulation
17 * @author Fabian Paus ( fabian dot paus at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <cmath>
26#include <random>
27#include <string>
28
29#include <Eigen/Eigen>
30
31#include <VirtualRobot/VirtualRobot.h>
32
35
38#include <RobotAPI/interface/core/RobotState.h>
39#include <RobotAPI/interface/units/LaserScannerUnit.h>
40#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
41
43
44#include "ArVizDrawer.h"
45#include "OccupancyGrid.h"
46
47namespace armarx
48{
49 class Throttler;
50}
51
53{
54
55 /**
56 * @class LaserScannerSimulationPropertyDefinitions
57 * @brief
58 */
60 {
61 public:
64 {
66 "LaserScannerTopicName", "LaserScans", "Name of the laser scan topic.");
67 defineOptionalProperty<std::string>("RobotStateComponentName",
68 "RobotStateComponent",
69 "Name of the RobotStateComponent to use.");
71 "DebugDrawerTopicName", "DebugDrawerUpdates", "Visualize the results here.");
73 "ReportVisuTopicName",
74 "SimulatorVisuUpdates",
75 "The topic on which the visualization updates are published.");
76
77 defineOptionalProperty<bool>("TopicReplayerDummy",
78 false,
79 "Enable to serve the purpose of a topic replayer dummy");
80 defineOptionalProperty<int>("UpdatePeriod", 25, "Update period for laser scans in ms");
82 "VisuUpdateFrequency", 10, "Visualization update frequency (Hz) for laser scans");
84 "GridCellSize",
85 20.0f,
86 "Size of the grid cells used to generate the occupancy map in mm");
88 "Frames",
89 "LaserScanner_1",
90 "Name of the frames to attach the sensor to (e.g. Node1,Node2,Node3)");
92 "Devices",
93 "127.0.0.1",
94 "Name of the devices to simulate (e.g. Device1,Device2,Device3)");
96 "MinAngles",
97 std::to_string(-M_PI),
98 "Minumum angles to be reported in rad (e.g -2.35,-1.27,0)");
100 "MaxAngles",
101 std::to_string(M_PI),
102 "Maxiumum angles to be reported in rad (e.g 2.35,1.27,3.14)");
104 "Steps",
105 "1081",
106 "Number of single steps (angle, distance) per scan (e.g 1081,360,270)");
108 "NoiseStdDev",
109 "40.0",
110 "Noise is added to the distance of single steps (e.g 40,30,20)");
112 "visualization.enable",
113 false,
114 "If enabled, useful information will be visualized in ArViz");
115 }
116 };
117
119 {
120 std::string frame;
121 float minAngle;
122 float maxAngle;
124 int steps;
125 SharedRobotNodeInterfacePrx frameNode;
126 };
127
129 {
130 float originX;
131 float originY;
132 std::size_t sizeX;
133 std::size_t sizeY;
134 };
135
136 /**
137 * @defgroup Component-LaserScannerSimulation LaserScannerSimulation
138 * @ingroup ArmarXSimulation-Components
139 * A description of the component LaserScannerSimulation.
140 *
141 * @class LaserScannerSimulation
142 * @ingroup Component-LaserScannerSimulation
143 * @brief Brief description of class LaserScannerSimulation.
144 *
145 * Detailed description of class LaserScannerSimulation.
146 */
148 virtual public armarx::SensorActorUnit,
149 virtual public armarx::LaserScannerUnitInterface,
151 {
152 public:
153 /**
154 * @see armarx::ManagedIceObject::getDefaultName()
155 */
156 std::string
157 getDefaultName() const override
158 {
159 return "LaserScannerSimulation";
160 }
161
162 virtual ~LaserScannerSimulation() override;
163
164 protected:
165 /**
166 * @see armarx::ManagedIceObject::onInitComponent()
167 */
168 void onInitComponent() override;
169
170 /**
171 * @see armarx::ManagedIceObject::onConnectComponent()
172 */
173 void onConnectComponent() override;
174
175 /**
176 * @see armarx::ManagedIceObject::onDisconnectComponent()
177 */
178 void onDisconnectComponent() override;
179
180 /**
181 * @see armarx::ManagedIceObject::onExitComponent()
182 */
183 void onExitComponent() override;
184
185 /**
186 * @see PropertyUser::createPropertyDefinitions()
187 */
189
190 std::string getReportTopicName(const Ice::Current&) const override;
191
192 LaserScannerInfoSeq getConnectedDevices(const Ice::Current&) const override;
193
194 private:
195 void updateScanData();
196
197 void fillOccupancyGrid(std::vector<VirtualRobot::SceneObjectPtr> const& sceneObjects);
198
199 GridDimension calculateGridDimension(VirtualRobot::SceneObjectSetPtr const& objects) const;
201 calculateGridDimension(const std::vector<VirtualRobot::BoundingBox>& boundingBoxes) const;
203 calculateGridDimension(const std::vector<VirtualRobot::SceneObjectPtr>& sceneObjects) const;
204
205 VirtualRobot::SceneObjectSetPtr
206 getCollisionObjects(const std::vector<VirtualRobot::SceneObjectPtr>& sceneObjects) const;
207
208 std::vector<VirtualRobot::BoundingBox>
209 boundingBoxes(VirtualRobot::SceneObjectSetPtr const& objects) const;
210
211 std::string topicName;
212 LaserScannerUnitListenerPrx topic;
213 std::string robotStateName;
216 std::string debugDrawerName;
218
220
221 bool topicReplayerDummy = false;
222 int updatePeriod = 25;
223 float gridCellSize = 20.0f;
224 int visuUpdateFrequency = 10;
225
226 bool enableVisualization{false};
227
228 float boxPosZ = 50.0f; // sensor height
229
230 std::vector<LaserScannerSimUnit> scanners;
232
233 OccupancyGrid grid;
234 std::mt19937 engine;
235
236 LaserScannerInfoSeq connectedDevices;
237
238 std::unique_ptr<ArVizDrawer> arvizDrawer;
239
240 std::unique_ptr<Throttler> visuThrottler;
241 };
242
243} // namespace armarx::laser_scanner_simulation
#define M_PI
Definition MathTools.h:17
Provides a ready-to-use ArViz client arviz as member variable.
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Base Class for SensorActorUnits.
The Throttler class.
Definition Throttler.h:35
Brief description of class LaserScannerSimulation.
std::string getReportTopicName(const Ice::Current &) const override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
LaserScannerInfoSeq getConnectedDevices(const Ice::Current &) const override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< ArmarXPhysicsWorldVisualization > ArmarXPhysicsWorldVisualizationPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx