10 #include <mrpt/core/lock_helper.h> 20 using namespace mvsim;
29 m_rangeStdNoise(0.01),
47 const std::map<std::string, std::string> varValues = {
56 params[
"fov_degrees"] =
TParamEntry(
"%lf", &fov_deg);
66 params[
"viz_visiblePlane"] =
68 params[
"viz_visiblePoints"] =
97 m_gl_scan = mrpt::opengl::CPlanarLaserScan::Create();
103 m_gl_scan->setLocalRepresentativePoint({0, 0, 0.10f});
120 const double z_incrs = 10e-3;
121 const double z_offset = 1e-2;
124 p.
x(), p.
y(), z_offset + z_incrs *
m_z_order, p.
phi(), 0.0, 0.0));
150 std::list<CObservation2DRangeScan> lstScans;
164 for (
const auto& element : elements)
170 const COccupancyGridMap2D& occGrid = grid->
getOccGrid();
174 CObservation2DRangeScan& scan = lstScans.back();
188 lstScans.push_back(CObservation2DRangeScan(
m_scan_model));
189 CObservation2DRangeScan& scan = lstScans.back();
192 std::map<b2Fixture*, void*> orgUserData;
194 auto makeFixtureInvisible = [&](
b2Fixture*
f) {
196 orgUserData[
f] =
f->GetUserData();
199 auto undoInvisibleFixtures = [&]() {
200 for (
auto& kv : orgUserData) kv.first->SetUserData(kv.second);
248 RayCastClosestCallback callback;
253 scan.resizeScanAndAssign(nRays, maxRange,
false);
255 sensorPose.
phi() + (scan.rightToLeft ? -0.5 : +0.5) * scan.aperture;
257 (scan.rightToLeft ? 1.0 : -1.0) * (scan.aperture / (nRays - 1));
259 auto& rnd = mrpt::random::getRandomGenerator();
261 for (
size_t i = 0; i < nRays; i++, A += AA)
264 sensorPt.
x + cos(A) * maxRange, sensorPt.
y + sin(A) * maxRange);
266 callback.m_hit =
false;
268 scan.setScanRangeValidity(i, callback.m_hit);
270 float range = scan.getScanRange(i);
275 mrpt::square(callback.m_point.x - sensorPt.
x) +
276 mrpt::square(callback.m_point.y - sensorPt.
y));
284 scan.setScanRange(i, range);
287 undoInvisibleFixtures();
295 auto lastScan = CObservation2DRangeScan::Create(
m_scan_model);
298 lastScan->sensorLabel =
m_name;
300 lastScan->resizeScanAndAssign(nRays, maxRange,
false);
302 for (
const auto& scan : lstScans)
304 for (
size_t i = 0; i < nRays; i++)
306 if (scan.getScanRangeValidity(i))
308 lastScan->setScanRange(
310 std::min(lastScan->getScanRange(i), scan.getScanRange(i)));
311 lastScan->setScanRangeValidity(i,
true);
void resizeScan(const size_t len)
const mrpt::maps::COccupancyGridMap2D & getOccGrid() const
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
b2Fixture * get_fixture_chassis()
mrpt::poses::CPose2D getCPose2D() const
Alternative to getPose()
mrpt::system::TTimeStamp now()
double simul_time
Current time in the simulated world.
std::unique_ptr< b2World > & getBox2DWorld()
LaserScanner(VehicleBase &parent, const rapidxml::xml_node< char > *root)
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
bool parseSensorPublish(const rapidxml::xml_node< char > *node, const std::map< std::string, std::string > &varValues)
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
void insert(const CRenderizablePtr &newObject, const std::string &viewportName=std::string("main"))
const TListSensors & getSensors() const
std::string m_name
sensor label/name
const std::string & getName() const
mrpt::poses::CPose3D sensorPose
VehicleBase & m_vehicle
The vehicle this sensor is attached to.
void reportNewObservation(const std::shared_ptr< mrpt::obs::CObservation > &obs, const TSimulContext &context)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
mrpt::obs::CObservation2DRangeScan m_scan_model
double DEG2RAD(const double x)
const double & phi() const
mrpt::obs::CObservation2DRangeScan::Ptr m_last_scan
virtual void simul_pre_timestep(const TSimulContext &context) override
virtual void internalGuiUpdate(mrpt::opengl::COpenGLScene &scene, bool childrenOnly) override
#define INVISIBLE_FIXTURE_USER_DATA
Used to signal a Box2D fixture as "invisible" to sensors.
virtual void simul_post_timestep(const TSimulContext &context)
virtual void simul_post_timestep(const TSimulContext &context) override
void laserScanSimulator(mrpt::obs::CObservation2DRangeScan &inout_Scan, const mrpt::poses::CPose2D &robotPose, float threshold=0.6f, size_t N=361, float noiseStd=0, unsigned int decimation=1, float angleNoiseStd=mrpt::utils::DEG2RAD(0)) const
const WorldElementList & getListOfWorldElements() const
mrpt::system::CTimeLogger & getTimeLogger()
std::vector< b2Fixture * > & get_fixture_wheels()
mrpt::obs::CObservation2DRangeScan::Ptr m_last_scan2gui
int m_z_order
to help rendering multiple scans
std::list< WorldElementBase::Ptr > WorldElementList
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root) override
double m_sensor_last_timestamp
mrpt::opengl::CPlanarLaserScan::Ptr m_gl_scan
std::mutex m_last_scan_cs
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble f
size_t getScanSize() const
void * GetUserData() const