Skip to content

raisim::SingleBodyObject ​

class · #include <raisim/object/singleBodies/SingleBodyObject.hpp>

Inherits: raisim::Object
Derived by: raisim::Box, raisim::Capsule, raisim::Compound, raisim::Cone, raisim::Cylinder, raisim::Ground, raisim::HeightMap, raisim::Mesh, raisim::Sphere

Base class of rigid single-body objects (Sphere, Box, Cylinder, Capsule, Mesh, Compound, Ground, ...). This class is only for inheritance. The pose is that of the body frame; the COM is at getBodyToComPosition_rs() in the body frame.

Constructors & destructor ​

SingleBodyObject ​

cpp
explicit SingleBodyObject(ObjectType singleBodyObjectType)

Internal: called by the concrete shape constructors.

Parameters

ParameterDescription
singleBodyObjectType (in)the concrete object type

Public member functions ​

getQuaternion ​

cpp
Eigen::Vector4d getQuaternion() const

returns the quaternion in Eigen::Vector4d

Returns the orientation of the object as a unit quaternion (w, x, y, z)

cpp
void getQuaternion(Vec<4> &quat) const

returns the quaternion in raisim::Vec<4>

Parameters

ParameterDescription
quat (out)the orientation of the object as a unit quaternion (w, x, y, z)

getRotationMatrix ​

cpp
Eigen::Matrix3d getRotationMatrix() const

returns the rotation matrix in Eigen::Matrix3d

Returns the orientation of the object (body-to-world rotation)

cpp
void getRotationMatrix(Mat<3, 3> &rotation) const

returns the rotation matrix in raisim::Mat<3,3>

Parameters

ParameterDescription
rotation (out)the orientation of the object (body-to-world rotation)

getPosition ​

cpp
Eigen::Vector3d getPosition() const

returns the body frame origin in the world frame (m). It coincides with the COM unless the object has a COM offset (see getBodyToComPosition_rs())

Returns the position of the object

cpp
void getPosition(size_t localIdx, Vec<3> &pos_w) const final

returns position vector.

Parameters

ParameterDescription
localIdx (in)this should be always 0 (this method is just to keep the same api as the ArticulatedSystem class)
pos_w (out)the body frame origin in the world frame
cpp
void getPosition(
    size_t localIdx,
    const Vec<3> &pos_b,
    Vec<3> &pos_w) const final

Get position of a point on the body

Parameters

ParameterDescription
localIdx (in)this should always be 0 (because the single body object only has one body)
pos_b (in)the point in the body frame (relative to the body frame origin)
pos_w (out)the corresponding position in the world frame
cpp
void getPosition(Vec<3> &pos_w)

Get the body frame origin of the object

Parameters

ParameterDescription
pos_w (out)the body frame origin in the world frame

getComPosition ​

cpp
Eigen::Vector3d getComPosition() const

returns the center of mass position in Eigen::Vector3d.

Returns the COM position in the world frame (m)

getComPosition_rs ​

cpp
const raisim::Vec<3> &getComPosition_rs() const

returns the center of mass position in raisim::Vec<3>.

Returns the COM position in the world frame (m)

getBodyToComPosition_rs ​

cpp
const raisim::Vec<3> &getBodyToComPosition_rs() const

returns the offset from the body frame origin to the COM.

Returns the COM offset expressed in the body frame (m)

getLinearVelocity ​

cpp
Eigen::Vector3d getLinearVelocity() const

returns the linear velocity

Returns the linear velocity of the COM in the world frame (m/s)

cpp
void getLinearVelocity(Vec<3> &linVel)

returns the linear velocity

Parameters

ParameterDescription
linVel (out)the linear velocity of the COM in the world frame (m/s)

getAngularVelocity ​

cpp
Eigen::Vector3d getAngularVelocity() const

returns the angular velocity

Returns the angular velocity of the object in the world frame (rad/s)

cpp
void getAngularVelocity(Vec<3> &angVel)

returns the angular velocity

Parameters

ParameterDescription
angVel (out)the angular velocity of the object in the world frame (rad/s)

getOrientation ​

cpp
void getOrientation(size_t localIdx, Mat<3, 3> &rot) const final

returns the orientation of the object

Parameters

ParameterDescription
localIdx (in)local idx should be always 0 (this method is just to keep the same api as the ArticulatedSystem class)
rot (out)the rotation matrix of the object
cpp
const Mat<3, 3> &getOrientation() const

returns the rotation matrix

Returns rotation matrix

getKineticEnergy ​

cpp
double getKineticEnergy() const

returns the kinetic energy

Returns the translational plus rotational kinetic energy of the object (J)

getPotentialEnergy ​

cpp
double getPotentialEnergy(const Vec<3> &gravity) const

returns the gravitational potential energy, -mass * dot(gravity, COM position), i.e., zero at the world origin

Parameters

ParameterDescription
gravity (in)gravitational acceleration (m/s^2)

Returns the potential energy of the object (J)

getEnergy ​

cpp
double getEnergy(const Vec<3> &gravity) const

equivalent to getKineticEnergy() + getPotentialEnergy(gravity)

Parameters

ParameterDescription
gravity (in)gravitational acceleration (m/s^2)

Returns the sum of the kinetic and potential energy of the object (J)

getLinearMomentum ​

cpp
Eigen::Vector3d getLinearMomentum() const

returns the linear momentum of the object

Returns the linear momentum of the object in the world frame (kg m/s)

getMass ​

cpp
double getMass(size_t localIdx=0) const override

returns the mass of the object.

Parameters

ParameterDescription
localIdx (in)unused

Returns the mass of the object (kg)

setMass ​

cpp
void setMass(double mass)

set the mass of the object. The inertia is not changed (see setInertia()).

Parameters

ParameterDescription
mass (in)the mass of the object (kg). Must be finite and positive

getInertiaMatrix_B ​

cpp
Eigen::Matrix3d getInertiaMatrix_B() const

get the inertia matrix about the COM in the body frame. This value is constant.

Returns the inertia matrix in the body frame (kg m^2)

getInertiaMatrix_W ​

cpp
Eigen::Matrix3d getInertiaMatrix_W() const

get the inertia matrix about the COM in the world frame. This value changes as the body rotates. It is only updated for dynamic bodies.

Returns the inertia matrix in the world frame (kg m^2)

getInertiaMatrix_B_rs ​

cpp
const raisim::Mat<3, 3> &getInertiaMatrix_B_rs() const

get the inertia matrix in the body frame (raisim matrix type). This value is constant.

Returns the inertia matrix in the body frame

getInertiaMatrix_W_rs ​

cpp
const raisim::Mat<3, 3> &getInertiaMatrix_W_rs() const

get the inertia matrix in the world frame (raisim matrix type). This value changes as the body rotates. It is only updated for dynamic bodies.

Returns the inertia matrix in the world frame

getObjectType ​

cpp
ObjectType getObjectType() const final

get the object type. Possible types are SPHERE, BOX, CYLINDER, CONE, CAPSULE, MESH, HALFSPACE, COMPOUND, HEIGHTMAP, ARTICULATED_SYSTEM, DEFORMABLE, GRANULAR

Returns the object type

getCollisionBody ​

cpp
CollisionBodyHandlePtr getCollisionBody() const

Returns the collision body of this object (owned by the object).

getGyroscopicMode ​

cpp
GyroscopicMode getGyroscopicMode() const

Returns the current gyroscopic integration mode.

setPosition ​

cpp
virtual void setPosition(const Eigen::Ref<const Eigen::Vector3d, Eigen::Unaligned> &originPosition)

Set position of the object (using Eigen). The orientation and velocity are unchanged.

Parameters

ParameterDescription
originPosition (in)position of the body frame origin in the world frame (m)
cpp
template <typename Position, typename std::enable_if<std::is_same<typename std::decay<Position>::type, Vec<3>>::value, int>::type = 0>
void setPosition(Position &&originPosition)

Set position of the object (using raisim::Vec<3>)

Parameters

ParameterDescription
originPosition (in)position of the body frame origin in the world frame (m)
cpp
virtual void setPosition(double x, double y, double z)

Set position of the body frame origin in the world frame (using three doubles)

Parameters

ParameterDescription
x (in)x position
y (in)y position
z (in)z position

setOrientation ​

cpp
virtual void setOrientation(const Eigen::Quaterniond &quaternion)

Set orientation of the object (using Eigen::Quaterniond). The body rotates about its body frame origin.

Parameters

ParameterDescription
quaternion (in)quaternion. It is normalized; a zero or non-finite quaternion is a fatal error
cpp
virtual void setOrientation(const Eigen::Vector4d &quaternion)

Set orientation of the object (using Eigen::Vector4d)

Parameters

ParameterDescription
quaternion (in)quaternion (w, x, y, z). It is normalized; a zero or non-finite quaternion is a fatal error
cpp
virtual void setOrientation(const Vec<4> &quaternion)

Set orientation of the object (using raisim::Vec<4>)

Parameters

ParameterDescription
quaternion (in)quaternion (w, x, y, z). It is normalized; a zero or non-finite quaternion is a fatal error
cpp
virtual void setOrientation(double w, double x, double y, double z)

Set orientation of the object (using doubles). The quaternion is normalized

Parameters

ParameterDescription
w (in)quaternion w (scalar part)
x (in)quaternion x
y (in)quaternion y
z (in)quaternion z
cpp
virtual void setOrientation(const Eigen::Matrix3d &rotationMatrix)

Set orientation of the object (using Eigen::Matrix3d)

Parameters

ParameterDescription
rotationMatrix (in)body-to-world rotation matrix
cpp
virtual void setOrientation(const Mat<3, 3> &rotationMatrix)

Set orientation of the object (using raisim::Mat<3,3>)

Parameters

ParameterDescription
rotationMatrix (in)body-to-world rotation matrix

setPose ​

cpp
virtual void setPose(
    const Eigen::Vector3d &originPosition,
    const Eigen::Quaterniond &quaternion)

Set both the position and orientation of the object (using Eigen::Vector3d and Eigen::Quaterniond)

Parameters

ParameterDescription
originPosition (in)position
quaternion (in)quaternion
cpp
virtual void setPose(
    const Eigen::Vector3d &originPosition,
    const Eigen::Vector4d &quaternion)

Set both the position and orientation of the object (using Eigen::Vector3d and Eigen::Vector4d)

Parameters

ParameterDescription
originPosition (in)position
quaternion (in)quaternion (w, x, y, z)
cpp
virtual void setPose(
    const Eigen::Vector3d &originPosition,
    const Eigen::Matrix3d &rotationMatrix)

Set both the position and orientation of the object (using Eigen::Vector3d and Eigen::Matrix3d)

Parameters

ParameterDescription
originPosition (in)position
rotationMatrix (in)rotation matrix

setInertia ​

cpp
void setInertia(const Eigen::Ref<const Eigen::Matrix3d, Eigen::Unaligned> &inertia)

Set inertia of the object (using Eigen::Matrix3d)

Parameters

ParameterDescription
inertia (in)inertia about the COM in the body frame (kg m^2). Must be finite, symmetric and positive definite

getCom ​

cpp
const Vec<3> &getCom()

get the center of mass position relative to the body frame origin

Returns the COM offset expressed in the body frame (m)

setCom ​

cpp
void setCom(const Vec<3> &com)

set the center of mass position relative to the body frame origin. The body pose is preserved.

Parameters

ParameterDescription
com (in)the COM offset expressed in the body frame (m)

setVelocity ​

cpp
virtual void setVelocity(
    const Eigen::Ref<const Eigen::Vector3d, Eigen::Unaligned> &linearVelocity,
    const Eigen::Ref<const Eigen::Vector3d, Eigen::Unaligned> &angularVelocity)

set both the linear and angular velocity of the object (using Eigen::Vector3d)

Parameters

ParameterDescription
linearVelocity (in)the linear velocity of the COM in the world frame (m/s)
angularVelocity (in)the angular velocity of the object in the world frame (rad/s)
cpp
virtual void setVelocity(
    double dx,
    double dy,
    double dz,
    double wx,
    double wy,
    double wz)

set both the linear (COM) and angular velocity of the object in the world frame (using 6 doubles)

Parameters

ParameterDescription
dx (in)the x-axis linear velocity of the object
dy (in)the y-axis linear velocity of the object
dz (in)the z-axis linear velocity of the object
wx (in)the x-axis angular velocity of the object
wy (in)the y-axis angular velocity of the object
wz (in)the z-axis angular velocity of the object

setLinearVelocity ​

cpp
void setLinearVelocity(const Vec<3> &linearVelocity)

set only the linear velocity

Parameters

ParameterDescription
linearVelocity (in)the linear velocity of the COM in the world frame (m/s)

setAngularVelocity ​

cpp
void setAngularVelocity(const Vec<3> &angularVelocity)

set only the angular velocity

Parameters

ParameterDescription
angularVelocity (in)the angular velocity in the world frame (rad/s)

setExternalForce ​

cpp
void setExternalForce(size_t localIdx, const Vec<3> &force) final

set external force on the object. Forces accumulate and are applied during the next integration step only. A STATIC body ignores them.

Parameters

ParameterDescription
localIdx (in)this should always be 0 (because the single body object only has one body)
force (in)force acting on the center of the mass (expressed in the world frame, N)
cpp
void setExternalForce(
    size_t localIdx,
    const Vec<3> &pos,
    const Vec<3> &force) final

set external force on the object at a point. This also produces the corresponding torque about the COM. Forces accumulate and are applied during the next integration step only. A STATIC body ignores them.

Parameters

ParameterDescription
localIdx (in)this should always be 0 (because the single body object only has one body)
pos (in)the application point of the force (expressed in the body frame, relative to the body frame origin)
force (in)force acting at pos (expressed in the world frame, N)

setExternalTorque ​

cpp
void setExternalTorque(size_t localIdx, const Vec<3> &torque) final

set external torque on the object. Torques accumulate and are applied during the next integration step only. A STATIC body ignores them.

Parameters

ParameterDescription
localIdx (in)this should always be 0 (because the single body object only has one body)
torque (in)torque acting on body (expressed in the world frame, Nm)

setConstraintForce ​

cpp
void setConstraintForce(
    size_t localIdx,
    const Vec<3> &pos,
    const Vec<3> &force) final

should not be used by the users

Parameters

ParameterDescription
localIdx (in)unused
pos (in)application point in the body frame
force (in)force in the world frame

setGyroscopicMode ​

cpp
void setGyroscopicMode(GyroscopicMode gyroscopicMode)

set how the gyroscopic term is integrated.

Parameters

ParameterDescription
gyroscopicMode (in)the gyroscopic integration mode

getVelocity ​

cpp
void getVelocity(size_t localIdx, Vec<3> &vel_w) const final

Get the velocity of the center of mass (not of the body frame origin when the two differ).

Parameters

ParameterDescription
localIdx (in)ignored (a single body)
vel_w (out)the center-of-mass velocity in the world frame (m/s)
cpp
void getVelocity(
    size_t localIdx,
    const Vec<3> &pos_b,
    Vec<3> &vel_w) const final

Get the velocity of a point fixed to the body.

Parameters

ParameterDescription
localIdx (in)ignored (a single body)
pos_b (in)the point in the body frame, relative to the body frame origin (as for getPosition())
vel_w (out)the point velocity in the world frame (m/s)

preContactSolverUpdate1 ​

cpp
void preContactSolverUpdate1(const Vec<3> &gravity, double dt) final

Internal: first per-step update before the contact solver (called by World).

Parameters

ParameterDescription
gravity (in)gravitational acceleration (m/s^2)
dt (in)time step (s)

preContactSolverUpdate2 ​

cpp
void preContactSolverUpdate2(
    const Vec<3> &gravity,
    double dt,
    contact::ContactProblems &problems) final

Internal: second per-step update before the contact solver (called by World).

Parameters

ParameterDescription
gravity (in)gravitational acceleration (m/s^2)
dt (in)time step (s)
problems (in, out)contact problems of the world

integrate ​

cpp
void integrate(double dt, class World &world) final

Internal: integrates the state after the contact solve (called by World).

Parameters

ParameterDescription
dt (in)time step (s)
world (in)the owning world

getContactPointVel ​

cpp
void getContactPointVel(size_t pointId, Vec<3> &vel) const final

get the contact point velocity used by the contact solver (the velocity being solved for, not the state before the step). For single bodies, articulated systems and deformable objects, it is expressed in the contact frame (z is the contact normal).

Parameters

ParameterDescription
pointId (in)the contact index. This is an index of a contact in the contact vector that you can retrieve from getContacts().
vel (out)the contact point velocity

updateCollision ​

cpp
void updateCollision() override

Internal: synchronizes the collision geometry with the current pose.

setLinearDamping ​

cpp
void setLinearDamping(double damping)

Set the linear damping that the object experiences due to air (force proportional to the COM velocity).

Parameters

ParameterDescription
damping (in)the damping coefficient (N s/m)

setAngularDamping ​

cpp
void setAngularDamping(Vec<3> damping)

Set the angular damping that the object experiences due to air (proportional to the angular velocity).

Parameters

ParameterDescription
damping (in)the damping coefficient in the body frame

setBodyType ​

cpp
virtual void setBodyType(BodyType type)

set the body type. Dynamic means that object is free to move. Kinematic means that the object can have velocity but has an infinite mass (like a conveyor belt). A kinematic body moves with its set velocity and ignores forces, gravity and contacts. Static means that the object cannot move and has an infinite mass.

Parameters

ParameterDescription
type (in)the body type

getCollisionGroup ​

cpp
CollisionGroup getCollisionGroup()

get the current collision group of the object. Read the "Contact and Collision" to learn what the collision group is.

Returns the collision group

getCollisionMask ​

cpp
CollisionGroup getCollisionMask()

get the current collision mask of the object. Read the "Contact and Collision" to learn what the collision mask is.

Returns the collision mask

setAppearance ​

cpp
void setAppearance(const std::string &appearance)

set the appearance of the object. This works in both RaisimUnity and RaisimUnreal. But depending on the visualizer, they might do different things. You can specify the color by name like "blue", "green", "red" You can also specify the color by a string like "0, 0.5, 0.5, 1.0", which represent the RGBA values RayRai reserves "hidden" and "invisible" to omit the object from rendering.

Parameters

ParameterDescription
appearance (in)the appearance of the object

getAppearance ​

cpp
const std::string &getAppearance() const

get the current appearance of the object

Returns appearance

clearExternalForcesAndTorques ​

cpp
void clearExternalForcesAndTorques() override

clear the recorded external forces and torques (the data returned by getExternalForce() etc.). This is not called by World automatically; forces set with setExternalForce() are consumed by the next step anyway.

Static member functions ​

getDOF static ​

cpp
static constexpr size_t getDOF()

Single-body objects expose a free rigid-body velocity state.

Returns the dimension of generalized velocity

getGeneralizedCoordinateDim static ​

cpp
static constexpr size_t getGeneralizedCoordinateDim()

Single-body objects use position plus quaternion coordinates.

Returns the dimension of generalized coordinate

Inherited members ​

From raisim::Object: addContactToPerObjectContact, clearPerObjectContact, getBodyType, getContactAabb, getContactAabbCount, getContacts, getExternalForce, getExternalForcePosition, getExternalTorque, getExternalTorquePosition, getId, getIndexInWorld, getName, getRenderRevision, Id, lock, lockMutex, setIndexInWorld, setName, try_lock, unlock, unlockMutex, updateContactAabbs

RaiSim — physics for robotics and AI.