使用案例

以艾利特EC66机器人为例,基本的运动学及动力学计算函数的使用如下:

clear,clc,close all

% 导入机器人
robot = importrobot('ec66.urdf');
currentRobotJConfig = homeConfiguration(robot) % 获取当前关节配置
numJoints = numel(currentRobotJConfig)         % 获取机器人自由度

% 关节角
q   = [0 -pi/2 0 -pi/2 pi/2 0];
dq  = zeros(1,6);
ddq = zeros(1,6);
% 生成随机位姿配置
configuration = randomConfiguration(robot);
for i = 1:6
    configuration(i).JointPosition = q(i);
end
robot.show(configuration)
robot.DataFormat='row' %row为行输出,column为列输出
robot.Gravity = [0 0 -9.81]

%% 运动学
% 正运动学
T02 = getTransform(robot,q,'link2') 
T23 = getTransform(robot,q,'link3','link2') % 参数分别为robot,targetframe,sourceframe
T32 = getTransform(robot,q,'link3','link2') 
T07 = getTransform(robot,q,'link6') 

% 逆运动学
ik = inverseKinematics('RigidBodyTree',robot);
weights = [0.25 0.25 0.25 1 1 1]; % 权重矩阵,前三项为姿态权重,后三项为位置权重
randConfig = robot.randomConfiguration;
tform = getTransform(robot,randConfig,'link6','base');
[configSoln,solnInfo] = ik('link6',tform,weights,[0.5 0.5 0.5 0 0 0]);
show(robot,configSoln)

% 定义外力
wrench = [1,0,0,0,0,0];
fext   = externalForce(robot,'link6',wrench)   % 外力被定义在base系内
fext   = externalForce(robot,'link6',wrench,q) % 外力被定义在link6系内

% 计算雅克比
[com, comJac] = centerOfMass(robot, q) % 计算质心及质心雅克比
jacobian = geometricJacobian(robot,q,'link6')

%% 动力学
% 计算逆动力学
torque = inverseDynamics(robot,q,dq,ddq)
torque = inverseDynamics(robot,q,dq,ddq,fext) 

% 计算正动力学
ddq = forwardDynamics(robot,q,dq,torque)
ddq = forwardDynamics(robot,q,dq,torque,fext) 

% 获取动力学单项
M = massMatrix(robot,q) 
Cdq = -velocityProduct(robot,q,dq)
G = gravityTorque(robot,q) 

%% 获取基本动力学信息
% 获取各刚体
L{1} = robot.getBody('link1');
L{2} = robot.getBody('link2');
L{3} = robot.getBody('link3');
L{4} = robot.getBody('link4');
L{5} = robot.getBody('link5');
L{6} = robot.getBody('link6');

% 读取质量
M1 = L{1}.Mass;                                               
M2 = L{2}.Mass;                       
M3 = L{3}.Mass; 
M4 = L{4}.Mass; 
M5 = L{5}.Mass;
M6 = L{6}.Mass;

% 读取质心
c{1} = L{1}.CenterOfMass;
c{2} = L{2}.CenterOfMass
c{3} = L{3}.CenterOfMass; 
c{4} = L{4}.CenterOfMass; 
c{5} = L{5}.CenterOfMass;
c{6} = L{6}.CenterOfMass; 

% 读取惯量 [Ixx Iyy Izz Iyz Ixz Ixy]
Inertia = L{2}.Inertia;
I = [Inertia(1),Inertia(6),Inertia(5);
     Inertia(6),Inertia(2),Inertia(4);
     Inertia(5),Inertia(4),Inertia(3)]

工具箱单位

在这里插入图片描述

动力学属性

在这里插入图片描述

动力学方程

在这里插入图片描述


参考链接: