Joint torques that compensate gravity
Compute Gravity Torque for Robot Configuration
Load a predefined KUKA LBR robot model, which is specified as a
load exampleRobots.mat lbr
Set the data format to
'row'. For all dynamics calculations, the data format must be either
'column'. Set the
lbr.DataFormat = 'row'; lbr.Gravity = [0 0 -9.81];
Get a random configuration for
q = randomConfiguration(lbr);
Compute the gravity-compensating torques for each joint.
gtau = gravityTorque(lbr,q);
robot — Robot model
Robot model, specified as a
rigidBodyTree object. To use the
gravityTorque function, set the
property to either
configuration — Robot configuration
Robot configuration, specified as a vector with positions for all nonfixed joints in the robot
model. You can generate a configuration using
randomConfiguration(robot), or by specifying your own joint
positions. To use the vector form of
configuration, set the
DataFormat property for the
robot to either
gravTorq — Gravity-compensating torque for each joint
Gravity-compensating torque for each joint, returned as a vector.
When working with robot dynamics, specify the information for individual bodies of your manipulator robot using these properties of the
Mass— Mass of the rigid body in kilograms.
CenterOfMass— Center of mass position of the rigid body, specified as a vector of the form
[x y z]. The vector describes the location of the center of mass of the rigid body, relative to the body frame, in meters. The
centerOfMassobject function uses these rigid body property values when computing the center of mass of a robot.
Inertia— Inertia of the rigid body, specified as a vector of the form
[Ixx Iyy Izz Iyz Ixz Ixy]. The vector is relative to the body frame in kilogram square meters. The inertia tensor is a positive definite matrix of the form:
The first three elements of the
Inertiavector are the moment of inertia, which are the diagonal elements of the inertia tensor. The last three elements are the product of inertia, which are the off-diagonal elements of the inertia tensor.
For information related to the entire manipulator robot model, specify these
rigidBodyTree object properties:
Manipulator rigid body dynamics are governed by this equation:
also written as:
— is a joint-space mass matrix based on the current robot configuration. Calculate this matrix by using the
— is the coriolis terms, which are multiplied by to calculate the velocity product. Calculate the velocity product by using by the
— is the geometric Jacobian for the specified joint configuration. Calculate the geometric Jacobian by using the
— is a matrix of the external forces applied to the rigid body. Generate external forces by using the
— are the joint torques and forces applied directly as a vector to each joint.
— are the joint configuration, joint velocities, and joint accelerations, respectively, as individual vectors. For revolute joints, specify values in radians, rad/s, and rad/s2, respectively. For prismatic joints, specify in meters, m/s, and m/s2.
To compute the dynamics directly, use the
forwardDynamics object function. The function calculates the joint accelerations for the specified combinations of the above inputs.
To achieve a certain set of motions, use the
inverseDynamics object function. The function calculates the joint torques required to achieve the specified configuration, velocities, accelerations, and external forces.
 Featherstone, Roy. Rigid Body Dynamics Algorithms. Springer US, 2008. DOI.org (Crossref), doi:10.1007/978-1-4899-7560-7.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When creating the
rigidBodyTree object, use the syntax that specifies the
MaxNumBodies as an upper bound for adding bodies to the robot model.
You must also specify the
DataFormat property as a name-value pair. For
robot = rigidBodyTree("MaxNumBodies",15,"DataFormat","row")
To minimize data usage, limit the upper bound to a number close to the expected number of bodies in the model. All data formats are supported for code generation. To use the dynamics functions, the data format must be set to