Challenge

Week 2- 2R Robotic Arm Challenge

close all
clc

% input
l1 = 1;
l2 = .75;
theta1 = linspace(0,90,30);
theta2 = linspace(0,90,30);
ct = 1;
for i = 1: length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        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.75 0 1.75])
        pause(0.05)
        M(ct) = getframe(gcf);
        ct = ct+1;
    end
end
movie (M)
videofile = videoWriter('forward_kinematics_of_roboticarm.avi','Uncompressed AVI');
open(videofile)
Writervideo(videofile,M)
close(videofile)

first of all type

clear all

close all

clc

to give the input values type

% input

l1 =1; (to give the length of arm 1 as 1m and i we don't want to see that on the command window give a semicolumn.)

l2 = .75; the length of arm 2 as .75m

theta 1 = linspace(0,90,50)

theta 2 = linspace(0,90,50)

to give the angles of arm 1&2, and if we want theta values from 0 to 90 at an interval of 50.

create a for loop, that helps to change and select multiple input values to the input angle for the robotic arm 1&2 such as

for i= 1: length (theta 1)

ie; take the values of theta (0) to the last values, ie; the entire length of theta. and for each values of theta i should be change to give different input angles and we denote it as THETA

THETA 1 = theta (i);

again we create another for loop that for the input angles of arm 2

for j= 1: length (theta2)

THETA 2 = theta 2 (j)

and to give the co-ordinate values give as follows

x0=0;

y0=0;

as we know that,

x1= l1*cosd(THETA 1)

y1= l1*sind(THETA 1)

also, plot the animation of arm 2

x2= x1+ l2*cosd (THETA 2)

y2=y1+l2*sind(THETA 2)

to plot the diagram

% plot

plot ([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linwidth',3)

to set the axis (and going the x limits & y limits)

axis([0 1.75 0 1.75])

pause (0.3) (to visuallize the plot)

then figure of counter to show particular combination of arm 1 & 2. but is like individual figures. initially ct is set to be 1

ct=ct + 1;

so we want to create a movie from this, type get individual frames & that saved in an away called (M)

M(ct) =get frame(gcf)

ct represents each & every frame

get frame means get current figure window(gcf)

And at the end of the for loop as shown above type

Movie ( M )

videofile = videowriter ( 'forward_kinnematics_avi','uncompressed AVI');

open(videofile)

writeVideo (videofile, M)

close (window)

https://drive.google.com/file/d/1qqtxJi2rRDzuf7uqsnTN47eNYptoPzFa/view?usp=sharing

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.