Project

Python program to simulate the forward kinematics of a 2R Robotic Arm

AIM : Python program to simulate the forward kinematics of a 2R Robotic Arm.

BACKGROUND : 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.

The forward kinematics problem is characterized by determining the final position and orientation of a link (e.g., anatomical landmark on the hand) with knowledge of the joint variables. One can think of the forward kinematics (sometimes called direct kinematics) as a black box that contains the necessary calculations for accepting joint coordinates as input, and producing position and orientation parameters as output, for any of the segmental links in the chain.

Manipulator fig.

In our analysis, we are simulating a 2 link, 3 joints robotic arm with a manipulator at the end effect.

SOLUTION ALGORITHM

  1. The programming code will be written in Sublime Text editor.
  2. The angles 1,2 and the lengths of the 2 links will be fed as the input.
  3. To simulate the movement of the end effector, the angles made by the links, namely, angle1 and angle2 will be varied over a range.
  4. The coordinates (x0,y0) of point 1 are taken at origin and hence (x0,y0)= (0,0).
  5. The coordinates of point 2 i.e. (x1,y1) are calculated using the formula,

x1= L1 * cosine(theta 1)

y1= L1 * sine(theta 1) ; theta1 = angle 1

  1. Similarly, the coordinates of point 3 i.e. (x2, y2) are calculated using the formula,

x2= x1 + L2 * cosine(theta 2)

y2= y1 + L2 * sine(theta 2) ; theta 2= angle 2

  1. After getting the coordinates the two links will be plotted on the same graph.
  2. To obtain a simulation, the angles theta1 and theta2 will be varied over a range.
  3. For each value of theta1, theta2 will be changed over the entire range, to obtain different positions of the manipulator at a particular angle theta1.
  4. The final output will be obtained in the form of an animation video clip.

PYTHON CODE :

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

By Abhishek Arora

"""

import math
import matplotlib.pyplot as plt 
import numpy as np

#input variables
#the manipulator has 2 arms and 3 joints

#length of first arm(in metres)
l1= 1

#length of second arm(in metres)
l2=0.5

#coordinates of first joint
x0=0
y0=0

#theta 1 and theta 2 are the angles made by the arms with respect to x axis

theta1= np.linspace(0,math.pi/2,10)
theta2= np.linspace(0,math.pi/2,10)

ct=1
for t1 in theta1:
	for t2 in theta2:
		x1=  l1*math.cos(t1)
		y1=  l1*math.sin(t1)

		x2= x1 + l2*math.cos(t2)
		y2= y1 + l2*math.sin(t2)
		
		#saving each file name with a different name
		filename= str(ct) + '.png'
		ct= ct+1

		#plotting the positions 
		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)

OUTPUT

The output is obtained in the form of an animated video clip which can be viewed from the youtube link below :

https://youtu.be/fO6vo2orBfY

NOTE

  • The angles theta1 and theta2 take 10 values each in the range of 0 to 90 degrees.
  • The length of the links are taken as 1 m and 0.5 m respectively.
  • The coordinates of point1 are taken at origin i.e. (0,0).
  • FFmpeg software is used to generate the video from the pictures using the following command in the command prompt.
  • Use the command only after getting into the parent folder where all the images have been saved in proper sequence.
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.