Challenge

Week 3.2 - 2R Robotic Arm Challenge

A program in Matlab to simulate the forward kinematics of a 2R Robotic Arm:

Pseudocode for the forward kinematics of a 2R Robotic Arm:

1. Clear all variables and close all figures
2. Set values for l1, l2 and ct
3. Create a range of values for theta1 and theta2
4. For each value in theta1:
    a. Set THETA1 to the current value of theta1
    b. For each value in theta2:
        i. Set THETA2 to the current value of theta2
        ii. Calculate x0, y0, x1, y1, x2 and y2
        iii. Plot the lines connecting (x0,y0) to (x1,y1) and (x1,y1) to (x2,y2)
        iv. Set axis limits
        v. Pause for 0.03 seconds
        vi. Store the current frame in M
        vii. Increment ct by 1
5. Play the movie stored in M
6. Create a video file named 'forward_kinematics.avi'
7. Open the video file
8. Write the movie stored in M to the video file
9. Close the video file

This is the code for the above mentioned pseudocode for the forward kinematics of 2R Robotic arm:

clear all
close all
clc

%inputs
l1=1;
l2=0.5;

%angle
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

ct=1
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
        THETA2=theta2(j);
        %coordinates
        x0=0
        y0=0

        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',3);
        axis([-0.1 1.5 0 1.5])
        pause(0.01)
        M(ct)=getframe(gcf);
        ct=ct+1
    end
end
movie(M)
videofile=VideoWriter('forward_kinematics.avi','uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

In this case :

  • Assign the length of the 2 arms for the kinematics of the 2R Robotic arm.
  • Assign the angle for the arms for the rotations the arm.
  • Calculate the end coordinates of the 2R robotic arms for plotting the graph.
  • Plot the result in the graph and pause it 0.01 seconds
  • Capture the frame with the help of M command
  • Create a video file of the output for 2R robotic arm.

Errors :

  • The error I have faced was the grammatical mistake of the "uncrompessed" function
  • Due to that I cannot able to provide the animation for the output.

Ater that I have rectified it and then I can able to prduce the video of the output.

Below is the animation link:

https://drive.google.com/file/d/1fuau2rAVjvXeNy8OT7UYFQnIOgbzzATg/view?usp=sharing

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.