10 #include <mrpt/io/CFileGZInputStream.h> 11 #include <mrpt/maps/CSimplePointsMap.h> 14 #include <mrpt/serialization/CArchive.h> 24 using namespace mvsim;
27 OccupancyGridMap::OccupancyGridMap(
30 m_gui_uptodate(false),
31 m_show_grid_collision_points(true),
33 m_lateral_friction(0.5)
45 if (!xml_file || !xml_file->
value())
46 throw std::runtime_error(
47 "Error: <file></file> XML entry not found inside gridmap node!");
50 const string sFileExt =
54 if (sFileExt ==
"gridmap")
56 mrpt::io::CFileGZInputStream fi(sFile);
57 auto f = mrpt::serialization::archiveFrom(fi);
64 double xcenterpixel = -1, ycenterpixel = -1;
65 double resolution = 0.10;
67 other_params[
"resolution"] =
TParamEntry(
"%lf", &resolution);
68 other_params[
"centerpixel_x"] =
TParamEntry(
"%lf", &xcenterpixel);
69 other_params[
"centerpixel_y"] =
TParamEntry(
"%lf", &ycenterpixel);
74 sFile, resolution, {xcenterpixel, ycenterpixel}))
76 "[OccupancyGridMap] ERROR: File not found '%s'",
83 ps[
"show_collisions"] =
100 m_gl_grid = mrpt::opengl::CSetOfObjects::Create();
123 gl_objs = mrpt::opengl::CSetOfObjects::Create();
124 MRPT_TODO(
"Add a name, and remove old ones in scene, etc.")
148 const size_t nObjs = lstVehs.size() + lstBlocks.size();
152 for (World::VehicleList::const_iterator itVeh = lstVehs.begin();
153 itVeh != lstVehs.end(); ++itVeh, ++obj_idx)
157 itVeh->second->getMaxVehicleRadius() * 1.50f;
163 for (
const auto& block : lstBlocks)
167 block.second->getMaxBlockRadius() * 1.50f;
185 for (
size_t obj_idx = 0; obj_idx < nObjs; obj_idx++)
189 mrpt::obs::CObservation2DRangeScan::Ptr& scan = ipv.
scan;
191 if (!scan) scan = mrpt::obs::CObservation2DRangeScan::Create();
194 const float occup_threshold = 0.5f;
195 const size_t nRays = 50;
197 scan->aperture = 2.0 *
M_PI;
198 scan->maxRange = veh_max_obstacles_ranges;
201 *scan, ipv.
pose, occup_threshold, nRays, 0.0f );
206 for (
size_t k = 0; k < scan->getScanSize(); k++)
208 scan->setScanRange(k, scan->getScanRange(k) + range_enlarge);
227 mrpt::opengl::CPointCloud::Ptr& gl_pts =
231 gl_pts = mrpt::opengl::CPointCloud::Create();
232 gl_pts->setPointSize(4.0
f);
233 gl_pts->setColor(0, 0, 1);
243 sqrPoly.
SetAsBox(occCellSemiWidth, occCellSemiWidth);
246 fixtureDef.
shape = &sqrPoly;
256 for (
size_t k = 0; k < nRays; k++)
262 if (!scan->getScanRangeValidity(k))
282 sincos_tab.
ccos[k] * scan->getScanRange(k);
284 sincos_tab.
csin[k] * scan->getScanRange(k);
286 const float ggx = ipv.
pose.
x() + llx;
287 const float ggy = ipv.
pose.
y() + lly;
292 const float lx = gx - ipv.
pose.
x();
293 const float ly = gy - ipv.
pose.
y();
296 occCellSemiWidth, occCellSemiWidth,
b2Vec2(lx, ly),
301 gl_pts->mrpt::opengl::CPointCloud::insertPoint(
float idx2y(const size_t cy) const
This file contains rapidxml parser and DOM implementation.
const TSinCosValues & getSinCosForScan(const CObservation2DRangeScan &scan) const
b2Fixture * CreateFixture(const b2FixtureDef *def)
std::vector< mrpt::opengl::CSetOfObjects::Ptr > m_gl_obs_clouds
std::map< std::string, TParamEntry > TParameterDefinitions
float max_obstacles_ranges
mrpt::opengl::CSetOfObjects::Ptr m_gl_grid
call of internalGuiUpdate()
void getAs3DObject(mrpt::opengl::CSetOfObjectsPtr &outObj) const MRPT_OVERRIDE
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="")
const VehicleList & getListOfVehicles() const
mrpt::obs::CObservation2DRangeScan::Ptr scan
bool m_show_grid_collision_points
std::multimap< std::string, VehicleBase::Ptr > VehicleList
mrpt::obs::CSinCosLookUpTableFor2DScans m_sincos_lut
virtual ~OccupancyGridMap()
std::unique_ptr< b2World > & getBox2DWorld()
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"))
std::vector< TFixturePtr > collide_fixtures
void SetTransform(const b2Vec2 &position, float32 angle)
std::multimap< std::string, Block::Ptr > BlockList
MRPT_TODO("Modify ping to run on Windows + Test this")
double m_restitution
Elastic restitution coef (default: 0.01)
std::string resolvePath(const std::string &in_path) const
float getResolution() const
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
std::string BASE_IMPEXP extractFileExtension(const std::string &filePath, bool ignore_gz=false)
mrpt::math::CVectorFloat csin
#define INVISIBLE_FIXTURE_USER_DATA
Used to signal a Box2D fixture as "invisible" to sensors.
float32 density
The density, usually in kg/m^2.
void SetAsBox(float32 hx, float32 hy)
mrpt::math::CVectorFloat ccos
virtual void loadConfigFrom(const rapidxml::xml_node< char > *root) 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
mrpt::maps::COccupancyGridMap2D m_grid
std::vector< mrpt::opengl::CPointCloud::Ptr > m_gl_obs_clouds_buffer
float32 restitution
The restitution (elasticity) usually in the range [0,1].
virtual void internalGuiUpdate(mrpt::opengl::COpenGLScene &scene, bool childrenOnly) override
double m_lateral_friction
(Default: 0.5)
bool loadFromBitmapFile(const std::string &file, float resolution, float xCentralPixel=-1, float yCentralPixel=-1)
std::vector< TInfoPerCollidableobj > m_obstacles_for_each_obj
mrpt::poses::CPose2D pose
virtual void simul_pre_timestep(const TSimulContext &context) override
std::mutex m_gl_obs_clouds_buffer_cs
float32 friction
The friction coefficient, usually in the range [0,1].
float idx2x(const size_t cx) const
const BlockList & getListOfBlocks() const
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble f