Challenge

Week 2- 2R Robotic Arm Challenge

first of all we will plot simple non moving arms by fixed angle and co,ordinates for which we use following steps ;

step 1- we gives the inputs like value of theta and length(l1 , l2)

step 2-after giving inputs we wil calculate coordinates (x0,x1,x2) (y0,y1,y2) by using equation x1=l1cosd(theta1) , but we got the error(1.1) saying " undefined function 'l1cosd' the mistake i makeis i didnt put multiplication sign(*) in between l1 & cosd which gives us equation like x1=l1*cosd(theta1). and simillarly we plot other coordinates using equation

step 3-then we start to plot the arms by comanding "plot([x0 x1],[y0 y1],'linewidth',3,'color','r') & plot([x1 x2],[y1 y2],'linewidth',3,'color','b') then we got the plot now lets move to next stage to make moving arm

close all 
clear all 
clc

%inputs
l1 = 2;
l2 = 1.5;

%thetas or angles
theta1=45;
theta2=90;

%cordinates
x0=0;
y0=0;

x1=l1*cosd(theta1)
y1=l1*sind(theta1)

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

%ploting
line([x0 x1],[y0 y1],'linewidth',3,'color','r')
line([x1 x2],[y1 y2],'linewidth',3,'Color','b')


starting our phase-2 for moving 2r robotic arm by using following steps;

step 1- keeping above code same and making slight changes in that like first change is changing of angle for moving arm we need many angles so we giving command "theta1=linspace[0,90,10]" which gives us angle from 0 to 90 with every 10 degree gap in between ,and simillarly we do for theta2

step 2-now we ar going to add "for" & "end" loop in the code

step 3-now in for loop we add i=1:length(theta1) & THETA1=theta1(i) which gives us the length with respect to every 10 degree angle and simillarly we do it for 'j' and leaving the every coordinates same as in first phase

step 4-now we come to the ploting of arms, we make another change in ploting section wrt phase 1, we add "plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)" command which gives us every cocordinate in one plot ,after that we the limits to x and y axis axis by giving command"axis([-0.1 1.5 0 1.5])"

step 5-now we have to make movie or we can say animation of that moving chart and for that we require the pausing of frames so we give command "pause(0.03)"

step 6-after hiting run we got the error (2.1) which shows us "theta1=linspace[0,90,10]" in this command they are showing invalid expression or ceck for mismatched delimiters..... so we make small mistake , we gives the square bracket insted of normal so after changing equetion be like "theta1=linspace(0,90,10)"

step 7-after adding pause code we now going to ad ct which means counter so we starting from ct=1 to ct=ct+1 , so each and every time for loop is going to excecuted the ct=ct+1 gets incrementing

step 8-now we give the comand movie(m) to matlab that generates the animation video of the plot or arm. after that we have to add file name which we gave to that matlab code to complete the video 
 

final code given below-

close all 
clear all 
clc

%inputs
l1 = 1;
l2 = 0.5;
ct = 1

%thetas or angles
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);

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)

%ploting
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

movie(m)
videofile = VideoWriter('roboticsarm2r.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)
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.