14 #include <mrpt/opengl/COpenGLScene.h> 15 #include <mrpt/random.h> 16 #include <mrpt/version.h> 20 using namespace mvsim;
29 m_rangeStdNoise(0.01),
30 m_angleStdNoise(DEG2RAD(0.01)),
42 std::map<std::string, TParamEntry> attribs;
51 std::map<std::string, TParamEntry> params;
52 params[
"fov_degrees"] =
TParamEntry(
"%lf", &fov_deg);
65 #if MRPT_VERSION >= 0x150 76 m_name = mrpt::format(
"laser%u", static_cast<unsigned int>(nextIdx));
85 m_gl_scan = mrpt::opengl::CPlanarLaserScan::Create();
103 const double z_incrs = 10e-3;
104 const double z_offset = 10e-2;
107 mrpt::poses::CPose3D(
108 p.x(), p.y(), z_offset + z_incrs *
m_z_order, p.phi(), 0.0, 0.0));
123 std::list<CObservation2DRangeScan> lstScans;
137 for (World::TListWorldElements::const_iterator it = elements.begin();
138 it != elements.end(); ++it)
144 const COccupancyGridMap2D& occGrid = grid->
getOccGrid();
147 lstScans.push_back(CObservation2DRangeScan(
m_scan_model));
148 CObservation2DRangeScan& scan = lstScans.back();
151 occGrid.laserScanSimulator(
162 lstScans.push_back(CObservation2DRangeScan(
m_scan_model));
163 CObservation2DRangeScan& scan = lstScans.back();
203 const mrpt::poses::CPose2D sensorPose =
204 vehPose + mrpt::poses::CPose2D(scan.sensorPose);
205 const b2Vec2 sensorPt =
b2Vec2(sensorPose.x(), sensorPose.y());
207 RayCastClosestCallback callback;
212 #if MRPT_VERSION >= 0x150 213 scan.resizeScan(nRays);
215 scan.scan.resize(nRays);
216 scan.validRange.resize(nRays);
219 sensorPose.phi() + (scan.rightToLeft ? -0.5 : +0.5) * scan.aperture;
221 (scan.rightToLeft ? 1.0 : -1.0) * (scan.aperture / (nRays - 1));
224 #if MRPT_VERSION >= 0x199 225 mrpt::random::getRandomGenerator();
227 mrpt::random::randomGenerator;
230 for (
size_t i = 0; i < nRays; i++, A += AA)
233 sensorPt.
x + cos(A) * maxRange, sensorPt.
y + sin(A) * maxRange);
235 callback.m_hit =
false;
237 #if MRPT_VERSION >= 0x150 238 scan.setScanRangeValidity(i, callback.m_hit);
240 scan.validRange[i] = callback.m_hit ? 1 : 0;
243 float range = scan.scan[i];
248 callback.m_point.x - sensorPt.
x,
249 callback.m_point.y - sensorPt.
y);
251 rnd.drawGaussian1D_normalized() *
259 #if MRPT_VERSION >= 0x150 260 scan.setScanRange(i, range);
262 scan.scan[i] = range;
272 CObservation2DRangeScan* lastScan =
274 lastScan->timestamp = mrpt::system::now();
275 lastScan->sensorLabel =
m_name;
277 #if MRPT_VERSION >= 0x150 278 lastScan->resizeScanAndAssign(nRays, maxRange,
false);
280 lastScan->scan.assign(nRays, maxRange);
281 lastScan->validRange.assign(nRays, 0);
284 for (std::list<CObservation2DRangeScan>::const_iterator it =
286 it != lstScans.end(); ++it)
288 ASSERT_(it->scan.size() == nRays && it->validRange.size() == nRays);
290 for (
size_t i = 0; i < nRays; i++)
292 if (it->validRange[i])
294 #if MRPT_VERSION >= 0x150 295 lastScan->setScanRange(
296 i, std::min(lastScan->scan[i], it->scan[i]));
297 lastScan->setScanRangeValidity(i,
true);
299 lastScan->scan[i] = std::min(lastScan->scan[i], it->scan[i]);
300 lastScan->validRange[i] = 1;
309 m_last_scan = CObservation2DRangeScan::Ptr(lastScan);
std::list< WorldElementBase * > TListWorldElements
getListOfVehicles()
double simul_time
Current time in the simulated world.
LaserScanner(VehicleBase &parent, const rapidxml::xml_node< char > *root)
virtual void onNewObservation(const VehicleBase &veh, const mrpt::slam::CObservation *obs)
const TListSensors & getSensors() const
virtual void simul_post_timestep(const TSimulContext &context)
See docs in base class.
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root)
See docs in base class.
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > ¶ms, const char *function_name_context="")
std::string m_name
sensor label/name
CTimeLogger & getTimeLogger()
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > ¶ms, const char *function_name_context="")
void RayCast(b2RayCastCallback *callback, const b2Vec2 &point1, const b2Vec2 &point2) const
VehicleBase & m_vehicle
(in seconds) (Default = 0.1)
#define SCENE_INSERT_Z_ORDER(_SCENE, _ZORDER_INDEX, _OBJ_TO_INSERT)
mrpt::obs::CObservation2DRangeScan::Ptr m_last_scan
Last simulated scan.
#define INVISIBLE_FIXTURE_USER_DATA
Used to signal a Box2D fixture as "invisible" to sensors.
virtual void gui_update(mrpt::opengl::COpenGLScene &scene)
See docs in base class.
CObservation2DRangeScan m_scan_model
or not (Default=true)
const COccupancyGridMap2D & getOccGrid() const
mrpt::obs::CObservation2DRangeScan::Ptr m_last_scan2gui
int m_z_order
to help rendering multiple scans
b2World * getBox2DWorld()
virtual void simul_pre_timestep(const TSimulContext &context)
See docs in base class.
mrpt::poses::CPose2D getCPose2D() const
const TListWorldElements & getListOfWorldElements() const
double m_sensor_last_timestamp
mrpt::opengl::CPlanarLaserScan::Ptr m_gl_scan
call of gui_update() from m_last_scan2gui
std::mutex m_last_scan_cs
void * GetUserData() const