Challenge

Week 2- 2R Robotic Arm Challenge

                                                   Aim of the assignment

To write a program in matlab to simulate the forward kinematics of a 2R robotic arm

Introduction

Kinematics is the relationships between the positions, velocities and accelerations of the links of a manipulator

The forward kinematics is when the kinematical data are known for the joint coordinates the variables of the end effector in a given cartesian space are to be computed.

Robotic arms are machines that are programmed to execute a specific task or a job quickly efficiently and extremely accurately generally motor driven they are most often used for rapid consistent performance of a heavy and or highly repetitive procedures over extended periods of time and especially valued in the industrial production manufacturing machining and assembly sectors.

A robotic joint provides relative motion between 2 links of the robot each joint or axis provides a certain degree of freedom of motion in most cases only one degree of freedom is associated with each joint therefore the robots complexity can be classified according to the total number of degree of freedom they possess.

The given figure shows the basic join link scheme for a robot manipulator

fig 1:basic join link scheme for a robot manipulator

The figure shows the formulas for calculating the forward kinematics of a 2 link robotic arm

fig 2:formulas for calculating the forward kinematics of a 2 link robotic arm

As we see in the above formula the position for  xj,yj  has to be calculated using trigonometry,     xg= length of the first  link arm*cos( angle of the first  link arm) the same process is applied to find yg,yg =length of the first link arm* sin( angle of the first link arm).

SAMPLE PROGRAM FOR KINEMATICS OF A ROBOTIC ARM

%KINEMATICS OF A ROBOTIC ARM

clear all
close all

%inputs
%lengths of the link l1 & l2
l1=4;
l2=3;

%angles made by the links
theta1=linspace(0,90,30);
theta2=linspace(0,90,30);

%looping
ct=1; %counter
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',2)
grid on
axis([-0.1 8 -0.1 8])
pause(.1)
m(ct)=getframe(gcf);
ct=ct+1;
end
end

%animation
movie(m);
videofile=VideoWriter('robotic_.avi','uncompressed AVI');
open(videofile);
writeVideo(videofile,m);
close(videofile);

The screenshots of the program has been given below and the workspace values obtained are also provided as screenshots.

CODE EXPLANATION

We start with clear all and close all commands

Clear all- removes data from the workspace , freeing up the system memory

Close all-deletes the current figure or the specified figure

Next step for the code is to define the input inputs and its values. Length of arm one an arm two were both defined they were given the names L1 and L2 respectively. The theta 1 and the theta 2 were also defined for the respective angles made by L1 and L2. Both the angles where defined by using linspace command the function linspace generates linearly spaced vectors so in this case Theta 1 and Theta 2 were given link space of (0, 90, 30). The given line space of (0, 90, 30) means that the math lab will generate a row vector of 90 of 10 points linearly space between and including 0 and 90.

The next step is to set up a counter,the counter is a variable that counts an event in a loop. A for loop was used for this assignment a for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

Since theta 1 and theta 2 will contain multiple values of the angles within the x axis a new variable is needed inside the for loop for both x and y coordinates. THETA 1 and THETA 2 are added to the code for THETA 2 the variable j was added instead of I as this will leave THETA 2 its own respective angle the formula for calculating x1,y1,x2 and y 2 are shown in the figure above.

Once the for loop was completed it is time to plot a graph for the x & y coordinates as shown in the figure A pause command was also introduced for posing the command for a certain period of time, in this assignment I used a pause time of 0.1 seconds. The M command was used to capture the current frame every time the loop runs.

The final step of the loop was to add a +1 to the counter variable, this will increment the frame every time for the loop run in command was used for the plot and for the loop to stop both from running.

The final step of the code is to create a movie of the animation of the robotic arm, so the movie command was used the VideoWriter command was used to obtain the video format, for the assignment .avi was used as a format. The open command was used to open the video. writevideo commands was used to write the video from the plot frames. Finally the close command was used to close the video file.

Errors faced in the program

No major error occurred but faced difficulty in saving the output in the animation or movie format. The doubt was finally cleared with the help of a support engineer who guided me for the same.

Animation Video

Here is the link of the animation ,the result of which I got for this assignment.

https://youtu.be/5BR4pJi_x6Y

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.