Challenge

Week 2- 2R Robotic Arm Challenge

Program to simulate the forward kinematics of a 2R robotic arm

Video link: https://youtu.be/RO_81efHii0

For the given problem and as stated in the video as well, I have considered a robotic arm with two links; one of which is hinged to the ground at one end and can rotate about this fixed point. The other link is connected to the end of this first link and is free to rotate about it. For the given conditions, I think of it to be a welding robotic arm. Now, since welding requires different positions for different joint configurations, I have taken angles between -45 and 60° (though not all welding positions are covered in this). Also, most fillet joints require an incident angle of 45°, hence the consideration of -45° for the initial position.

Understanding of the code:

So, at first the inputs as a raw data for processing need to be provided. They are: length of the links, position of initial points and the range of inclinations(wrt to ground) that both the links may assume as per the requirements. Then, the counter variable is set to 1 initially and then at the end of our iteration the counter is given an increment(of our will) to run the next iteration. Then we enter the for loop. Herein, we have a for-in-for loop where we provide conditions such that the link 2 will assume all its destined positions(n2) at each unique position of link 1(n1). But, what will those positions be? This is something that is answered by our 2nd set of inputs. These are computational equations showing coordinate positions of the end points of both the links. Next up is plotting all of this. The plot command is used to plot our end results. But, there are n1xn2 number of plots that are obtained and they don't look too attractive. To view it as a transition video, the getframe command is made use of, within the loop. For it, we also need to form an array of the n1xn2 plot figures, which here is given by M(ct). So, the movie needs to be named and saved with proper extensions and that is done outside of the loop.

Output:

The output firstly shows the animation and then plays the movie. Also, the video with specified name and extension gets saved in our working directory.

Errors faced:

1) Use of inappropriate variable, theta for THETA. Overcome by changing the same.

2) Calling a command by the wrong case letters, Movie for movie- changed it.

3) Naming the video file inappropriately, very basic indeed. Overcome by using a _ instead of space.

% Program to simulate the kinematics of a 2R Robotic arm (assuming a welding robotic arm)
% Inputs #1
L1 =1; % metre
L2 = 0.5; % metre
x0 = 0;
y0 = 0;
theta1 = linspace(0,90,15); % degrees
theta2 = linspace(-45,60,25); % degrees

ct = 1;  % Counter for increment per iteration

for i = 1:length(theta1) %Iteration 1
    THETA1=theta1(i);
    for j = 1:length(theta2)  %Iteration 2
        THETA2=theta2(j);
        % Inputs #2
        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([-1 2 -1 2])
pause(.03)
M(ct) = getframe(gcf);  % Converting array of plot figures to movie
ct = ct+1;  % Counter increment by 1

    end
end

movie(M)
videofile = VideoWriter('Forward_Kinematics.avi','Uncompressed AVI') % Naming and storing the movie
open(videofile)
writeVideo(videofile,M)
close(videofile)
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.