Project

2-R Robotic Arm Simulator

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

GOVERNING EQUATIONS: Basic math concepts like the resolution of vectors and locating coordinates the specific points in the plane.

OBJECTIVES OF THE PROJECT: The main objective of this project is to create the animation of the 2-R robotic arm.

PROGRAMMING LANGUAGE USED: PYTHON

create a new file with an extension .py as forward_kinematics.py

#Forward kinematics of the 2R Robotic arm
import math
import matplotlib.pyplot as plt
import numpy as np



#lengths of the rombotic links
l1 = 1
l2 = 0.5
#The position of the links in terms of angle theta
theta1 = np.linspace(0,90,10)
theta2 = np.linspace(0,90,10)

#We are going to plot the arm using coordinates
#fixed cooerdinates
x0 = 0
y0 = 0

ct = 1
#use for loop for changing the angles 
for i in theta1:
	x1 = l1*math.cos(np.deg2rad(i))
	y1 = l1*math.sin(np.deg2rad(i))

	for j in theta2:
		x2 = x1 + l2*math.cos(np.deg2rad(j))
		y2 = y1 + l2*math.sin(np.deg2rad(j))

		filename = 'test%05d.png' % ct
		ct = ct +1 

		#plotting
		plt.figure()

		plt.plot([x0,x1],[y0,y1],[x1,x2],[y1,y2])
		#add title
		plt.title('robotic arm simulation')
		#set the axes for better visibility and clear view 
		plt.xlim([-0.05,2])
		plt.ylim([-0.05,2])
		#save the figure everytime after the completion of the loop
		plt.savefig(filename) 

EXPLANATION TO THE CODE:

  • import modules like math, matplotlib, numpy.
  • Initialize the lengths of the links with l1 and l2 with respective values.
  • use the linspace to get different angles and store them in variables theta1 and theta2.
  • use the for loop to pass the values of theta one by one.
  • locate the coordinates with the help of link lengths and thetas
  • join these points to form a line using plot function
  • add the additional details like axes and title to provide a better understanding
  • save the figure and make use it to create an animation using ImageMagick

ERRORS: An indentation error and spelling mistakes which can be overcome through practice.

RESULT: the link for the animation is given below

https://youtu.be/MFh8e9mkhRc

The animation is done using the ImageMagick software

cmd: magick *.png output.gif

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.