Challenge

Week 2- 2R Robotic Arm Challenge

Aim :

To write a program for 2r Robotic arm.

Syntex:

clear all
close all
clc

%2R Robotic Arm

%Inputs

theta1 = linspace(20,90,4);
theta2 = linspace(30,160,8);

%Arm Length in meter
l1 = 3;
l2 = 1.58;

%initial cordinates
x0 = 0;
y0 = 0;

ctr = 1;
for i = 1:length(theta1);
    THETA1 = theta1(i);
    for j = 1:length(theta2);
        THETA2 = theta2(j);
        %Cordinate Calculaction

        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',2)
        axis([-4 5 0 5])
        grid on
        pause(1)
        m(ctr) = getframe(gcf);
        ctr = ctr+1;

    end

end

movie(m)
Videofile = VideoWriter('Robo arm chalange.avi','Uncompressed AVI')
open(Videofile);
writeVideo(Videofile,m);
close(Videofile);

Explanaction:

  • Matlab initially read clear all,close all,clc comand and clear all window,close all files related to matlab.
  • then it initialy read the theta1 and theta2 value.
  • then it took l1 and l2 value
  • now it reads inetial coordinates
  • then it takes the variable ctr and its respective value is 1.
  • now it enters to the for loop.
  • first for loop variable is i and its vaue is give to the value of theta1
  • these value is now stored in new variable as THETA1.
  • another for loop was created to declear the value for theta2 which is j.
  • as like variable j alue is stored in THETA2.
  • now other output coordinates and its formula were given respect to THETA1 and THETA2.
  • the plot command set to draw the line as per the output coordinates.
  • now the plots were displayed as image and different color.
  • axis comend is use to give the sertain space for the robo arm.
  • pause comend helps to see what hapen when arm goes frame by frame.
  • grid commend helps to easily identif the movement
  • now the ctr is declated to a video file
  • and then the increment value for ctr given
  • it helps capture each frame in m variable and save these frame for each times for loop runs.
  • these frames are gatherd togeather and create a video file with movie commend.
  • here the frames are form as video and save in location with videoWrite commend.
  • open(videofile,m) these sentance used to open the video file,writeVideo(videofile)-helps to form a video file,close(videofile) close the video file.

Output in commend window:

Videofile = 

  VideoWriter

    General Properties:

       Filename:                 'Robo arm chalange.avi'
       Path:                     'C:\Users\jaena\OneDrive\Documents\MATLAB'
       FileFormat:               'avi'
       Duration:                 0

    Video Properties:

       ColorChannels:            3
       Height:                   []
       Width:                    []
       FrameCount:               0
       FrameRate:                30
       VideoBitsPerPixel:        24
       VideoFormat:              'RGB24'
       VideoCompressionMethod:   'None'

  Methods

Note: while running the program notices the error that i forget to give square bracket for setting the limits.

:: I cann't able to slow the video in avi file.

:: Link for video for my theta values : https://youtu.be/LLfa8Ae4HAY.

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.