Week 2- 2R Robotic Arm Challenge
Object:
write a program in Matlab to simulate the forward kinematics of a 2R Robotic arm and Create an animation file of the plot
Code:
clear all
close all
clc
%input
l1=1;
l2=0.5;
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);
xo=0;
yo=0;
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
%plotting
plot([xo x1],[yo y1],[x1 x2],[y1 y2],'LineWidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile = VideoWriter('forward_kinamatics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Output:
Drive link:
https://drive.google.com/file/d/1NnKAzZ1C2-iwLIYbcolDlZ4S7bcADfAP/view?usp=sharing
Drive link:(screen record)
https://drive.google.com/file/d/1aZEeoM-LmhaaSCq-edr9t18HJxGU1KkC/view?usp=sharing
Youtube link:https://youtu.be/1vPoHKDF5nA
Report:
%Input
The length of the first arm is taken 1m, the length of the second arm is taken 0.5m, theta1 is the angle between the X-axis (Xo, Yō) to Y-axis (X1, Y1) of the first arm and theta2 is the angle between X-axis (X1, Y1) to Y-axis (X2, Y2).
Theta1 and Theta2 was taken in linspace of 0 to 90 differences of 10 that should be theta1 is linspace(0,90,10) and theta2 is linspace(0,90,10) and counter should be 1.
For loop
For statements loop a specific number of times and keep track of each iteration with an incrementing index variable.
Using for loop I should be taken as 1 to the length of theta1 that is THETA1= theta1(I) same as j=1 to a length of theta2 that is THETA2= theta2(j).
The starting point of the first arm is Xo, Yō and the ending point of the first arm is X1=length1*cosd(THETA1), Y1= length1*sind(THETA1), and the starting of the second arm X1=length1*cosd(THETA1), Y1= length1*sind(THETA1) and the ending point of second arm X2=X1+length2*cosd(THETA2), Y2=Y1+length2*sind(THETA2).
Plotting
Polt should represent the whole arm is as the plot ([Xo, X1], [Yo, Y1], [X1, X2], [Y1, Y2]) and the linewidth is 3.
Axes are taken as axis (-0.1 1.5 0 1.5), pause off 0.03 is slow down the speed of movement and the counter should be taken as CT=ct+1.
Creating the plot animation to use M(CT)= getframe(gcf) and the file should be saved as forward_kinematics.avi is as saved in video format


when I run the program I didn't face any errors in the program and the command window was showed an empty error
