Model¶
-
class
MuJoCoModel¶ Convenient class to interface with MuJoCo models.
Includes numerical gradients.
A model instance is created from an XML file. The mjModel* and mjData* properties are stored internally.
General methods
-
const std::string &
get_file() const¶ Return XML file used to construct model
-
int
get_mumber_of_bodies() const¶ Return number of bodies in model
This includes the worldbody!
-
void
reset_data(const VectorXd &qpos = VectorXd(0), const VectorXd &qvel = VectorXd(0), const VectorXd &u = VectorXd(0), const ListVectorXd &xfrc = {})¶ Set current state of MJ data object
Each cartesian force is stacked like [Fx; Fy; Fz; taux; tauy; tauz]; All forward functions will be called after setting states.
- Parameters
qpos: Generalized positionsqvel: Generalized velocitiesu: Actuator forces/torquesxfrc: Cartesian applied foces
-
std::vector<std::pair<double, double>>
get_joint_limits() const¶ Get joint limits corresponding to qpos vector
Joints without limits will return (-1.0e19, 1.0e19)
- Return
Vector of pairs of doubles
-
std::vector<std::pair<double, double>>
get_torque_limits() const¶ Get actuator limits
Unlimited actuators have bounds (-1.0e19, 1.0e19)
- Return
Vector of pairs of double
-
const std::vector<int> &
get_quat_ids() const¶ Return list of quaternion ids
-
mjModel *
get_model() const¶ Get pointer to MJ model object
-
mjData *
get_data() const¶ Get pointer to MJ data object
-
int
get_body_id(const std::string &name) const¶ Return body id
- Parameters
name: Name of the body as defined in XML
Get acceleration jacobians
These jacobians are found through finite difference
-
MatrixXd
get_dynamics_diff_qpos()¶ Get derivative of acceleration w.r.t. position
- Return
Matrix, size is nv x nq.
-
MatrixXd
get_dynamics_diff_qvel()¶ Get derivative of acceleration w.r.t. velocity
- Return
Matrix, size is nv x nv.
-
MatrixXd
get_dynamics_diff_u()¶ Get derivative of acceleration w.r.t. input force
- Return
Matrix, size is nv x nu.
Kinematics functions
The body id refers to the MuJoCo m->bodyid. Note that this start at 0 for the worldbody.
- Parameters
body_id: Id of MuJoCo body
-
MatrixXd
get_geometric_jacobian_pos(int body_id) const¶ Get geometric jacobian of body for position
This is the velocity jacobian:
\[ \dot{p} = J_v * qvel \]
Set body pose through inverse kinematics
Solver works iteratively by setting end-effector velocities. This method modifies d->qpos and d->qvel directly.
- Return
True of acceptable solution was found within max. iterations
-
bool
inverse_kinematics(int base_id, const Vector3d &base_pos, int ee_id, const Vector3d &ee_pos)¶ IK for a single base and end-effector position.
- Parameters
base_id: Body id of the basebase_pos: Desired position of the baseee_id: Body id of the end-effectoree_pos: Desired position of the end-effector
-
bool
inverse_kinematics(const ListVector3d &refs_pos, const ListVector4d &refs_quat = {}, const IKSettings &settings = IKSettings())¶ IK for a list of bodies, for positions and quaternions.
Each reference is a pair of the body id and the desired pose.
- Parameters
refs_pos: Body ids and their desired locationrefs_quat: Body ids and their desired orientation (quaternions)settings: IK settings
Actuation functions
Modelling functions
Set height data of an existing heightfield
The base_z value is the padding between the bottom of the map and the bottom of the geom. It will protrude negatively, such that z = 0 will be global z = 0 too.
- Return
bool True on no errors
- Parameters
map: Matrix of height dataradius_x: Half of the x-lengthradius_y: Half of the y-lengthbase_z: Thickness of the material below z=0
-
bool
set_heightfield_normalized(int id, const MatrixXd &map, double max_elevation = 0.0, double radius_x = 0.0, double radius_y = 0.0, double base_z = 0.0)¶ Set normalized height data of an existing heightfield.
Map data must be scaled to [0 1]!
- Parameters
id: ID of the heightfieldmap:max_elevation: Max. height of hfieldradius_x:radius_y:base_z:
Public Types
-
using
MatrixXd= Eigen::MatrixXd¶
-
using
VectorXd= Eigen::VectorXd¶
-
using
Vector3d= Eigen::Vector3d¶
-
using
Vector4d= Eigen::Vector4d¶
-
using
ListVector3d= std::vector<std::pair<int, Eigen::Vector3d>>¶
-
using
ListVector4d= std::vector<std::pair<int, Eigen::Vector4d>>¶
-
using
ListVectorXd= std::vector<std::pair<int, Eigen::VectorXd>>¶
Public Functions
-
MuJoCoModel(const std::string &model_file)¶ Regular constructor
-
MuJoCoModel(const MuJoCoModel &rhs)¶ Copy constructor
Current pose and data will NOT be copied! Only the model is copied and new data is initialized.
-
~MuJoCoModel()¶ Destructor
-
MuJoCoModel &
operator=(const MuJoCoModel &rhs)¶ Assignment operator
thisis the left-hand side,rhsis the right-hand side. If right-hand side has a different file, mjModel will be copied. mjData will always be copied.
-
struct
IKSettings¶ Struct to group settings for inverse kinematics.
Used in MuJoCoModel.inverse_kinematics().
-
const std::string &