Challenge

Week 2- 2R Robotic Arm Challenge

AIM : To write a program in mathlab to simulate the forward kinematics of a 2r robotic arm

Equations to be considered : For a 2r Robotic arm the working is so important, in order to find that we divide the arm into two links at two locations and taking length as l1 and l2 making an angle thetha1 and thetha2

x0 = 0 y0 = 0 ; x1 = l1*cos(thetha1) y1 = l1*sin(thetha1)
x2 = x1 + l2*cos(thetha2) y2 = y1 + l2*sin(thetha2)

by using these equations we will write a program to determine the working space of a 2r robotic arm.

Objectives : For finding the working space of a 2r robotic arm and creating a movie for the animation and exporting it as a video.

CODE :

clear all
close all
clc

%input data given as 
l1=1;
l2=0.5;

%thetha angles
thetha1 = linspace(0,90,10);
thetha2 = linspace(0,90,10);

%loop for creating animation
ct=1
for i=1:length(thetha1)
    THETHA1 = thetha1(i)
    for j=1:length(thetha2)
        THETHA2 = thetha2(j)
        x0=0;
        y0=0;

        x1=l1*cosd(THETHA1);
        y1=l1*sind(THETHA1);

        x2 = x1+l2*cosd(THETHA2);
        y2 = y1+l2*sind(THETHA2);

        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',3,'Color','r')
        axis([0 3 0 3])
        pause(0.03)
        M(ct) = getframe(gcf);
        ct = ct+1;
    end
end

movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)


code explain : Always start with the basic commands clc close all and clear all. The input data is given and for the thetha values we are using the linspace command
and for the animation part we are using the for loop, here a point to be noted the particular angle of link 1 has multiple values
of link 2 so we are creating an another for loop in the command once again. finally we are plotting the resukts
using the plot command and we are creating a movie using the m(ct)=getframe(gcf) and stroing it in the folder with
the uncompressed avi and writing it and closing the video file

Animation Video link from youtube :

https://www.youtube.com/watch?v=lnsuRATzHxY

REFERENCES :

https://www.fengyuanhanxi.top/ProductDetail.aspx?iid=55029491&pr=43.88
https://medium.com/@neerajdixit_55283/forward-kinematics-of-a-2r-robotic-arm-bd9502d70fbc

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.