Project

Python Project 2 : 2R Robotic Arm Simulation

Objective : To simulate 2R robotics arm by using Python.

Problem Statement :-

Write a program in MATLAB to simulate the forward kinematics of 2R Robotic Arm.

Theory :-

Forward kinematics :-

Forward kinematics refers to the use of the knematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.

The kinematics equations of therobot are used in robotics, computer games, and in animation. The reverse process that compuyes the joint parameters that achieve a specified position of the end effector is known as inverse kinematics.

2R Robotic Arm :-

2R robotic arm ia a robotic arm with two degree og freedom. 2R robotic arm has two links which rotate in a two dimensional plane with each of links have a single degree of freedom.

A 2R robotic arm is shown in figure.

In the figure 2R robotic arm is shown. This arm contain two links, link 1 and link 2, the length of tese both links are l1 and l2 respectively. It is consider that link 1 is fixed to the horizontal and making an angle θ1 with horizontal. One end of link 2 is connected to link 1 and make with horizontal θ2.

It is consider that the start point coordinate of link 1 is (X0, Y0) and end point coordinate of link 1 is (X1, Y1). similarly for link 2 start and end point coordinates are (X1, Y1) and (X2, Y2), respectively.

Let X0 = 0 and Y0 = 0.

From figure and use of trigonometry formula we can say that

X1 = l1. Cos (θ1) Y1=l1. Sin (θ1)

X2=X1+l2. Cos(θ2) Y2=Y1+l2. Sin(θ2)

By using this equation we will solve the problem.

Procedure to create Python program :-

To solve this problem first we provide some input data. This input data contain Arm length (l1 and l2), angle (θ1 and θ2) and the position of absolute coordinate(X0, Y0). After giving this data we will calculate the value of the other coordinates by using above equation. To calculate the values of the coordinate for different angles we will use for loop. By using the for loop we get position of the links for different angles. By using plot command we will get graphical form of data. This graphical data is save by threre figure name and then we combine those figure to get animation of the robotics arm.

Python program :-

Google colab is use by me for programming.

"""Animation of 2R Robotic Arm Challenge"""
# Import library
import math
import matplotlib.pyplot as plt

# Input Arm length
l1 = 2
l2 = 1.5

# Theta start and end values
theta_start = 0
theta_end = math.pi/2

# Number of theta values
n_theta = 10

# Define Angle variable
theta_1= []
theta_2= []

# Input Position of (x0,y0)
x0 = 0
y0 = 0

# Values of angle find out
for i in range(0,n_theta):
    theta_value = theta_start+i*(theta_end-theta_start)/(n_theta-1)
    theta_1.append(theta_value)
    theta_2.append(theta_value)

# A constant for getting movie frame.
k=1

# Calculate (x1,y1)   
for i in theta_1:
    # Calculating x2, y2 for corresponding theta2 by taking theta 1 value one by one
    for j in theta_2:
             
        # Calculate coordinates (x1, y1)
        x1= l1* math.cos(i)
        y1= l1* math.sin(i)

        # Calculate (x2,y2)
        x2= x1 + l2*math.cos(j)
        y2= y1 + l2*math.sin(j)
    
        # Define plot file name for generate animation
        filename = str(k) + '.png'
        k=k+1
        print(filename)
        
        # Plot of robotics arm
        plt.figure(1)
        plt.plot([x0,x1], [y0,y1],'r')
        plt.plot([x1,x2], [y1,y2],'b')
        
        # Plot axis limit
        plt.xlim([0,5])
        plt.ylim([0,5])
        
        # Save plot figure
        plt.savefig(filename)

Screenshot of Output:- (100 figures are generated)

Animation Video Link:-

By using online software the animation of 2 R Robotics arm is generated using the image file generated through python programming.

Conclusion:-

By this project successfully program the 2R robotic arm and get the animation of the arm.

END.

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.