%% Compute Inverse Dynamics from Static Joint Configuration
% Use the inverseDynamics function to calculate the required joint torques to statically hold a specific robot configuration. You can also specify the joint velocities, joint accelerations, and external forces using other syntaxes.
%
% Load a predefined KUKA LBR robot model, which is specified as a  RigidBodyTree object.

load exampleRobots.mat lbr

%
% Set the data format to 'row'. For all dynamics calculations, the data format must be either 'row' or 'column'.

lbr.DataFormat = 'row';

%
% Set the Gravity property to give a specific gravitational acceleration.

lbr.Gravity = [0 0 -9.81];

%
% Generate a random configuration for lbr.

q = randomConfiguration(lbr);

%
% Compute the required joint torques for lbr to statically hold that configuration.

tau = inverseDynamics(lbr,q);

% Copyright 2012 The MathWorks, Inc.