Challenge

Week 2- 2R Robotic Arm Challenge

  • First clear memory
  • clear all
    close all
    clc
  • Define variables :- In that linspace can make matrix and store value from 0 to 90 by 4 equal values.
  • theta1 = linspace(0,90,20)
    theta2 = linspace(0,90,20)
    l1 = 1.0
    l2 = 0.5
    x0 = 0
    y0 = 0
    ct = 1
  • Starting for loop to get value of theta1 from 0 to 90 one by one. So we can get different output values for it. In this, length command use to count numbers of column or rank of column vector. For loop executing from 1 to length of array of theta1.
    for i = 1:length(theta1)
        Theta1 = theta1(i);​
  • Now after getting one value of theta1 we have to compute various value of theta2. So by using another for loop with same above fundamental for theta2. For 1 value of theta1 we run loop for n times of theta2 to get various output.
    for j = 1:length(theta2)
            Theta2 = theta2(j)​
  • Now defining formula to get output for theta1 and theta2.
     x1 = l1*cosd(Theta1);
            y1 = l1*sind(Theta1);
            x2 = x1+l2*cosd(Theta2);
            y2 = y1+l2*sind(Theta2);​
  • For plotting there is two method.In first method, we can use hold on command and write two different function of plot 1 and plot 2.In which hold on command use to combine graph of underlying plots. Rather than this, in second method, we can use single function of plot to execute our graph as showing below. In this axis command use to fix end point of axis. And pause is setting interval between two successive for loop execution.
    plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
            axis ([-0.5 1.5 0 2.5])
            pause(0.05)​
  • For writing movie, every frame must be capture as video so for that we are using getframe command with incremental value for frame by which it stores various frames by inserting in same for loop. Now close both loops.
    M(ct) = getframe(gcf)
     ct = ct+1;​
    end
    end
    
  • Now call command of movie and give value of M which stroed all frames.Then we generate a file in which we store this frame.For this we use videowriter command. We gave file name and its type.Now call to openfile to open it. After opening file we write frames as video by using writevideo with varible of file name and frame stored variable (M). After writing close file to stop writing of frames.
    movie(M)
    videofile = VideoWriter ("kinematics_of_2r_robotic_arm.avi",'Uncompressed AVI')
    open(videofile)
    writeVideo(videofile,M)
    close(videofile)​
  • Now ouputs, graphs and animations are ready.

Output video link :- https://youtu.be/DQTJheHeG34

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.