In MATLAB, you represent a multi-link robot manipulator using the rigidBodyTree object from the Robotics System Toolbox. You construct the manipulator kinematics by defining individual rigid bodies (rigidBody), attaching joints (rigidBodyJoint), specifying spatial transformations between links, and assembling them into a tree structure using addBody(). You can also define kinematics via standard Denavit-Hartenberg (DH) parameter matrices or import existing URDF models using importrobot().
Method 1: Building a Multi-Link Arm with rigidBodyTree (Recommended)
The rigidBodyTree class creates a tree-structured kinematic and dynamic model supporting forward kinematics, inverse kinematics, and 3D rendering.
% Step 1: Initialize an empty Rigid Body Tree
robot = rigidBodyTree('DataFormat', 'row');
% Step 2: Create Link 1 and its Revolute Joint
body1 = rigidBody('link1');
joint1 = rigidBodyJoint('joint1', 'revolute');
setFixedTransform(joint1, trvec2tform([0, 0, 0])); % Attached to base origin
body1.Joint = joint1;
addBody(robot, body1, 'base');
% Step 3: Create Link 2 (Length: 1.0 m along X-axis)
body2 = rigidBody('link2');
joint2 = rigidBodyJoint('joint2', 'revolute');
setFixedTransform(joint2, trvec2tform([1.0, 0, 0]));
body2.Joint = joint2;
addBody(robot, body2, 'link1');
% Step 4: Create Link 3 (Length: 0.8 m along X-axis)
body3 = rigidBody('link3');
joint3 = rigidBodyJoint('joint3', 'revolute');
setFixedTransform(joint3, trvec2tform([0.8, 0, 0]));
body3.Joint = joint3;
addBody(robot, body3, 'link2');
% Step 5: Add End-Effector
endEffector = rigidBody('end_effector');
setFixedTransform(endEffector.Joint, trvec2tform([0.6, 0, 0]));
addBody(robot, endEffector, 'link3');
% Step 6: Compute Forward Kinematics for Joint Angles [q1, q2, q3]
q = [deg2rad(30), deg2rad(45), deg2rad(-20)];
tform = getTransform(robot, q, 'end_effector', 'base');
disp('End-Effector Transformation Matrix:');
disp(tform);
% Step 7: Visualize the Multi-Link Manipulator in 3D
figure('Name', '3-DOF Multi-Link Robot Manipulator');
show(robot, q, 'Visuals', 'on', 'Collisions', 'off');
title('3-DOF Multi-Link Robot Configuration');
grid on;
axis equal;
Method 2: Representing Multi-Link Manipulators via DH Parameters
If your robot model uses standard Denavit-Hartenberg parameters [a, alpha, d, theta], configure each joint transformation using the dh flag:
% Define DH parameters: [a, alpha, d, theta_offset]
dh_params = [
0, pi/2, 0.5, 0; % Link 1
1.0, 0, 0.0, 0; % Link 2
0.8, 0, 0.0, 0 % Link 3
];
robotDH = rigidBodyTree('DataFormat', 'row');
numLinks = size(dh_params, 1);
parentName = 'base';
for i = 1:numLinks
bodyName = sprintf('link%d', i);
jointName = sprintf('joint%d', i);
body = rigidBody(bodyName);
joint = rigidBodyJoint(jointName, 'revolute');
% Apply DH parameters directly
setFixedTransform(joint, dh_params(i,:), 'dh');
body.Joint = joint;
addBody(robotDH, body, parentName);
parentName = bodyName;
end
Key MATLAB Functions for Multi-Link Robots
| Function | Description |
|---|---|
rigidBodyTree |
Creates the multi-body robot kinematic and dynamic container. |
rigidBody |
Defines individual link elements with mass and inertia parameters. |
rigidBodyJoint |
Defines joint motion constraints (revolute, prismatic, or fixed). |
getTransform() |
Calculates 4x4 forward kinematics transformation matrix. |
inverseKinematics() |
Solves for joint angles given desired Cartesian end-effector coordinates. |
show() |
Renders interactive 3D multi-body visualization with joint frames. |
Practical Engineering Applications
- Forward & Inverse Kinematics: Calculate exact end-effector coordinates and solve joint displacements for pick-and-place trajectories.
- Trajectory Generation: Create smooth polynomial profiles using
trapveltrajandquinticpolytraj. - Simscape Multibody Co-Simulation: Export the robot model to Simscape to simulate actuator torques, joint friction, and closed-loop PID control dynamics.
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Explore similar technical troubleshooting questions and verified MATLAB solutions: