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 
37 #include <RobotAPI/interface/core/RobotState.h>
39 #include <RobotAPI/interface/units/LaserScannerUnit.h>
40 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
41 
43 
44 #include "OccupancyGrid.h"
45 #include "ArVizDrawer.h"
46 
47 namespace armarx
48 {
49  class Throttler;
50 }
51 
53 {
54 
55  /**
56  * @class LaserScannerSimulationPropertyDefinitions
57  * @brief
58  */
61  {
62  public:
65  {
66  defineOptionalProperty<std::string>("LaserScannerTopicName", "LaserScans", "Name of the laser scan topic.");
67  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the RobotStateComponent to use.");
68  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Visualize the results here.");
69  defineOptionalProperty<std::string>("ReportVisuTopicName", "SimulatorVisuUpdates", "The topic on which the visualization updates are published.");
70 
71  defineOptionalProperty<bool>("TopicReplayerDummy", false, "Enable to serve the purpose of a topic replayer dummy");
72  defineOptionalProperty<int>("UpdatePeriod", 25, "Update period for laser scans in ms");
73  defineOptionalProperty<int>("VisuUpdateFrequency", 10, "Visualization update frequency (Hz) for laser scans");
74  defineOptionalProperty<float>("GridCellSize", 20.0f, "Size of the grid cells used to generate the occupancy map in mm");
75  defineOptionalProperty<std::string>("Frames", "LaserScanner_1", "Name of the frames to attach the sensor to (e.g. Node1,Node2,Node3)");
76  defineOptionalProperty<std::string>("Devices", "127.0.0.1", "Name of the devices to simulate (e.g. Device1,Device2,Device3)");
77  defineOptionalProperty<std::string>("MinAngles", std::to_string(-M_PI), "Minumum angles to be reported in rad (e.g -2.35,-1.27,0)");
78  defineOptionalProperty<std::string>("MaxAngles", std::to_string(M_PI), "Maxiumum angles to be reported in rad (e.g 2.35,1.27,3.14)");
79  defineOptionalProperty<std::string>("Steps", "1081", "Number of single steps (angle, distance) per scan (e.g 1081,360,270)");
80  defineOptionalProperty<std::string>("NoiseStdDev", "40.0", "Noise is added to the distance of single steps (e.g 40,30,20)");
81  defineOptionalProperty<bool>("visualization.enable", false, "If enabled, useful information will be visualized in ArViz");
82  }
83  };
84 
86  {
87  std::string frame;
88  float minAngle;
89  float maxAngle;
90  float noiseStdDev;
91  int steps;
92  SharedRobotNodeInterfacePrx frameNode;
93  };
94 
96  {
97  float originX;
98  float originY;
99  std::size_t sizeX;
100  std::size_t sizeY;
101  };
102 
103  /**
104  * @defgroup Component-LaserScannerSimulation LaserScannerSimulation
105  * @ingroup ArmarXSimulation-Components
106  * A description of the component LaserScannerSimulation.
107  *
108  * @class LaserScannerSimulation
109  * @ingroup Component-LaserScannerSimulation
110  * @brief Brief description of class LaserScannerSimulation.
111  *
112  * Detailed description of class LaserScannerSimulation.
113  */
115  virtual public armarx::SensorActorUnit,
116  virtual public armarx::LaserScannerUnitInterface,
117  virtual public armarx::ArVizComponentPluginUser
118  {
119  public:
120  /**
121  * @see armarx::ManagedIceObject::getDefaultName()
122  */
123  std::string getDefaultName() const override
124  {
125  return "LaserScannerSimulation";
126  }
127 
128  virtual ~LaserScannerSimulation() override;
129 
130  protected:
131  /**
132  * @see armarx::ManagedIceObject::onInitComponent()
133  */
134  void onInitComponent() override;
135 
136  /**
137  * @see armarx::ManagedIceObject::onConnectComponent()
138  */
139  void onConnectComponent() override;
140 
141  /**
142  * @see armarx::ManagedIceObject::onDisconnectComponent()
143  */
144  void onDisconnectComponent() override;
145 
146  /**
147  * @see armarx::ManagedIceObject::onExitComponent()
148  */
149  void onExitComponent() override;
150 
151  /**
152  * @see PropertyUser::createPropertyDefinitions()
153  */
155 
156  std::string getReportTopicName(const Ice::Current&) const override;
157 
158  LaserScannerInfoSeq getConnectedDevices(const Ice::Current&) const override;
159 
160  private:
161  void updateScanData();
162 
163  void fillOccupancyGrid(std::vector<VirtualRobot::SceneObjectPtr> const& sceneObjects);
164 
165  GridDimension calculateGridDimension(VirtualRobot::SceneObjectSetPtr const& objects) const;
166  GridDimension calculateGridDimension(const std::vector<VirtualRobot::BoundingBox>& boundingBoxes) const;
167  GridDimension calculateGridDimension(const std::vector<VirtualRobot::SceneObjectPtr>& sceneObjects) const;
168 
169  VirtualRobot::SceneObjectSetPtr getCollisionObjects(const std::vector<VirtualRobot::SceneObjectPtr>& sceneObjects) const;
170 
171  std::vector<VirtualRobot::BoundingBox> boundingBoxes(VirtualRobot::SceneObjectSetPtr const& objects) const;
172 
173  std::string topicName;
174  LaserScannerUnitListenerPrx topic;
175  std::string robotStateName;
178  std::string debugDrawerName;
180 
182 
183  bool topicReplayerDummy = false;
184  int updatePeriod = 25;
185  float gridCellSize = 20.0f;
186  int visuUpdateFrequency = 10;
187 
188  bool enableVisualization{false};
189 
190  float boxPosZ = 50.0f; // sensor height
191 
192  std::vector<LaserScannerSimUnit> scanners;
194 
195  OccupancyGrid grid;
196  std::mt19937 engine;
197 
198  LaserScannerInfoSeq connectedDevices;
199 
200  std::unique_ptr<ArVizDrawer> arvizDrawer;
201 
202  std::unique_ptr<Throttler> visuThrottler;
203  };
204 
205 } // namespace armarx::laser_scanner_simulation
206 
ArVizComponentPlugin.h
armarx::armem::vision::OccupancyGrid
Definition: types.h:36
armarx::laser_scanner_simulation::LaserScannerSimulation::onInitComponent
void onInitComponent() override
Definition: LaserScannerSimulation.cpp:248
armarx::laser_scanner_simulation::LaserScannerSimulation
Brief description of class LaserScannerSimulation.
Definition: LaserScannerSimulation.h:114
armarx::laser_scanner_simulation::LaserScannerSimulation::onExitComponent
void onExitComponent() override
Definition: LaserScannerSimulation.cpp:501
armarx::laser_scanner_simulation::LaserScannerSimUnit::minAngle
float minAngle
Definition: LaserScannerSimulation.h:88
ArVizDrawer.h
armarx::laser_scanner_simulation::LaserScannerSimUnit::frame
std::string frame
Definition: LaserScannerSimulation.h:87
armarx::laser_scanner_simulation::LaserScannerSimulationPropertyDefinitions::LaserScannerSimulationPropertyDefinitions
LaserScannerSimulationPropertyDefinitions(std::string prefix)
Definition: LaserScannerSimulation.h:63
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::laser_scanner_simulation::LaserScannerSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LaserScannerSimulation.cpp:510
armarx::laser_scanner_simulation::LaserScannerSimUnit::frameNode
SharedRobotNodeInterfacePrx frameNode
Definition: LaserScannerSimulation.h:92
armarx::laser_scanner_simulation::GridDimension
Definition: LaserScannerSimulation.h:95
armarx::laser_scanner_simulation::GridDimension::originY
float originY
Definition: LaserScannerSimulation.h:98
armarx::laser_scanner_simulation::LaserScannerSimulation::getConnectedDevices
LaserScannerInfoSeq getConnectedDevices(const Ice::Current &) const override
Definition: LaserScannerSimulation.cpp:521
IceInternal::Handle< ArmarXPhysicsWorldVisualization >
armarx::laser_scanner_simulation
Definition: ArVizDrawer.cpp:18
armarx::laser_scanner_simulation::LaserScannerSimUnit::noiseStdDev
float noiseStdDev
Definition: LaserScannerSimulation.h:90
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
ArmarXPhysicsWorldVisualization.h
armarx::laser_scanner_simulation::LaserScannerSimulation::onConnectComponent
void onConnectComponent() override
Definition: LaserScannerSimulation.cpp:370
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:123
armarx::laser_scanner_simulation::GridDimension::originX
float originX
Definition: LaserScannerSimulation.h:97
OccupancyGrid.h
Throttler.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::laser_scanner_simulation::GridDimension::sizeX
std::size_t sizeX
Definition: LaserScannerSimulation.h:99
armarx::laser_scanner_simulation::LaserScannerSimulation::getReportTopicName
std::string getReportTopicName(const Ice::Current &) const override
Definition: LaserScannerSimulation.cpp:516
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::laser_scanner_simulation::LaserScannerSimulation::onDisconnectComponent
void onDisconnectComponent() override
Definition: LaserScannerSimulation.cpp:492
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::SensorActorUnit
Base Class for SensorActorUnits.
Definition: SensorActorUnit.h:42
armarx::laser_scanner_simulation::LaserScannerSimUnit
Definition: LaserScannerSimulation.h:85
armarx::laser_scanner_simulation::LaserScannerSimUnit::steps
int steps
Definition: LaserScannerSimulation.h:91
armarx::laser_scanner_simulation::LaserScannerSimulation::~LaserScannerSimulation
virtual ~LaserScannerSimulation() override
armarx::laser_scanner_simulation::GridDimension::sizeY
std::size_t sizeY
Definition: LaserScannerSimulation.h:100
armarx::laser_scanner_simulation::LaserScannerSimUnit::maxAngle
float maxAngle
Definition: LaserScannerSimulation.h:89
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28