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 
47 namespace armarx
48 {
49  class Throttler;
50 }
51 
53 {
54 
55  /**
56  * @class LaserScannerSimulationPropertyDefinitions
57  * @brief
58  */
60  {
61  public:
64  {
65  defineOptionalProperty<std::string>(
66  "LaserScannerTopicName", "LaserScans", "Name of the laser scan topic.");
67  defineOptionalProperty<std::string>("RobotStateComponentName",
68  "RobotStateComponent",
69  "Name of the RobotStateComponent to use.");
70  defineOptionalProperty<std::string>(
71  "DebugDrawerTopicName", "DebugDrawerUpdates", "Visualize the results here.");
72  defineOptionalProperty<std::string>(
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");
81  defineOptionalProperty<int>(
82  "VisuUpdateFrequency", 10, "Visualization update frequency (Hz) for laser scans");
83  defineOptionalProperty<float>(
84  "GridCellSize",
85  20.0f,
86  "Size of the grid cells used to generate the occupancy map in mm");
87  defineOptionalProperty<std::string>(
88  "Frames",
89  "LaserScanner_1",
90  "Name of the frames to attach the sensor to (e.g. Node1,Node2,Node3)");
91  defineOptionalProperty<std::string>(
92  "Devices",
93  "127.0.0.1",
94  "Name of the devices to simulate (e.g. Device1,Device2,Device3)");
95  defineOptionalProperty<std::string>(
96  "MinAngles",
98  "Minumum angles to be reported in rad (e.g -2.35,-1.27,0)");
99  defineOptionalProperty<std::string>(
100  "MaxAngles",
102  "Maxiumum angles to be reported in rad (e.g 2.35,1.27,3.14)");
103  defineOptionalProperty<std::string>(
104  "Steps",
105  "1081",
106  "Number of single steps (angle, distance) per scan (e.g 1081,360,270)");
107  defineOptionalProperty<std::string>(
108  "NoiseStdDev",
109  "40.0",
110  "Noise is added to the distance of single steps (e.g 40,30,20)");
111  defineOptionalProperty<bool>(
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;
123  float noiseStdDev;
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,
150  virtual public armarx::ArVizComponentPluginUser
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
ArVizComponentPlugin.h
armarx::armem::vision::OccupancyGrid
Definition: types.h:36
armarx::laser_scanner_simulation::LaserScannerSimulation::onInitComponent
void onInitComponent() override
Definition: LaserScannerSimulation.cpp:256
armarx::laser_scanner_simulation::LaserScannerSimulation
Brief description of class LaserScannerSimulation.
Definition: LaserScannerSimulation.h:147
armarx::laser_scanner_simulation::LaserScannerSimulation::onExitComponent
void onExitComponent() override
Definition: LaserScannerSimulation.cpp:514
armarx::laser_scanner_simulation::LaserScannerSimUnit::minAngle
float minAngle
Definition: LaserScannerSimulation.h:121
ArVizDrawer.h
armarx::laser_scanner_simulation::LaserScannerSimUnit::frame
std::string frame
Definition: LaserScannerSimulation.h:120
armarx::laser_scanner_simulation::LaserScannerSimulationPropertyDefinitions::LaserScannerSimulationPropertyDefinitions
LaserScannerSimulationPropertyDefinitions(std::string prefix)
Definition: LaserScannerSimulation.h:62
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
armarx::laser_scanner_simulation::LaserScannerSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LaserScannerSimulation.cpp:524
armarx::laser_scanner_simulation::LaserScannerSimUnit::frameNode
SharedRobotNodeInterfacePrx frameNode
Definition: LaserScannerSimulation.h:125
armarx::laser_scanner_simulation::GridDimension
Definition: LaserScannerSimulation.h:128
armarx::laser_scanner_simulation::GridDimension::originY
float originY
Definition: LaserScannerSimulation.h:131
armarx::laser_scanner_simulation::LaserScannerSimulation::getConnectedDevices
LaserScannerInfoSeq getConnectedDevices(const Ice::Current &) const override
Definition: LaserScannerSimulation.cpp:537
IceInternal::Handle< ArmarXPhysicsWorldVisualization >
armarx::laser_scanner_simulation
Definition: ArVizDrawer.cpp:18
armarx::laser_scanner_simulation::LaserScannerSimUnit::noiseStdDev
float noiseStdDev
Definition: LaserScannerSimulation.h:123
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:35
ArmarXPhysicsWorldVisualization.h
armarx::laser_scanner_simulation::LaserScannerSimulation::onConnectComponent
void onConnectComponent() override
Definition: LaserScannerSimulation.cpp:379
M_PI
#define M_PI
Definition: MathTools.h:17
SensorActorUnit.h
armarx::laser_scanner_simulation::LaserScannerSimulationPropertyDefinitions
Definition: LaserScannerSimulation.h:59
armarx::laser_scanner_simulation::LaserScannerSimulation::getDefaultName
std::string getDefaultName() const override
Definition: LaserScannerSimulation.h:157
armarx::laser_scanner_simulation::GridDimension::originX
float originX
Definition: LaserScannerSimulation.h:130
OccupancyGrid.h
Throttler.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::laser_scanner_simulation::GridDimension::sizeX
std::size_t sizeX
Definition: LaserScannerSimulation.h:132
armarx::laser_scanner_simulation::LaserScannerSimulation::getReportTopicName
std::string getReportTopicName(const Ice::Current &) const override
Definition: LaserScannerSimulation.cpp:531
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::laser_scanner_simulation::LaserScannerSimulation::onDisconnectComponent
void onDisconnectComponent() override
Definition: LaserScannerSimulation.cpp:504
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::SensorActorUnit
Base Class for SensorActorUnits.
Definition: SensorActorUnit.h:43
armarx::laser_scanner_simulation::LaserScannerSimUnit
Definition: LaserScannerSimulation.h:118
armarx::laser_scanner_simulation::LaserScannerSimUnit::steps
int steps
Definition: LaserScannerSimulation.h:124
armarx::laser_scanner_simulation::LaserScannerSimulation::~LaserScannerSimulation
virtual ~LaserScannerSimulation() override
armarx::laser_scanner_simulation::GridDimension::sizeY
std::size_t sizeY
Definition: LaserScannerSimulation.h:133
armarx::laser_scanner_simulation::LaserScannerSimUnit::maxAngle
float maxAngle
Definition: LaserScannerSimulation.h:122
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27