Project

2R Robotic arm movie

Objective: To write a program to simulate the forward kinematics of a 2R Robotic Arm.

Body:

code:

clear all
close all
clc
%inputs theta 1 and 2 length of arm 1 and 2
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
l1=1;
l2=0.5;
%couter is one
ct=1;
%for loop to animate the plot for different values of theta 1
for i = 1:length(theta1) % for i value changing from 1 to 10
    THETA1 = theta1(i);
    for j = 1:length(theta2) %for j value chnaging from 1 to 10
        THETA2 = theta2(j);
        
       %co-ordinates x0 y0 x1 y1 x2 y2 
       
       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)
       
       %giving limits for axis
       
       axis([0 1.5 0 1.5])
       %this will pause the code so that the animation will run smoothly
       pause(0.005) 
       M(ct) = getframe(gcf);
       %this shows that for every iteration value will be added by one
       ct= ct+1; 
    end
end
%to create a movie using all the frames
movie(M)
%creating a videofile
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
%to open the video file
open(videofile)
%to write the video of all the frames captured
writeVideo(videofile,M)
close(videofile)

Result:

we can see that the 2R robotic arm's motion with respect to theta is plotted.

https://drive.google.com/file/d/18f9NaqUPnm046Fkz5ZVUSnl0ioi0Dqg5/view?usp=sharing

errors during programming:

1. due to closing the movie before it ended, there was an error shown which was rectified.

2. "uncompressed AVI" command while saving video file was not capitalized due to while AVI file was not getting saved only a picture was getting saved(only a particular frame) which was then rectified.

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.