Simulate forward kinematics of 2R Robotic Arm
Aim:-To simulate forward kinematics of Robotic Arm
Objective:-
- To show the region which can be covered by the manipulator by pivoting across the robotic arm.
Robotic Arm is used where repetitive motion is required and the skill required to complete the task is less.Robots saves manpower required for the job; even though of their initial costing they can work continuosly without interference .Before assigning them to their work it is feasible to test simulate this robots so as to know the region it can cover so as to decide its functionality accordingly.Also it gives the layout of safety structure to built so as to prevent human injury.
Fig 1. Block diagram of the Robotic manipulator
Explanation of code:-
- Considering point 1 of link 1 fixed so its co-ordinates x0 and y0 will always be 0.
- Considering length of link 1 and link 2 ,1m and 0.5m respectively.
- Considering θ1 as the angle made by link 1 with reference to fixed frame and θ2 as the angle made by link 2 with same reference.
- Also the ending co-ordinate of link 1 is starting co-ordinate of link 2.
- Linspace command is use to assign equally spaced values of theta (from 0 to 90 degree)in 10 equal parts.
- for loop is used to assign different values of theta genearted by the linspace command one after the other.
- One for loop is inside other for loop so when the outer for loop is executed it goes into the inner for loop and until the entire inner for loop is not complete it does not come out.
- So there are total 100 results due to as Outer for loop puts a value of theta and then inner for loops produces 10 values.Thus for 10 values of outer loop total 100 values will be produced.
- Line command was used previously to draw a link in between the defined points which was changed to plot command ; as line command used to give multiple plots of the results.
- In plot command we get the single result of how the link is moving as the for loop is getting executed .
- Hold on command is necessary when using plot otherwise it only shows the latest plot and erases the previous results.
- Pause command haults the execution of the program temporarily (0.1sec).
- Axis command is used to fix the axis while showing the output taking x array and then y array [ x x y y ]
- ct is counter used to get the figure of the result and ct=ct+1 is used in the for loop to get the next subsquent image inorder to create an animation
- Array M(ct) creates a movies on the individual frames that are captured.
- movie(M) is used to make movie with all the frames and videofile command is used to create and save the file in windows directory.
Assumptions:-
x0=0;
y0=0;
l1=1m;
l2=0.5m;
Ending Co ordinates (x1,y1) of link no1 is starting co-ordinate of link no 2
%Kinematics of Robotic Arm
clear all
close all
clc
%Inputs
ct=1;
l1=1;
l2=0.5;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%Coordinates
for i=1:length(theta1);
THETA1=theta1(i);
for j=1:length(theta2);
THETA2=theta2(j);
x0=0;
y0=0;
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1+12*cosd(THETA2);
y2=y1+l2*sind(THETA2);
%Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis ([-1.5 1.5 0 1.5]);
pause(0.1);
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)
Link to the Animation is as below:-
Error encountered while coding are as follows:-
- Forgot to type * symbol in defining x1 and y1 thinking that it by default takes multiplication into account if written together.
Fig. Forgot multiplication symbol (*)
2.Wrong arrangement of co-ordinates of robotic arm where array [x,y] of link 1 was to be mentioned and then of link 2
Fig .Wrong arrangement of array co-ordinates of links.
Conclusion:- Animation was perfomed so as to the show the various area that can be covered by the manipulator in doing the task that is intended.