Project

Program in python to simulate the forward kinematics

AIM: Write a program in python to simulate the forward kinematics of a 2R Robotic Arm

THEORY -
2R Robotic Arm- A robotic arm is a type of mechanical arm, usually programmable. The arm may be the sum total of the mechanisms or may be part of a more comple robot. The links of such a manipulator are connected by joints allowing either rotational motion or linear displacement. the links of the manipulator can be considered to form a kinematic chain. the terminus of the kinematic chain of the manipukator is called the end effector. An end effectror is the device at the end of a robotic arm, designed to interact with the environment.
The Kinematic analysis is the relationships between the positions, velocities and accelerations of the link manipulator. The kinmenatics separate in two types, direct kinematic and inverse kinematics. In Forward kinematics, the length of each link and the angle of each joint is given & we have to calculate the position of any point in the work volume of the robot. In Inverse Kinematics, the length of each link & position of the point in work volume is given & we have to calculate the angle of each joint.
In this project, we consider a 2R robotic arm with two rotations i.e. it has two links which rotate or work over a 2-D planee with each of link having a single degree of freedom.

As shown in figure a 2R robotic arm with its dimensions and coordinates shown here.

where,

Xo=0,Yo=0Xo=0,Yo=0

X1 =L1.cos(θ1) Y1=L1.sin(θ1)X1 =L1.cos(θ1) Y1=L1.sin(θ1)

X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)X2=X1+L2.cos(θ2) Y2=Y1+L2.sin(θ2)

PYTHON PROGRAM TO SIMULATE THE 2R ROBOTIC ARM

#PROGRAM TOo SIMULATE THE 2R ROBOTIC ARM

import math
import matplotlib.pyplot as plt

#Inputs
l1 = 1.2
l2 = 0.6

#Thetas
n_theta = 10

theta_start = 0
theta_end = math.pi/2

theta1 = []
theta2 = []

for i in range(0,n_theta):
  tmp = theta_start + i*(theta_end-theta_start)/(n_theta-1)
  theta1.append(tmp)
  theta2.append(tmp)


#Initial coordinate points
x0 = 0
y0 = 0

#Loop creating 100 values
ct = 1
for t1 in theta1:
  for t2 in theta2:
    # Link1, link2 connector
    x1 = l1 * math.cos(t1)
    y1 = l1 * math.sin(t1)
    
    #Coordinate points of the manipulator
    x2 = x1 + l2 * math.cos(t2)
    y2 = y1 + l2 * math.sin(t2)
    
    filename = str(ct) + '.png'
    ct=ct+1
    plt.figure()
    plt.plot([x0,x1], [y0,y1])
    plt.plot([x1,x2], [y1,y2])
    plt.xlim([0,2])
    plt.ylim([0,2])
    plt.savefig(filename)


Explanation to the Code

  • Importing math and plot function.
  • The lengths of the link1 and link2 are given as 1.2 m and 0.6 m respectively
  • Then no of theta values for which the simulation to be done is given as 10
  • The limits for the theta should be given (ie) the starting and ending value of theta. Between the starting and ending value of theta, there will be ten No. of values.
  • The starting value of theta is 0 and the ending value of theta is 90
  • For calculating the ten values between the starting and ending, ‘for loop’ is used.
  • For both the thetas separate empty array is created and using ‘append’ command the values are stored in the respective arrays the coordinates of the starting point of the first link are (0,0)
  • The coordinates of the ending point of the first link are calculated by means of angle theta. As there are different values of theta another ‘for loop’ is created to calculate the coordinates
  • Assigning a name to the output plot by converting it to a string function and storring all the output plots.
  • To obtain plots, the counter variable is used. Then using plot command the coordinates are plotted and there should be 100 plots
  • Then all the 100 plots are stitched and an animation file is created by selecting all the images and converting them into a video.



Conclusion- The animation google drive link of the 2R robotic arm given below


https://drive.google.com/file/d/1X-wgoW51J_h_BWx9l5ROLQEsaJbWFl1b/view?usp=sharing

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.