MVSim
Lightweight simulator for 2.5D vehicles and robots
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mvsim::SensorBase Class Reference

Virtual base class for all sensors. More...

#include <SensorBase.h>

Inheritance diagram for mvsim::SensorBase:
Inheritance graph
[legend]
Collaboration diagram for mvsim::SensorBase:
Collaboration graph
[legend]

Public Types

using Ptr = std::shared_ptr< SensorBase >
 
- Public Types inherited from mvsim::Simulable
using Ptr = std::shared_ptr< Simulable >
 

Public Member Functions

 SensorBase (Simulable &vehicle)
 
virtual void loadConfigFrom (const rapidxml::xml_node< char > *root)
 
void registerOnServer (mvsim::Client &c) override
 
virtual void simulateOn3DScene ([[maybe_unused]] mrpt::opengl::COpenGLScene &gl_scene)
 
double sensor_period () const
 
Simulablevehicle ()
 
const Simulablevehicle () const
 
- Public Member Functions inherited from mvsim::VisualObject
 VisualObject (World *parent, bool insertCustomVizIntoViz=true, bool insertCustomVizIntoPhysical=true)
 
 VisualObject (const VisualObject &)=delete
 
VisualObjectoperator= (const VisualObject &)=delete
 
 VisualObject (VisualObject &&)=delete
 
VisualObjectoperator= (VisualObject &&)=delete
 
virtual void guiUpdate (const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &viz, const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &physical)
 
Worldparent ()
 
const Worldparent () const
 
void customVisualVisible (const bool visible)
 
bool customVisualVisible () const
 
const std::optional< Shape2p5 > & collisionShape () const
 
void showCollisionShape (bool show)
 
- Public Member Functions inherited from mvsim::Simulable
 Simulable (World *parent)
 
virtual void simul_pre_timestep (const TSimulContext &context)
 
virtual void simul_post_timestep (const TSimulContext &context)
 
virtual void apply_force (const mrpt::math::TVector2D &force, const mrpt::math::TPoint2D &applyPoint=mrpt::math::TPoint2D(0, 0))
 
virtual VisualObjectmeAsVisualObject ()
 
mrpt::math::TTwist2D getRefVelocityLocal () const
 
mrpt::math::TTwist2D getVelocityLocal () const
 
mrpt::math::TTwist2D getRefVelocityGlobal () const
 
mrpt::math::TTwist2D getComVelocityGlobal () const
 
mrpt::math::TPose3D getPose () const
 
virtual mrpt::math::TPose3D getRelativePose () const
 
mrpt::math::TPose3D getPoseNoLock () const
 No thread-safe version. Used internally only.
 
mrpt::math::TVector3D getLinearAcceleration () const
 
void setPose (const mrpt::math::TPose3D &p, bool notifyChange=true) const
 
virtual void setRelativePose (const mrpt::math::TPose3D &p)
 
void setRefVelocityLocal (const mrpt::math::TTwist2D &dq)
 
mrpt::poses::CPose2D getCPose2D () const
 Alternative to getPose()
 
mrpt::poses::CPose3D getCPose3D () const
 Alternative to getPose()
 
const std::string & getName () const
 
void setName (const std::string &s)
 
bool isInCollision () const
 
bool hadCollision () const
 
void resetCollisionFlag ()
 
const b2Body * b2d_body () const
 
b2Body * b2d_body ()
 
WorldgetSimulableWorldObject ()
 
const WorldgetSimulableWorldObject () const
 
virtual void freeOpenGLResources ()
 
virtual std::optional< float > getElevationAt ([[maybe_unused]] const mrpt::math::TPoint2D &worldXY) const
 

Static Public Member Functions

static SensorBase::Ptr factory (Simulable &parent, const rapidxml::xml_node< char > *xml_node)
 
static std::shared_ptr< mrpt::opengl::CSetOfObjects > GetAllSensorsOriginViz ()
 
static std::shared_ptr< mrpt::opengl::CSetOfObjects > GetAllSensorsFOVViz ()
 
static void RegisterSensorFOVViz (const std::shared_ptr< mrpt::opengl::CSetOfObjects > &o)
 
static void RegisterSensorOriginViz (const std::shared_ptr< mrpt::opengl::CSetOfObjects > &o)
 
- Static Public Member Functions inherited from mvsim::VisualObject
static void FreeOpenGLResources ()
 

Protected Member Functions

bool should_simulate_sensor (const TSimulContext &context)
 
Worldworld ()
 
const Worldworld () const
 
bool parseSensorPublish (const rapidxml::xml_node< char > *node, const std::map< std::string, std::string > &varValues)
 
void reportNewObservation (const std::shared_ptr< mrpt::obs::CObservation > &obs, const TSimulContext &context)
 
void reportNewObservation_lidar_2d (const std::shared_ptr< mrpt::obs::CObservation2DRangeScan > &obs, const TSimulContext &context)
 
void make_sure_we_have_a_name (const std::string &prefix)
 Assign a sensible default name/sensor label if none is provided:
 
- Protected Member Functions inherited from mvsim::VisualObject
bool parseVisual (const rapidxml::xml_node< char > &rootNode)
 Returns true if there is at least one <visual>...</visual> entry.
 
bool parseVisual (const JointXMLnode<> &rootNode)
 
virtual void internalGuiUpdate (const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &viz, const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &physical, bool childrenOnly=false)=0
 
void addCustomVisualization (const mrpt::opengl::CRenderizable::Ptr &glModel, const mrpt::poses::CPose3D &modelPose={}, const float modelScale=1.0f, const std::string &modelName="group", const std::optional< std::string > &modelURI=std::nullopt, const bool initialShowBoundingBox=false, const std::optional< double > &scaleOverride=std::nullopt)
 
void setCollisionShape (const Shape2p5 &cs)
 

Protected Attributes

Simulablevehicle_
 The vehicle this sensor is attached to.
 
double sensor_period_ = 0.1
 
double sensor_last_timestamp_ = 0
 
std::string publishTopic_
 
std::map< std::string, std::string > varValues_
 Filled in by SensorBase::loadConfigFrom()
 
- Protected Attributes inherited from mvsim::VisualObject
Worldworld_
 
std::shared_ptr< mrpt::opengl::CSetOfObjects > glCustomVisual_
 
std::shared_ptr< mrpt::opengl::CSetOfObjects > glCollision_
 
int32_t glCustomVisualId_ = -1
 
const bool insertCustomVizIntoViz_ = true
 
const bool insertCustomVizIntoPhysical_ = true
 
- Protected Attributes inherited from mvsim::Simulable
std::string name_
 

Additional Inherited Members

- Static Public Attributes inherited from mvsim::VisualObject
static double GeometryEpsilon
 

Detailed Description

Virtual base class for all sensors.

Constructor & Destructor Documentation

◆ SensorBase()

mvsim::SensorBase::SensorBase ( Simulable vehicle)

Ctor takes a ref to the vehicle to which the sensor is attached.

Member Function Documentation

◆ factory()

static SensorBase::Ptr mvsim::SensorBase::factory ( Simulable parent,
const rapidxml::xml_node< char > *  xml_node 
)
static

Class factory: Creates a sensor from XML description of type "<sensor class='CLASS_NAME'>...</sensor>".

◆ loadConfigFrom()

virtual void mvsim::SensorBase::loadConfigFrom ( const rapidxml::xml_node< char > *  root)
virtual

Loads the parameters common to all sensors. Should be overriden, and they call to this base method.

Reimplemented in mvsim::Lidar3D, mvsim::LaserScanner, mvsim::IMU, mvsim::GNSS, mvsim::DepthCameraSensor, and mvsim::CameraSensor.

◆ should_simulate_sensor()

bool mvsim::SensorBase::should_simulate_sensor ( const TSimulContext context)
protected

Should be called within each derived class simul_post_timestep() method to update sensor_last_timestamp_ and check if the sensor should be simulated now, given the current simulation time, and the sensor rate in sensor_period_.

Returns
true if it is now time to simulate a new sensor reading, false otherwise.

◆ vehicle()

Simulable& mvsim::SensorBase::vehicle ( )
inline

The vehicle this sensor is attached to

Member Data Documentation

◆ publishTopic_

std::string mvsim::SensorBase::publishTopic_
protected

Publish to MVSIM ZMQ topic stream, if not empty (default)

◆ sensor_last_timestamp_

double mvsim::SensorBase::sensor_last_timestamp_ = 0
protected

The last sensor reading timestamp. See sensor_period_

◆ sensor_period_

double mvsim::SensorBase::sensor_period_ = 0.1
protected

Generate one sensor reading every this period s


The documentation for this class was generated from the following file: