Challenge

Week 3.2 - 2R Robotic Arm Challenge

AIM: To Analyze the Forward Kinematics of a 2R Robotic Arm

Introduction

In the field of robotics, the analysis of the solution space of robotic arm manipulators is essential for understanding their capabilities and limitations. The 2R robotic arm, consisting of two rotating links, is a fundamental model that demonstrates the principles of forward kinematics. The first link (l1) is fixed at one end and can rotate around its base. The second link (l2) is attached to the end of the first link and can rotate around the connection point. The objective of this assignment is to estimate the positions of the links in the plane and animate the movement of the robotic arm as it explores its solution space.

MATLAB Code with Explanation

The following MATLAB code is designed to animate the movement of the 2R robotic arm. The animation shows how the arm explores different positions in its solution space by varying the angles of rotation for both links.

MATLAB Code

% Animating the 2R Robotic Arm

clear all

close all

clc

% INPUTS

l1 = 1; % Length of the first link

l2 = 0.5; % Length of the second link

theta1 = linspace(0, 90, 10); % Range of angles for the first link (degrees)

theta2 = linspace(0, 90, 10); % Range of angles for the second link (degrees)

ct = 1; % Initialization counter for frames

% Create a figure for the animation

figure;

for i = 1:length(theta1)

THETA1 = theta1(i); % Current angle for the first link

for j = 1:length(theta2)

THETA2 = theta2(j); % Current angle for the second link

% Base coordinates

x0 = 0;

y0 = 0;

% Calculate the end coordinates of the first link

x1 = l1 * cosd(THETA1);

y1 = l1 * sind(THETA1);

% Calculate the end coordinates of the second link

x2 = x1 + l2 * cosd(THETA2);

y2 = y1 + l2 * sind(THETA2);

% Plot the arm positions

plot([x0, x1], [y0, y1], 'r', 'LineWidth', 3); % First link

hold on;

plot([x1, x2], [y1, y2], 'b', 'LineWidth', 3); % Second link

hold off;

axis([-0.1 1.5 0 1.5]);

xlabel('X Position');

ylabel('Y Position');

title('2R Robotic Arm Animation');

grid on;

% Capture the frame for the animation

M(ct) = getframe(gcf);

ct = ct + 1;

end

end

% Create and save the animation

VideoFile = VideoWriter('Forward_Kinematics_2R_Robotic_Arm', 'Uncompressed AVI');

open(VideoFile);

writeVideo(VideoFile, M);

close(VideoFile);

disp('Animation saved successfully.');

Explanation of the Code

1. Initialization:

- The `clear all`, `close all`, and `clc` commands are used to clear the workspace, close all figure windows, and clear the command window, respectively.

2. Input Parameters:

- `l1` and `l2` represent the lengths of the first and second links of the robotic arm.

- `theta1` and `theta2` are arrays of angles in degrees, representing the range of rotation for each link. These angles are generated using the `linspace` function, which creates linearly spaced vectors.

3. Animation Loop:

- A nested `for` loop iterates over all combinations of `theta1` and `theta2`.

- For each combination of angles (`THETA1` and `THETA2`), the end coordinates of the first link (`x1`, `y1`) and the second link (`x2`, `y2`) are calculated using trigonometric functions (`cosd` and `sind` for cosine and sine in degrees).

4. Plotting:

- The `plot` function is used to draw the links of the robotic arm. The first link is plotted from the base (`x0`, `y0`) to its end (`x1`, `y1`), and the second link is plotted from the end of the first link (`x1`, `y1`) to its own end (`x2`, `y2`).

- The `axis` function sets the limits of the plot to ensure the entire arm is visible within the specified range.

5. Capturing Frames:

- The `getframe` function captures the current figure window as a frame for the animation. These frames are stored in the array `M`.

6. Creating the Video:

- The `VideoWriter` function creates a video file for the animation. The `open`, `writeVideo`, and `close` functions are used to write the captured frames to the video file and finalize it.

Results and Observations

(Figure and Animation file, attached with the report.)

The animation shows the movement of the 2R robotic arm as it covers different positions within its reach. By varying the angles of both links, the arm can reach a wide range of positions within its workspace. This demonstrates the flexibility and range of motion of the 2R robotic arm, which is essential for various applications in robotics where precise positioning is required.

Conclusion

This report presents the analysis and animation of the solution space of a 2R robotic arm manipulator using MATLAB. The code effectively demonstrates the principles of forward kinematics by calculating and visualizing the positions of the links as their angles vary. The resulting animation highlights the versatility of the 2R robotic arm and its ability to reach various positions within its workspace, making it a valuable tool in the field of robotics.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.