Challenge

Week 3.2 - 2R Robotic Arm Challenge

Code:

clear all
close all
clc

%Inputs
l1 = 1;    %Length of one arm
l2 = 0.5;  %Length of second arm
theta1 = linspace(0,90,10);   %Creating points for theta1
theta2 = linspace(0,90,10);   %Creating points for theta2

ct = 1;  %Variable for frames

for i = 1:length(theta1)   %For loop
    theta1_1 = theta1(i);  
    for j = 1:length(theta2)  %For loop
        theta2_1 = theta2(j);

        x0 = 0;   %Origin
        y0 = 0;

        x1 = l1*cosd(theta1_1);  %calculating the end of first rod
        y1 = l1*sind(theta1_1);

        x2 = x1 + l2*cosd(theta2_1); %Calculating the end of second rod
        y2 = y1 + l2*sind(theta2_1);

        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)  %Plotting the points
        axis([-0.1 1.5 0 1.5])  %Confining the axis
        pause(0.03) %Pause

        M(ct) = getframe(gcf);  %Capturing the frames
        ct = ct+1;
        
    end
end

%Making the movie
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Explanation:

The equations are derived from the kinematics to solve the moment of the arm and plotted the endpoints of the first stick and the second stick. The nested for loop is used to calculate the position. Each instance was captured and added to make the video which is linked below.

Error:

the error was caused by capitalizing the letter 'M' in the movie.

Result:

Video Link: https://youtu.be/F8ydwFHlpVI

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.