Challenge

Week 3.2 - 2R Robotic Arm Challenge

Aim

To make animation of robotic arm.

Explanation

Clear all- Delete variable

Close all-Close all the Plot

Clc-Clean the command window

I give the input Theta1, Theta2, L1 and L2

Theta1 and Theta2 give input as Linspace (0,90,10)

Linspace work as, here I mention (0,90,10) It gives 10 between 0 to 90 (0,10,20,30,40,50,60,70,80,90)

l1- Length of first arm

l2- Length of second arm

After Counter used.

Counter is used to increment the plot.

FOR LOOP-Refers anything Between Initial value to end value.

In this for loop I used 2 variable (I,j)

In (i) variable initial value was one and final value full length of theta1

Follow by statement THETA1 was assign the variable (i) in theta1

Nested for loop used for assign the variable (j)

In (j) variable initial value was one and final value full length of theta2

Follow by statement THETA2 was assign the variable (j) in theta2

Assign the coordinate values for to plotting

(x0,y0,x1,y1,x2,y2) coordinate going to assign the value.

x0 and yo are orgin coordinate so the values are zero

x1 and y1 are second coordinate it represent the length of first link of roboarm

x1 coordinate the value is l1 multiply with cosd(THETA1)

y1 coordinate the value is l1 multiply with sind(THETA2)

Here if I given cos it assign value in Radian if value to be assign in degree means we need put “d” so I given cosd and sind

x 2 and y2 are second coordinate it represent the length of first link of roboarm

x2 coordinate the value is l1 multiply with cosd(THETA1)with addition of x1

y2 coordinate the value is l1 multiply with sind(THETA2) with addition of y1

here I add the x1 and y1 to x2 and y2 because to join the two coordinate.

Plot

In this process I going to plot the coordinates

Plot command is used for plotting the all the coordinates we assign.

And using the “linewidth” command for specific of width of the line.

In plot command enter the coordinate as (x0,x1)and (y0,y1) then only it will plot the coordinates.

Axis

Here I enter the axis value for x and y(where to start and where to end)

Pause

Pause command is used execution or fractional pause before continuing the sequence of plotting.

Get frame

Get frame used to capture the frame and it assign to the variable name called M.

Counter

After capture the frame it will move to another frame so here we use counter command, it will take to another frame.

And finally end is used to end the loop. Here two end command used because of nested for loop used.

Now need to make movie of robotic arm

For making movie “Movie” command is used. Assign the M variable in movie command because in M variable we capture all the frames.

To make video file in avi format “videofile” command in used. In this command we can name open video file.

To open video file, Assign the videofile in open.

To write the video, assign videofile with variable M.

To close video file, Assign the videofile in open.

Issue face

1)Letter case error occurred in (video writer)

This error solved by asking expert in skill lync.

2) y1=l1*sind(THETA1) in this step i didn’t put multiply.

This error solved by watching video.

https://drive.google.com/file/d/1cl-i5ct_-D0Zc7-tZthYv22WFH9Z3EZD/view?usp=sharing

clear all
close all
clc

%Input
 theta1 = linspace(0,90,10);
 theta2 = linspace(0,90,10);
 
 l1=1;
 l2=0.5;
 ct=1;
 for i=1:length(theta1);
     THETA1=theta1(i);
    for j=1:length(theta2);
        THETA2=theta2(j);
        
       xo=0;
       yo=0;
       
       x1=l1*cosd(THETA1);
       y1=l1*sind(THETA1);
       
       x2=x1+l2*cosd(THETA2);
       y2=y1+l2*sind(THETA2);
       
       %plot
       plot([xo x1],[yo y1],[x1 x2],[y1 y2],'linewidth',3);
       axis([-0.1 2 0 2])
       pause(0.2)
       M(ct) = getframe(gcf);
       ct=ct+1;
    end
 end
 movie(M)
 videofile=VideoWriter('robotic_arm.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.