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
explicit SingleBodyObject(ObjectType singleBodyObjectType)Internal: called by the concrete shape constructors.
Parameters
| Parameter | Description |
|---|---|
singleBodyObjectType (in) | the concrete object type |
Public member functions
getQuaternion
Eigen::Vector4d getQuaternion() constreturns the quaternion in Eigen::Vector4d
Returns the orientation of the object as a unit quaternion (w, x, y, z)
void getQuaternion(Vec<4> &quat) constreturns the quaternion in raisim::Vec<4>
Parameters
| Parameter | Description |
|---|---|
quat (out) | the orientation of the object as a unit quaternion (w, x, y, z) |
getRotationMatrix
Eigen::Matrix3d getRotationMatrix() constreturns the rotation matrix in Eigen::Matrix3d
Returns the orientation of the object (body-to-world rotation)
void getRotationMatrix(Mat<3, 3> &rotation) constreturns the rotation matrix in raisim::Mat<3,3>
Parameters
| Parameter | Description |
|---|---|
rotation (out) | the orientation of the object (body-to-world rotation) |
getPosition
Eigen::Vector3d getPosition() constreturns 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
void getPosition(size_t localIdx, Vec<3> &pos_w) const finalreturns position vector.
Parameters
| Parameter | Description |
|---|---|
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 |
void getPosition(
size_t localIdx,
const Vec<3> &pos_b,
Vec<3> &pos_w) const finalGet position of a point on the body
Parameters
| Parameter | Description |
|---|---|
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 |
void getPosition(Vec<3> &pos_w)Get the body frame origin of the object
Parameters
| Parameter | Description |
|---|---|
pos_w (out) | the body frame origin in the world frame |
getComPosition
Eigen::Vector3d getComPosition() constreturns the center of mass position in Eigen::Vector3d.
Returns the COM position in the world frame (m)
getComPosition_rs
const raisim::Vec<3> &getComPosition_rs() constreturns the center of mass position in raisim::Vec<3>.
Returns the COM position in the world frame (m)
getBodyToComPosition_rs
const raisim::Vec<3> &getBodyToComPosition_rs() constreturns the offset from the body frame origin to the COM.
Returns the COM offset expressed in the body frame (m)
getLinearVelocity
Eigen::Vector3d getLinearVelocity() constreturns the linear velocity
Returns the linear velocity of the COM in the world frame (m/s)
void getLinearVelocity(Vec<3> &linVel)returns the linear velocity
Parameters
| Parameter | Description |
|---|---|
linVel (out) | the linear velocity of the COM in the world frame (m/s) |
getAngularVelocity
Eigen::Vector3d getAngularVelocity() constreturns the angular velocity
Returns the angular velocity of the object in the world frame (rad/s)
void getAngularVelocity(Vec<3> &angVel)returns the angular velocity
Parameters
| Parameter | Description |
|---|---|
angVel (out) | the angular velocity of the object in the world frame (rad/s) |
getOrientation
void getOrientation(size_t localIdx, Mat<3, 3> &rot) const finalreturns the orientation of the object
Parameters
| Parameter | Description |
|---|---|
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 |
const Mat<3, 3> &getOrientation() constreturns the rotation matrix
Returns rotation matrix
getKineticEnergy
double getKineticEnergy() constreturns the kinetic energy
Returns the translational plus rotational kinetic energy of the object (J)
getPotentialEnergy
double getPotentialEnergy(const Vec<3> &gravity) constreturns the gravitational potential energy, -mass * dot(gravity, COM position), i.e., zero at the world origin
Parameters
| Parameter | Description |
|---|---|
gravity (in) | gravitational acceleration (m/s^2) |
Returns the potential energy of the object (J)
getEnergy
double getEnergy(const Vec<3> &gravity) constequivalent to getKineticEnergy() + getPotentialEnergy(gravity)
Parameters
| Parameter | Description |
|---|---|
gravity (in) | gravitational acceleration (m/s^2) |
Returns the sum of the kinetic and potential energy of the object (J)
getLinearMomentum
Eigen::Vector3d getLinearMomentum() constreturns the linear momentum of the object
Returns the linear momentum of the object in the world frame (kg m/s)
getMass
double getMass(size_t localIdx=0) const overridereturns the mass of the object.
Parameters
| Parameter | Description |
|---|---|
localIdx (in) | unused |
Returns the mass of the object (kg)
setMass
void setMass(double mass)set the mass of the object. The inertia is not changed (see setInertia()).
Parameters
| Parameter | Description |
|---|---|
mass (in) | the mass of the object (kg). Must be finite and positive |
getInertiaMatrix_B
Eigen::Matrix3d getInertiaMatrix_B() constget 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
Eigen::Matrix3d getInertiaMatrix_W() constget 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
const raisim::Mat<3, 3> &getInertiaMatrix_B_rs() constget 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
const raisim::Mat<3, 3> &getInertiaMatrix_W_rs() constget 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
ObjectType getObjectType() const finalget the object type. Possible types are SPHERE, BOX, CYLINDER, CONE, CAPSULE, MESH, HALFSPACE, COMPOUND, HEIGHTMAP, ARTICULATED_SYSTEM, DEFORMABLE, GRANULAR
Returns the object type
getCollisionBody
CollisionBodyHandlePtr getCollisionBody() constReturns the collision body of this object (owned by the object).
getGyroscopicMode
GyroscopicMode getGyroscopicMode() constReturns the current gyroscopic integration mode.
setPosition
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
| Parameter | Description |
|---|---|
originPosition (in) | position of the body frame origin in the world frame (m) |
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
| Parameter | Description |
|---|---|
originPosition (in) | position of the body frame origin in the world frame (m) |
virtual void setPosition(double x, double y, double z)Set position of the body frame origin in the world frame (using three doubles)
Parameters
| Parameter | Description |
|---|---|
x (in) | x position |
y (in) | y position |
z (in) | z position |
setOrientation
virtual void setOrientation(const Eigen::Quaterniond &quaternion)Set orientation of the object (using Eigen::Quaterniond). The body rotates about its body frame origin.
Parameters
| Parameter | Description |
|---|---|
quaternion (in) | quaternion. It is normalized; a zero or non-finite quaternion is a fatal error |
virtual void setOrientation(const Eigen::Vector4d &quaternion)Set orientation of the object (using Eigen::Vector4d)
Parameters
| Parameter | Description |
|---|---|
quaternion (in) | quaternion (w, x, y, z). It is normalized; a zero or non-finite quaternion is a fatal error |
virtual void setOrientation(const Vec<4> &quaternion)Set orientation of the object (using raisim::Vec<4>)
Parameters
| Parameter | Description |
|---|---|
quaternion (in) | quaternion (w, x, y, z). It is normalized; a zero or non-finite quaternion is a fatal error |
virtual void setOrientation(double w, double x, double y, double z)Set orientation of the object (using doubles). The quaternion is normalized
Parameters
| Parameter | Description |
|---|---|
w (in) | quaternion w (scalar part) |
x (in) | quaternion x |
y (in) | quaternion y |
z (in) | quaternion z |
virtual void setOrientation(const Eigen::Matrix3d &rotationMatrix)Set orientation of the object (using Eigen::Matrix3d)
Parameters
| Parameter | Description |
|---|---|
rotationMatrix (in) | body-to-world rotation matrix |
virtual void setOrientation(const Mat<3, 3> &rotationMatrix)Set orientation of the object (using raisim::Mat<3,3>)
Parameters
| Parameter | Description |
|---|---|
rotationMatrix (in) | body-to-world rotation matrix |
setPose
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
| Parameter | Description |
|---|---|
originPosition (in) | position |
quaternion (in) | quaternion |
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
| Parameter | Description |
|---|---|
originPosition (in) | position |
quaternion (in) | quaternion (w, x, y, z) |
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
| Parameter | Description |
|---|---|
originPosition (in) | position |
rotationMatrix (in) | rotation matrix |
setInertia
void setInertia(const Eigen::Ref<const Eigen::Matrix3d, Eigen::Unaligned> &inertia)Set inertia of the object (using Eigen::Matrix3d)
Parameters
| Parameter | Description |
|---|---|
inertia (in) | inertia about the COM in the body frame (kg m^2). Must be finite, symmetric and positive definite |
getCom
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
void setCom(const Vec<3> &com)set the center of mass position relative to the body frame origin. The body pose is preserved.
Parameters
| Parameter | Description |
|---|---|
com (in) | the COM offset expressed in the body frame (m) |
setVelocity
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
| Parameter | Description |
|---|---|
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) |
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
| Parameter | Description |
|---|---|
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
void setLinearVelocity(const Vec<3> &linearVelocity)set only the linear velocity
Parameters
| Parameter | Description |
|---|---|
linearVelocity (in) | the linear velocity of the COM in the world frame (m/s) |
setAngularVelocity
void setAngularVelocity(const Vec<3> &angularVelocity)set only the angular velocity
Parameters
| Parameter | Description |
|---|---|
angularVelocity (in) | the angular velocity in the world frame (rad/s) |
setExternalForce
void setExternalForce(size_t localIdx, const Vec<3> &force) finalset external force on the object. Forces accumulate and are applied during the next integration step only. A STATIC body ignores them.
Parameters
| Parameter | Description |
|---|---|
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) |
void setExternalForce(
size_t localIdx,
const Vec<3> &pos,
const Vec<3> &force) finalset 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
| Parameter | Description |
|---|---|
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
void setExternalTorque(size_t localIdx, const Vec<3> &torque) finalset external torque on the object. Torques accumulate and are applied during the next integration step only. A STATIC body ignores them.
Parameters
| Parameter | Description |
|---|---|
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
void setConstraintForce(
size_t localIdx,
const Vec<3> &pos,
const Vec<3> &force) finalshould not be used by the users
Parameters
| Parameter | Description |
|---|---|
localIdx (in) | unused |
pos (in) | application point in the body frame |
force (in) | force in the world frame |
setGyroscopicMode
void setGyroscopicMode(GyroscopicMode gyroscopicMode)set how the gyroscopic term is integrated.
Parameters
| Parameter | Description |
|---|---|
gyroscopicMode (in) | the gyroscopic integration mode |
getVelocity
void getVelocity(size_t localIdx, Vec<3> &vel_w) const finalGet the velocity of the center of mass (not of the body frame origin when the two differ).
Parameters
| Parameter | Description |
|---|---|
localIdx (in) | ignored (a single body) |
vel_w (out) | the center-of-mass velocity in the world frame (m/s) |
void getVelocity(
size_t localIdx,
const Vec<3> &pos_b,
Vec<3> &vel_w) const finalGet the velocity of a point fixed to the body.
Parameters
| Parameter | Description |
|---|---|
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
void preContactSolverUpdate1(const Vec<3> &gravity, double dt) finalInternal: first per-step update before the contact solver (called by World).
Parameters
| Parameter | Description |
|---|---|
gravity (in) | gravitational acceleration (m/s^2) |
dt (in) | time step (s) |
preContactSolverUpdate2
void preContactSolverUpdate2(
const Vec<3> &gravity,
double dt,
contact::ContactProblems &problems) finalInternal: second per-step update before the contact solver (called by World).
Parameters
| Parameter | Description |
|---|---|
gravity (in) | gravitational acceleration (m/s^2) |
dt (in) | time step (s) |
problems (in, out) | contact problems of the world |
integrate
void integrate(double dt, class World &world) finalInternal: integrates the state after the contact solve (called by World).
Parameters
| Parameter | Description |
|---|---|
dt (in) | time step (s) |
world (in) | the owning world |
getContactPointVel
void getContactPointVel(size_t pointId, Vec<3> &vel) const finalget 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
| Parameter | Description |
|---|---|
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
void updateCollision() overrideInternal: synchronizes the collision geometry with the current pose.
setLinearDamping
void setLinearDamping(double damping)Set the linear damping that the object experiences due to air (force proportional to the COM velocity).
Parameters
| Parameter | Description |
|---|---|
damping (in) | the damping coefficient (N s/m) |
setAngularDamping
void setAngularDamping(Vec<3> damping)Set the angular damping that the object experiences due to air (proportional to the angular velocity).
Parameters
| Parameter | Description |
|---|---|
damping (in) | the damping coefficient in the body frame |
setBodyType
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
| Parameter | Description |
|---|---|
type (in) | the body type |
getCollisionGroup
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
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
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
| Parameter | Description |
|---|---|
appearance (in) | the appearance of the object |
getAppearance
const std::string &getAppearance() constget the current appearance of the object
Returns appearance
clearExternalForcesAndTorques
void clearExternalForcesAndTorques() overrideclear 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
static constexpr size_t getDOF()Single-body objects expose a free rigid-body velocity state.
Returns the dimension of generalized velocity
getGeneralizedCoordinateDim static
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