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

#include <VehicleBase.h>

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

Classes

struct  OdometryNoise
 

Public Types

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

Public Member Functions

virtual void simul_pre_timestep (const TSimulContext &context) override
 
virtual void simul_post_timestep (const TSimulContext &context) override
 
virtual void apply_force (const mrpt::math::TVector2D &force, const mrpt::math::TPoint2D &applyPoint=mrpt::math::TPoint2D(0, 0)) override
 
virtual void create_multibody_system (b2World &world)
 
virtual double getMaxVehicleRadius () const
 
virtual double getChassisMass () const
 
b2Body * getBox2DChassisBody ()
 
mrpt::math::TPoint2D getChassisCenterOfMass () const
 In local coordinates (this excludes the mass of wheels)
 
size_t getNumWheels () const
 
const WheelgetWheelInfo (const size_t idx) const
 
WheelgetWheelInfo (const size_t idx)
 
std::vector< mrpt::math::TVector2D > getWheelsVelocityLocal (const mrpt::math::TTwist2D &veh_vel_local) const
 
virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate () const =0
 
double estimateSlopeTorquePerWheel (size_t nDrivenWheels=0) const
 
const TListSensors & getSensors () const
 
TListSensors & getSensors ()
 
CSVLogger::Ptr getLoggerPtr (const std::size_t logger_index)
 
const std::vector< CSVLogger::Ptr > & getLoggers () const
 
const mrpt::math::TPolygon2D & getChassisShape () const
 
void setVehicleIndex (size_t idx)
 
size_t getVehicleIndex () const
 
void setRecording (bool record)
 
void clearLogs ()
 
void newLogSession ()
 
virtual ControllerBaseInterfacegetControllerInterface ()=0
 
void registerOnServer (mvsim::Client &c) override
 
b2Fixture * get_fixture_chassis ()
 
std::vector< b2Fixture * > & get_fixture_wheels ()
 
const b2Fixture * get_fixture_chassis () const
 
const std::vector< b2Fixture * > & get_fixture_wheels () const
 
void freeOpenGLResources () override
 
void chassisAndWheelsVisible (bool visible)
 
double chassisZMin () const
 
double chassisZMax () const
 
const mrpt::math::TPoint3D & getSlopeDirection () const
 
void setSlopeDirection (const mrpt::math::TPoint3D &d)
 
mrpt::poses::CPose2D getOdometry () const
 
void resetOdometry ()
 
bool isLogging () 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)
 
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 std::optional< float > getElevationAt ([[maybe_unused]] const mrpt::math::TPoint2D &worldXY) const
 

Static Public Member Functions

static Ptr factory (World *parent, const rapidxml::xml_node< char > *xml_node)
 
static Ptr factory (World *parent, const std::string &xml_text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
static void register_vehicle_class (const World &parent, const rapidxml::xml_node< char > *xml_node)
 
- Static Public Member Functions inherited from mvsim::VisualObject
static void FreeOpenGLResources ()
 

Static Public Attributes

static constexpr std::string_view DL_TIMESTAMP = "Timestamp"
 
static constexpr std::size_t LOGGER_IDX_POSE = 0
 
static constexpr std::size_t LOGGER_IDX_WHEELS = 1
 
static constexpr std::string_view PL_Q_X = "q0x"
 
static constexpr std::string_view PL_Q_Y = "q1y"
 
static constexpr std::string_view PL_Q_Z = "q2z"
 
static constexpr std::string_view PL_Q_YAW = "q3yaw"
 
static constexpr std::string_view PL_Q_PITCH = "q4pitch"
 
static constexpr std::string_view PL_Q_ROLL = "q5roll"
 
static constexpr std::string_view PL_DQ_X = "dqx"
 
static constexpr std::string_view PL_DQ_Y = "dqy"
 
static constexpr std::string_view PL_DQ_W = "dqw"
 
static constexpr std::string_view PL_ODO_X = "odo_x"
 
static constexpr std::string_view PL_ODO_Y = "odo_y"
 
static constexpr std::string_view PL_ODO_YAW = "odo_yaw"
 
static constexpr std::string_view WL_TORQUE = "torque"
 
static constexpr std::string_view WL_FORCE_Z = "force_z"
 
static constexpr std::string_view WL_VEL_X = "velocity_x"
 
static constexpr std::string_view WL_VEL_Y = "velocity_y"
 
static constexpr std::string_view WL_FRIC_X = "friction_x"
 
static constexpr std::string_view WL_FRIC_Y = "friction_y"
 
- Static Public Attributes inherited from mvsim::VisualObject
static double GeometryEpsilon
 

Protected Member Functions

virtual void initLoggers ()
 
virtual void writeLogStrings ()
 
virtual void internalGuiUpdate (const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &viz, const mrpt::optional_ref< mrpt::opengl::COpenGLScene > &physical, bool childrenOnly) override
 
 VehicleBase (World *parent, size_t nWheels)
 
virtual void dynamics_load_params_from_xml (const rapidxml::xml_node< char > *xml_node)=0
 
virtual std::vector< double > invoke_motor_controllers (const TSimulContext &context)=0
 
virtual void invoke_motor_controllers_post_step ([[maybe_unused]] const TSimulContext &context)
 
VisualObjectmeAsVisualObject () override
 
void updateMaxRadiusFromPoly ()
 
- 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)
 
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

std::vector< CSVLogger::Ptr > loggers_
 
std::string log_path_
 
bool auto_start_recording_ = false
 
bool idealControllerActive_ = false
 
size_t vehicle_index_ = 0
 
std::vector< FrictionBase::Ptr > frictions_
 
TListSensors sensors_
 Sensors aboard.
 
double chassis_mass_ = 15.0
 
mrpt::math::TPolygon2D chassis_poly_
 
float linear_damping_ = 0.1
 
float angular_damping_ = 0.1
 
double maxRadius_ = 0.1
 
double chassis_z_min_ = 0.05
 
double chassis_z_max_ = 0.6
 
mrpt::img::TColor chassis_color_ {0xff, 0x00, 0x00}
 
mrpt::math::TPoint2D chassis_com_ {0, 0}
 
mrpt::math::TPoint3D slopeDir_ {0, 0, -1}
 
OdometryNoise odometry_noise_
 
std::deque< Wheelwheels_info_
 
b2Fixture * fixture_chassis_ = nullptr
 Created at.
 
std::vector< b2Fixture * > fixture_wheels_
 
- 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_
 

Detailed Description

Virtual base class for each vehicle "actor" in the simulation. Derived classes implements different dynamical models (Differential, Ackermann,...)

Member Function Documentation

◆ apply_force()

virtual void mvsim::VehicleBase::apply_force ( const mrpt::math::TVector2D &  force,
const mrpt::math::TPoint2D &  applyPoint = mrpt::math::TPoint2D(0, 0) 
)
overridevirtual

Override to register external forces exerted by other WorldElements. Force is (fx,fy) in global coordinates. Application point is (local_ptx,local_pty) in the body local frame

Reimplemented from mvsim::Simulable.

◆ create_multibody_system()

virtual void mvsim::VehicleBase::create_multibody_system ( b2World &  world)
virtual

Create bodies, fixtures, etc. for the dynamical simulation. May be overriden by derived classes

◆ dynamics_load_params_from_xml()

virtual void mvsim::VehicleBase::dynamics_load_params_from_xml ( const rapidxml::xml_node< char > *  xml_node)
protectedpure virtual

Parse node <dynamics>: The derived-class part of load_params_from_xml(), also called in factory(). Includes parsing the <controller></controller> block.

Implemented in mvsim::DynamicsDifferential, mvsim::DynamicsAckermannDrivetrain, and mvsim::DynamicsAckermann.

◆ estimateSlopeTorquePerWheel()

double mvsim::VehicleBase::estimateSlopeTorquePerWheel ( size_t  nDrivenWheels = 0) const

Estimate the per-wheel torque needed to counteract gravity on a slope. Returns the torque (in Nm) that would be needed per driven wheel to hold the vehicle stationary on the current slope. Positive = uphill resistance (opposing forward motion on an uphill).

Parameters
[in]nDrivenWheelsNumber of driven wheels sharing the load.

◆ factory()

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

Class factory: Creates a vehicle from XML description of type "<vehicle>...</vehicle>".

◆ getChassisMass()

virtual double mvsim::VehicleBase::getChassisMass ( ) const
inlinevirtual

Get the overall vehicle mass, excluding wheels.

◆ getChassisShape()

const mrpt::math::TPolygon2D& mvsim::VehicleBase::getChassisShape ( ) const
inline

Get the 2D shape of the vehicle chassis, as set from the config file (only used for collision detection)

◆ getMaxVehicleRadius()

virtual double mvsim::VehicleBase::getMaxVehicleRadius ( ) const
inlinevirtual

Get (an approximation of) the max radius of the vehicle, from its point of reference (in meters)

◆ getOdometry()

mrpt::poses::CPose2D mvsim::VehicleBase::getOdometry ( ) const
inline

Gets the noisy, biased, odometry estimation.

◆ getSlopeDirection()

const mrpt::math::TPoint3D& mvsim::VehicleBase::getSlopeDirection ( ) const
inline

The "down" direction (0,0,-1) in vehicle local frame, as computed from the terrain slope. Updated each timestep by the terrain elevation module. On flat ground this is (0,0,-1). On a slope, the x/y components indicate the gravity slope force direction.

◆ getVehicleIndex()

size_t mvsim::VehicleBase::getVehicleIndex ( ) const
inline

Get the vehicle index in the World

◆ getVelocityLocalOdoEstimate()

virtual mrpt::math::TTwist2D mvsim::VehicleBase::getVelocityLocalOdoEstimate ( ) const
pure virtual

Gets the current estimation of odometry-based velocity as reconstructed solely from wheels spinning velocities and geometry. This is the input of any realistic low-level controller onboard.

See also
getRefVelocityLocal()

Implemented in mvsim::DynamicsDifferential, mvsim::DynamicsAckermannDrivetrain, and mvsim::DynamicsAckermann.

◆ getWheelsVelocityLocal()

std::vector<mrpt::math::TVector2D> mvsim::VehicleBase::getWheelsVelocityLocal ( const mrpt::math::TTwist2D &  veh_vel_local) const

Current velocity of each wheel's center point (in local coords). Call with veh_vel_local=getRefVelocityLocal() for ground-truth.

◆ register_vehicle_class()

static void mvsim::VehicleBase::register_vehicle_class ( const World parent,
const rapidxml::xml_node< char > *  xml_node 
)
static

Register a new class of vehicles from XML description of type "<vehicle:class name='name'>...</vehicle:class>".

◆ setVehicleIndex()

void mvsim::VehicleBase::setVehicleIndex ( size_t  idx)
inline

Set the vehicle index in the World

◆ simul_post_timestep()

virtual void mvsim::VehicleBase::simul_post_timestep ( const TSimulContext context)
overridevirtual

Override to do any required process right after the integration of dynamic equations for each timestep. IMPORTANT: Reimplementations MUST also call this base method, since it is in charge of important tasks (e.g. update q_, dq_)

Reimplemented from mvsim::Simulable.

◆ simul_pre_timestep()

virtual void mvsim::VehicleBase::simul_pre_timestep ( const TSimulContext context)
overridevirtual

Process right before the integration of dynamic equations for each timestep: set action forces from motors, update friction models, etc.

Reimplemented from mvsim::Simulable.

Member Data Documentation

◆ angular_damping_

float mvsim::VehicleBase::angular_damping_ = 0.1
protected

Damping ("c" viscous friction coefficient) for angular velocities of the chassis on world

◆ chassis_com_

mrpt::math::TPoint2D mvsim::VehicleBase::chassis_com_ {0, 0}
protected

center of mass. in local coordinates (this excludes the mass of wheels)

◆ fixture_wheels_

std::vector<b2Fixture*> mvsim::VehicleBase::fixture_wheels_
protected

[0]:rear-left, etc. (depending on derived class). Size set at constructor.

◆ frictions_

std::vector<FrictionBase::Ptr> mvsim::VehicleBase::frictions_
protected

Instances of friction model for the vehicle-to-ground interaction, for each wheel

◆ idealControllerActive_

bool mvsim::VehicleBase::idealControllerActive_ = false
protected

When true, friction forces are computed (for wheel spin updates and logging) but NOT applied to the Box2D chassis body. This is set by ideal controllers that directly override the vehicle twist, so that friction reaction forces don't corrupt the kinematically-imposed trajectory.

◆ linear_damping_

float mvsim::VehicleBase::linear_damping_ = 0.1
protected

Damping ("c" viscous friction coefficient) for linear velocities of the chassis on world

◆ maxRadius_

double mvsim::VehicleBase::maxRadius_ = 0.1
protected

Automatically computed from chassis_poly_ upon each change via updateMaxRadiusFromPoly()

◆ slopeDir_

mrpt::math::TPoint3D mvsim::VehicleBase::slopeDir_ {0, 0, -1}
protected

Gravity "down" direction in vehicle local frame. On flat ground = (0,0,-1). Updated by internal_simul_pre_step_terrain_elevation() each timestep.

◆ vehicle_index_

size_t mvsim::VehicleBase::vehicle_index_ = 0
protected

user-supplied index number: must be set/get'ed with setVehicleIndex() getVehicleIndex() (default=0)

◆ wheels_info_

std::deque<Wheel> mvsim::VehicleBase::wheels_info_
protected

Wheels info. The fixed size of this vector is set upon construction. Derived classes must define the order of the wheels, e.g. [0]=rear left, etc.


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