Skip to content

raisim::Sensor ​

abstract class · #include <raisim/sensors/Sensors.hpp>

Derived by: raisim::DepthCamera, raisim::InertialMeasurementUnit, raisim::RGBCamera, raisim::SpinningLidar

Base class of all sensors attached to an ArticulatedSystem frame (RGBCamera, DepthCamera, InertialMeasurementUnit, SpinningLidar).

Sensors are owned by a SensorSet, which belongs to a body of an ArticulatedSystem. Every sensor is attached to a fixed frame of that system (see getFrameId()); its world pose is read from that frame. When the measurement source is MeasurementSource::RAISIM, the owning ArticulatedSystem refreshes the measurement during World::integrate() whenever at least 1/getUpdateRate() seconds of simulated time have passed since getUpdateTimeStamp(), and at once when World::setWorldTime() moved the time back before it (isUpdateDue()). IMUs use a phase-preserving clock and expose the acquisition time even when delivery is delayed. With MeasurementSource::MANUAL, user code (or a renderer) writes the measurement buffers.

Public types ​

Type ​

cpp
enum class Type : int

Concrete sensor type. Each subclass also provides a static getType() returning its value.

EnumeratorValueDescription
UNKNOWN0Not a known sensor type.
RGBRGBCamera.
DEPTHDepthCamera.
IMUInertialMeasurementUnit.
SPINNING_LIDARSpinningLidar.

MeasurementSource ​

cpp
enum class MeasurementSource : int

Who writes the sensor's measurement buffers.

EnumeratorValueDescription
RAISIM0RaiSim updates the measurement from the physics world.
MANUALUser code or an in-process renderer writes the measurement buffer.

Constructors & destructor ​

Sensor ​

cpp
Sensor(
    std::string name,
    std::string fullName,
    Type type,
    class ArticulatedSystem *as,
    const Vec<3> &pos,
    const Mat<3, 3> &rot,
    MeasurementSource source)

Parameters

ParameterDescription
name (in)Sensor name (unique within its SensorSet).
fullName (in)Name including the sensor-set prefix.
type (in)Concrete sensor type.
as (in)Owning articulated system (may be null until attached).
pos (in)Sensor position relative to the body (link) it is defined on.
rot (in)Sensor orientation relative to the body (link) it is defined on.
source (in)Initial measurement source.

~Sensor ​

cpp
virtual ~Sensor() = default

Public member functions ​

getPosition ​

cpp
const Vec<3> &getPosition()

The pose is refreshed by updatePose() (which the user may call) and by every RaiSim-sourced measurement update. It is not refreshed automatically for MANUAL sensors.

Returns The position of the sensor frame in the world frame

getOrientation ​

cpp
const Mat<3, 3> &getOrientation()

The pose is refreshed by updatePose() (which the user may call) and by every RaiSim-sourced measurement update. It is not refreshed automatically for MANUAL sensors.

Returns The orientation of the sensor frame in the world frame (sensor-to-world rotation)

getFramePosition ​

cpp
const Vec<3> &getFramePosition()

Returns The position of the frame w.r.t. the nearest moving parent. It is used to compute the frame position in the world frame

getFrameOrientation ​

cpp
const Mat<3, 3> &getFrameOrientation()

Returns The orientation of the frame w.r.t. the nearest moving parent. It is used to compute the frame position in the world frame

getPosInSensorFrame ​

cpp
const Vec<3> &getPosInSensorFrame()

Returns The position given at construction, relative to the body (link) the sensor was defined on (i.e., its parent joint frame). Unlike getFramePosition(), it is not re-expressed when fixed bodies are merged into their moving parent.

getOriInSensorFrame ​

cpp
const Mat<3, 3> &getOriInSensorFrame()

Returns The orientation given at construction, relative to the body (link) the sensor was defined on (i.e., its parent joint frame). See getPosInSensorFrame().

getName ​

cpp
const std::string &getName() const

Returns The name of the sensor, as given in the robot/sensor description file

getFullName ​

cpp
const std::string &getFullName() const

Returns The full name of the sensor, including the sensor set's name (e.g. "link_name:sensor_name" for sensors defined in URDF)

getSensorSetModel ​

cpp
const std::string &getSensorSetModel()

Returns The sensor model identifier from the sensor set.

getSerialNumber ​

cpp
const std::string &getSerialNumber()

Returns The serial number of the sensor (copied from the SensorSet when the sensor is added)

setSerialNumber ​

cpp
void setSerialNumber(const std::string &serialNumber)

Set the serial number of the sensor.

Parameters

ParameterDescription
serialNumber (in)Serial number string.

getType ​

cpp
Type getType()

Returns The type of the sensor

getUpdateRate ​

cpp
double getUpdateRate() const

Returns The update frequency in Hz

getUpdateTimeStamp ​

cpp
double getUpdateTimeStamp() const

This method returns a negative value if the sensor has never been updated

Returns The world time (s) when the last sensor measurement was recorded

isUpdateDue ​

cpp
bool isUpdateDue(double worldTime) const

Whether a scheduled update is due: one update interval after the last update, or at once when the world time went back before the last update (setWorldTime() at a new episode).

Parameters

ParameterDescription
worldTime (in)the world time (s)

Returns true if the sensor should be updated at worldTime

setUpdateRate ​

cpp
void setUpdateRate(double rate)

change the update rate of the sensor. Fatal error if the rate is not finite and positive.

Parameters

ParameterDescription
rate (in)the update rate in Hz

setUpdateTimeStamp ​

cpp
void setUpdateTimeStamp(double time)

Set the time stamp for the last sensor measurement. RaiSim uses it to schedule the next RaiSim-sourced update.

Parameters

ParameterDescription
time (in)the time stamp in seconds (world time)

serializeProp ​

cpp
virtual server::BoundedWriter serializeProp(server::BoundedWriter data) const = 0

Used by the server. Do not use it if you don't know what it does. It serializes the sensor properties

Parameters

ParameterDescription
data (in)where the property is written; throws server::SerializationError if it does not fit

Returns where the next data should be written

serializeMeasurements ​

cpp
virtual server::BoundedWriter serializeMeasurements(server::BoundedWriter data) const

Used by the server. Do not use it if you don't know what it does. It serializes sensor measurements.

Parameters

ParameterDescription
data (in)where the measurements are written; throws server::SerializationError if they do not fit

Returns where the next data should be written

updatePose ​

cpp
void updatePose()

update the world pose of the sensor (getPosition(), getOrientation()) from its attachment frame in the articulated system. Fatal error if the sensor is not attached to a valid frame.

getMeasurementSource ​

cpp
MeasurementSource getMeasurementSource()

Returns The measurement source.

setMeasurementSource ​

cpp
void setMeasurementSource(MeasurementSource source)

change the measurement source

Parameters

ParameterDescription
source (in)The measurement source.

getFrameId ​

cpp
size_t getFrameId() const

Get the id of the frame on which the sensor is attached

Returns frame id (index into ArticulatedSystem::getFrames()); size_t(-1) if not attached yet

getArticulatedSystem ​

cpp
class ArticulatedSystem *getArticulatedSystem() const

Returns The articulated system the sensor is attached to, or nullptr for a detached sensor.

setAttachmentFrame ​

cpp
void setAttachmentFrame(
    const Vec<3> &pos,
    const Mat<3, 3> &rot,
    size_t frameId)

Attach this sensor to an existing articulated-system frame. This is primarily useful for editor or procedural scene builders that create sensors after an articulated system has already been instantiated.

Parameters

ParameterDescription
pos (in)Frame position relative to the nearest moving parent body.
rot (in)Frame orientation relative to the nearest moving parent body.
frameId (in)Index of the frame in ArticulatedSystem::getFrames().

lockMutex ​

cpp
void lockMutex()

locks the sensor mutex. This can be used if you use raisim in a multi-threaded environment.

lock ​

cpp
void lock()

Same as lockMutex(); makes Sensor usable with std::lock_guard / std::unique_lock.

try_lock ​

cpp
bool try_lock()

Try to lock the sensor mutex without blocking.

Returns true if the lock was acquired.

unlockMutex ​

cpp
void unlockMutex()

unlock the sensor mutex. This can be used if you use raisim in a multi-threaded environment.

unlock ​

cpp
void unlock()

Same as unlockMutex(); for std::lock_guard / std::unique_lock compatibility.

RaiSim — physics for robotics and AI.