Project

KINEMATICS OF 2R ROBOTICS ARM USING PYTHON

AIM

To write a code in Python for the Forward Kinematics of a 2R Robotic Arm.

OBJECTIVES OF THE PROJECT

To see how the links are moving for different values of angle in the Forward Kinematics of a 2R Robotic Arm.

BODY OF CONTENT

Introduction

A robotic arm (not robotic hand) is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.

STEPS OF PROGRAM

  1. Provide topic of the code which is under comment
  1. Calling of library which will used for plotting and calculating i.e. math and matplotlib.pyplot library.
  1. Providing input data here L1 and L2 is the length of link of robotic arm, x0 and y0 is the initial point of the link 1 and n_theta is the no. of thetas.

Provide the start and end value of theta.

  1. Creating a empty array for storing data which is named as theta 1 and theta 2.
  1. By the help of for loop we calculate and stored the value of theta inside the empty array i.e. theta1 and theta2 by the help of append command.

6. Now ct is the variable which starts from 1

  1. Now the 2 for loop is used one for theta 1 and another for theta 2. After that these for loops helps in calculating the x and y coordinates of the link 1 and link 2
  1. After that giving the name of each of the files to make an animation. Here animation is the file name, %03d is the image having no. with 3 digit and .png is the file format.
  1. ct increment is used for increasing it by factor 1 which helps in plotting and giving name of the file.

For defining the figure we used plt.figure() where plt is library which is used and after that plotting of image is done. At last there is the defining of x and y limit of the plot is written in the code.

  1. At last we need to save all the plot which we have made inside the for loop.

STEPS FOR MAKING ANIMATION

  1. First install the imagemagick software from the internet.
  2. After installing open the command prompt from the run option. The command prompt display will be appeared.
  1. Copy the location of the file where you have saved all the image as shown in the figure below.
  1. Now open the command prompt and give command in the format cd<SPACE>(copy and paste the file directory where all the plots are saved) and press enter
  1. After that write dir in order to check the directory is correct or not after that all the images file name will be displayed.
  1. After that write the command magick *.png merge.gif . After that wait for some time until next line will not appear in the command prompt screen.

Where,

magick ==> Calling the software

* ==> All

.png ==> search only for the .png files in the folder

output ==> Name of the output file (it can be anything)

.gif ==> format of the file

  1. After that you see that merge file of gif is made in the same folder as shown in the figure. So merge file is the animation of the image.

Program for Kinematics of 2R Robotic Arm

"""
Forward kinematics of 2R robotic arm
"""

#importing of math and matplotlib library
import math
import matplotlib.pyplot as plt

#input of the robotic arm
#L1 is link 1 and L2 is link 2
l1 = 1
l2 = 0.5

#initial point of link 1
x0 = 0
y0 = 0

#no. of thetas
n_theta = 10

#Staring point of theta from 0 and end point is 90
theta_start = 0
theta_end = math.pi/2


#Empty array of theta 1 and 2
theta1 = []
theta2 = []

#for loop i starts from 0 to n_theta which is 100
for i in range(0,n_theta):
	
	#temp is local name for calculating theta values
	temp = theta_start + i*(theta_end-theta_start)/(n_theta-1)

	#Storing of theta values from temp in theta 1 and 2 by the help of append command
	theta1.append(temp)
	theta2.append(temp)


#ct is count variable which starts from 1
ct =1

#for loop of theta1 in t1 used in the for loop
for t1 in theta1:
	
	#for loop of theta2 in t2 used in the for loop
	for t2 in  theta2:

		#Length and coordinate of link 1 
		x1 = l1*math.cos(t1)
		y1 = l1*math.sin(t1)

		#coordinates of the manipulator
		x2 = x1 + l2*math.cos(t2)
		y2 = y1 + l2*math.sin(t2)


		#Getting image of all the values of thetas and make the image as animation xxx.png
		filename = 'animation %03d.png' %ct
		
		#increament of count variable
		ct = ct + 1
		
		#plot of figure
		plt.figure()
		
		#plotting of x0,y0, x1,y1, x2,y2 coordinate
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		
		#defining the limit of x and y axis
		plt.xlim([0,2])
		plt.ylim([0,2])
		
		#saving of image 
		plt.savefig(filename)



	

ERROR OBTAIN WHILE PROGRAMMING

  1. By typing mistake I wrote the filenam instead of filename the program not work properly.

GIF OF KINEMATICS OF 2R ROBOTIC ARM

CONCLUSION

The aim of this project is to study the motion kinematics of a 2R robotic arm by providing the values of l1, l2 and for different values of angle we get the combination of plot to make the animation of the motion kinematics of 2R robotic arm.

I have made the program by the help of using for loop.

YOUTUBE LINK

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.