Challenge

Week 2- 2R Robotic Arm Challenge

Aim- Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.

Theory- Forward kinematics refers to the use of the kinematics equation of a robot to compute the position of the end effector from specified values for the joint parameters. If we know the geometry of the robot and all its joint points, we can do the math and figure out the position and orientation of any point on the robot.

Code-

% Forward kinematics of a 2R robotic arm manipulator
clear all
close all
clc
% Inputs
l1= 1; % lenght of first link
l2= 0.5; % length of second link
theta1= linspace(0,90,10); % linspace command is used to create an array of angle theta.
theta2= linspace(0,90,10);
ct=1;
for i=1:length(theta1) % nested for loop is used to obtain the value of x and y co-ordinates at different theta values
THETA1= theta1(I);
for j=1:length(theta2)
THETA2= theta2(j);
% Co-ordinates
x0= 0;
y0=0;
x1= l1*cosd(THETA1);
y1= l1*sind(THETA1);
x2= x1 + l2*cosd(THETA2);
y2= y1 + l2*sind(THETA2);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
%getframe command is used to store frames of plots showing different positions of the robotic arm to create an animation.
movie(M)
videofile = VideoWriter('kinematics.avi', 'Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Output- The output is an animation file named kinematics. The google drive link for the same is provided below:-

https://drive.google.com/file/d/16P7cM98hoBH-n6O0XC3hU-PXbnoddCE2/view?usp=sharing

Errors occurred-

% movie(M)
% videofile = VideoWriter('forward_kinematics.avi','Uncompressed.AVI');
% open(videofile)
% writeVideo(videofile,M)
% close(videofile)
Steps Taken-
An error occurred during the final run of the program as the code line marked red above should not contain (.) in between 'Uncompressed AVI', which caused the video file to not be saved. The code was checked several times and the mistake was rectified. (Above picture shows the Comment part as rectified part.)
Conclusion- The program to write a code for forward kinematics of a 2R robotic arm was successfully performed and the animation video link was attached to the report.
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.

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.