Challenge

Week 2- 2R Robotic Arm Challenge

The robotic arm movement gives the insight into the accessibility of the effector, this is also known as the workspace of the robotic arm.

The below program helps to simulate the robotic arm movement & also understand the link movements of the robot.

clear all %1%
close all
clc

l_support=2; %2%
l_1=1;
l_2=1;
theta_1=linspace(0,60,14);
theta_2=linspace(-60,0,14);

ct=1; %3%
for i=1:length(theta_1) %4%
    Theta_1=theta_1(i);
    for j=1:length(theta_2) %5%
        Theta_2=theta_2(j);
        
        x_0=0; %6%
        y_0=0;
        x_1=0;
        y_1=2;
        x_2=x_1+l_1*cosd(Theta_1); %7%
        y_2=y_1+l_1*sind(Theta_1);
        x_3=x_2+l_2*cosd(Theta_2);
        y_3=y_2+l_2*sind(Theta_2);

        plot([x_0 x_1],[y_0 y_1],[x_1 x_2],[y_1 y_2],[x_2 x_3],[y_2 y_3]) %8%
        axis([-1 2 0 4]) %9%
        pause(0.5) %10%
        M(ct)=getframe(gcf); %11%
        ct=ct+1; %12%
    end 
end
movie(M) %13%
videofile=VideoWriter('Robotic_arm_forward_kinematics.avi','uncompressed AVI'); %14%
open(videofile) %15%
writeVideo(videofile,M) %16%
close(videofile) %17%

Stepwise Explanation;

1 - The following 3 lines are used to clear & close the previously existing codes & values.

2 - Next 5 lines are the fixed inputs required in the program, i.e, length of the links & angle value between the links.

3 - This is used to get different frames.

4 - For loop to generate the different positions of the link 1.

5 - For loop to generate the different position of link 2 with respect ot the link 1.

6 - Next 4 lines provide the initial fixed values for the plot.

7 - Next 4 lines provide the formula to obtain point values for X & Y in the plot.

8 - This is the command used to plot the lines in the figure window.

9 - This is used to define the graph size.

10 - This command is used to determine the animation time of the robot arm movement.

11 - M is an array to collect the different frames with the keyword getframe(gcf).

12 - This statement is used to increment the program or move to the next frame.

13 - This helps the program to understand that a movie needs to be created with the help of M array.

14 - Creation of videofile with help of VideoWriter command. The first value tells the file name in avi format & the second value tells the file format.

15 - This command is used to open the videofile.

16 - This command is used to create the animation in the video player.

17 - This command is used to stop & close the animation.

Animation Link : https://drive.google.com/file/d/1kyYpeeFSxhKQWYotUz_bNl8HicUMJQQR/view?usp=sharing

Errors Faced;

From the bottom 2 images, we can get to know that i faced an issue to create an animation of the robotic arm movement.

Steps taken to overcome the error;

Firstly, I referred the documentation article on videowrite to create the animation. After reading the article, I changed the above mentioned statement to;

  • videofile=VideoWrite('Robotic_arm_forward_kinematics','uncompressed AVI'); - made V & W capital in videowriter, changed .avi to AVI, added a semicolon after the statement.
  • open(videofile) - videofile was declared inside single inverted commas as a string value, therefore changed it into object by removing the single inverted commas.
  • writeVideo(videofile,M) - made V capital in writevideo.
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.