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
enum class Type : intConcrete sensor type. Each subclass also provides a static getType() returning its value.
| Enumerator | Value | Description |
|---|---|---|
UNKNOWN | 0 | Not a known sensor type. |
RGB | RGBCamera. | |
DEPTH | DepthCamera. | |
IMU | InertialMeasurementUnit. | |
SPINNING_LIDAR | SpinningLidar. |
MeasurementSource
enum class MeasurementSource : intWho writes the sensor's measurement buffers.
| Enumerator | Value | Description |
|---|---|---|
RAISIM | 0 | RaiSim updates the measurement from the physics world. |
MANUAL | User code or an in-process renderer writes the measurement buffer. |
Constructors & destructor
Sensor
Sensor(
std::string name,
std::string fullName,
Type type,
class ArticulatedSystem *as,
const Vec<3> &pos,
const Mat<3, 3> &rot,
MeasurementSource source)Parameters
| Parameter | Description |
|---|---|
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
virtual ~Sensor() = defaultPublic member functions
getPosition
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
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
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
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
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
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
const std::string &getName() constReturns The name of the sensor, as given in the robot/sensor description file
getFullName
const std::string &getFullName() constReturns The full name of the sensor, including the sensor set's name (e.g. "link_name:sensor_name" for sensors defined in URDF)
getSensorSetModel
const std::string &getSensorSetModel()Returns The sensor model identifier from the sensor set.
getSerialNumber
const std::string &getSerialNumber()Returns The serial number of the sensor (copied from the SensorSet when the sensor is added)
setSerialNumber
void setSerialNumber(const std::string &serialNumber)Set the serial number of the sensor.
Parameters
| Parameter | Description |
|---|---|
serialNumber (in) | Serial number string. |
getType
Type getType()Returns The type of the sensor
getUpdateRate
double getUpdateRate() constReturns The update frequency in Hz
getUpdateTimeStamp
double getUpdateTimeStamp() constThis 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
bool isUpdateDue(double worldTime) constWhether 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
| Parameter | Description |
|---|---|
worldTime (in) | the world time (s) |
Returns true if the sensor should be updated at worldTime
setUpdateRate
void setUpdateRate(double rate)change the update rate of the sensor. Fatal error if the rate is not finite and positive.
Parameters
| Parameter | Description |
|---|---|
rate (in) | the update rate in Hz |
setUpdateTimeStamp
void setUpdateTimeStamp(double time)Set the time stamp for the last sensor measurement. RaiSim uses it to schedule the next RaiSim-sourced update.
Parameters
| Parameter | Description |
|---|---|
time (in) | the time stamp in seconds (world time) |
serializeProp
virtual server::BoundedWriter serializeProp(server::BoundedWriter data) const = 0Used by the server. Do not use it if you don't know what it does. It serializes the sensor properties
Parameters
| Parameter | Description |
|---|---|
data (in) | where the property is written; throws server::SerializationError if it does not fit |
Returns where the next data should be written
serializeMeasurements
virtual server::BoundedWriter serializeMeasurements(server::BoundedWriter data) constUsed by the server. Do not use it if you don't know what it does. It serializes sensor measurements.
Parameters
| Parameter | Description |
|---|---|
data (in) | where the measurements are written; throws server::SerializationError if they do not fit |
Returns where the next data should be written
updatePose
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
MeasurementSource getMeasurementSource()Returns The measurement source.
setMeasurementSource
void setMeasurementSource(MeasurementSource source)change the measurement source
Parameters
| Parameter | Description |
|---|---|
source (in) | The measurement source. |
getFrameId
size_t getFrameId() constGet 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
class ArticulatedSystem *getArticulatedSystem() constReturns The articulated system the sensor is attached to, or nullptr for a detached sensor.
setAttachmentFrame
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
| Parameter | Description |
|---|---|
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
void lockMutex()locks the sensor mutex. This can be used if you use raisim in a multi-threaded environment.
lock
void lock()Same as lockMutex(); makes Sensor usable with std::lock_guard / std::unique_lock.
try_lock
bool try_lock()Try to lock the sensor mutex without blocking.
Returns true if the lock was acquired.
unlockMutex
void unlockMutex()unlock the sensor mutex. This can be used if you use raisim in a multi-threaded environment.
unlock
void unlock()Same as unlockMutex(); for std::lock_guard / std::unique_lock compatibility.