Project

2R Robotic Arm Challenge using Python

Objective:

The goal of this program is to make an animation that represents the forward kinematics of a 2R Robotic Arm Manipulator. I have done this successfully by using the following code mentioned in the below code block. I have used python as my programming language software to accomplish this task.

Project Statement:

To write a program in python to simulate the forward kinematics of a 2R Robotic Arm.

Create an animation file of the plot and upload an animation on Youtube and provide the Youtube link for animation in your report.

Introduction:

  • Kinematics: The kinematics describes the motion of points, bodies, and systems of bodies without considering the forces that cause them to move. In this case, we are discussing the links which majorly are in control of the motion and the movement. The degree of freedom of the body also plays a part in the kinematics of the object. The end effector attaches to the wrist of the robot arm and enables the general-purpose robot to perform a specific task.
  • Forward Kinematics: Forward kinematics refers to the process of obtaining position and velocity of end effector, given the known joint angles and angular velocities.

Diagram:

We can observe that there are four main components that are used in this diagram which complete the robotic arm. They are the links, connectors (such as pins), base, and the manipulator.

The links are the rigid members connecting the joints. The joints are the movable components of the robot that cause relative motion between adjacent links.

A manipulator is a device used to manipulate materials without direct physical contact by the operator. The applications were originally for dealing with radioactive or biohazardous materials, using robotic arms, or they were used in inaccessible places.

Code for the Program:

import math
import matplotlib.pyplot as plt

# Inputs 
l1 = 1
l2 = 0.5

# The number of instances
n_theta = 10

# Start and End values of theta
theta_start = 0
theta_end = math.pi/2

theta1 =[]
theta2 =[]

# Using for loop to generate the different theta values

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

# Base of the robot
x0 = 0
y0 = 0

# Count Time
ct = 1
for t1 in theta1:
	for t2 in theta2:
		# Link 1, Link 2 connector
		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)

		# Saving the file at each Frame

		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)

	

Procedure:

  1. Firstly, we choose our desired inputs such as the lengths of two links that are going to be used in this setup.
  2. Then, we create variables that store the values of the theta1 and theta2 from various values which vary from 0 to 90 degrees in this case and they are divided into 10 intervals each.
  3. There exists a variable 'ct' that is used to store the count value of the no. of frames when used in the for loop.
  4. Then we code the for loop such that each link is undergoing movements from 0 to 90 along with the other link being a part of it. (Ex: When the link 1 is at 0 degrees the link 2 must be able to complete the movement from 0 to 90 and then the link2 moves at an angle of 10 degrees the link 2 have to once again complete the movement from 0 to 90 degrees. This continues till both the links reach 90 degrees.)
  5. There are different parameters that are taken into account such as the coordinates of the (x0,y0)(x1,y1)(x2,y2).
  6. Then we plot the graph with a line that exists between (x0,y0)(x1,y1), and then it is connected with another line between (x1,y1)(x2,y2) which are represented by the lines red and green respectively.
  7. In the end, the code for saving each frame in png format is written for the python which is, later on, join together to form a video for which I have attached the gif file below.
  8. There haven't been any errors that occurred while running or executing the code.

Result:

Conclusion:

The 2R Robotic Arm is successfully simulated as we can observe from the above animation.

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.