Challenge

Week 3.2 - 2R Robotic Arm Challenge

1. Code With explanation:

clear all

close all

clc

% Define initial conditions and link lengths

x0 = 0;

y0 = 0;

l1 = 1;

l2 = 0.5;

% Define joint angles for two links

theta1 = linspace(0, 90, 5);

theta2 = linspace(0, 90, 5);

% Initialize frame counter

ct = 1;

% Loop through the first set of joint angles

for i = 1:length(theta1)

% Extract the current value of theta1

theta11 = theta1(i);

% Loop through the second set of joint angles

for j = 1:length(theta2)

% Extract the current value of theta2

theta22 = theta2(j);

% Initialize joint positions

x0 = 0;

y0 = 0;

x1 = l1 * cosd(theta11);

y1 = l1 * sind(theta11);

x2 = x1 + l2 * cosd(theta22);

y2 = y1 + l2 * sind(theta22);

% Plot the two-link robot arm

plot([x0, x1], [y0, y1], [x1, x2], [y1, y2], "linewidth", 2)

axis([-0.5 2 0 2])

pause(0.03) % Pause to create animation effect

M(ct) = getframe(gcf); % Capture the current figure as a frame

ct = ct + 1; % Increment frame counter

end

end

% Play the animation using the 'movie' function

movie(M)

% Create a video file in uncompressed AVI format

videofile = VideoWriter('Forward_Kinematics.avi', 'Uncompressed AVI');

open(videofile)

writeVideo(videofile, M)

close(videofile)

Errors faced in the video :

1) The pause time was earlier kept at 0.3 for slower animation but this was creating an issue while creating the file as the size was large resulting into corrupted file. The pause time was changed to 0.03 as per tutorial to have a

Video Link :

https://drive.google.com/file/d/1eraUHCljqolph37J64FPP0OhLpyB6pVq/view?usp=drive_link

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.