Project

Robotic Arm Simulator

A robot with two links with length l1 and l2, and having an angle between them are `theta1` and `theta2`with respect to X-axis:

In this simulation, the various angle for the robotic link had been calculated using Python

The module used in the python is:

1)"matplotlib" for plotting

2)"math" for mathematical operation

Running the Code:

The code will save all the figure into the folder, to change the figure to gif, Imagemagik is used.

Typing the following command in the terminal at the path where the figures are saved

"convert *.png output.gif"

code :

import math
import matplotlib.pyplot as plt

n_theta = 10

theta_Start = 0
theta_end = math.pi/2

theta1 = []
theta2 = []


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

#inputs
l1 = 1;
l2 = 0.5;
#base of the robot
x0 = 0
y0 = 0

ct = 1

plt.figure()

for t1 in theta1:
    for t2 in theta2:
        #link 1 end point (x1,y1)
        x1 = l1 * math.cos(t1)          #end point of the link 1
        y1 = l1 * math.sin(t1)          #end point of the link 1

        #link 2 end point (x2,y2)
        x2 = x1 + (l2 * math.cos(t2))
        y2 = y1 + (l2 * math.sin(t2))

        filename = str(ct) + ".png"
        ct += 1

        #plotting
        plt.clf()                       #Erase the previous plot on the figure
        plt.plot([x0,x1],[y0,y1])
        plt.plot([x1,x2],[y1,y2])
        plt.xlim([0,2])
        plt.ylim([0,2])
        plt.pause(0.01)
        plt.savefig(filename)

Similarly, for the 3 arm robotic manipulator

import math
import matplotlib.pyplot as plt

n_theta1 = 5
n_theta2 = 10

theta_Start = 0
theta_end = math.pi/2

theta1 = []
theta2 = []
theta3 = []


for i in range(0,n_theta1):
    tem = theta_Start + i*(theta_end - theta_Start)/(n_theta1-1)
    theta1.append(tem)
    theta2.append(tem)

for i in range(0,n_theta2):
    tem = theta_Start + i*(theta_end - theta_Start)/(n_theta2-1)
    theta3.append(tem)

#inputs
l1 = 1;
l2 = 0.5;
l3 = 0.3;
#base of the robot
x0 = 0
y0 = 0

ct = 1

#plt.ion()                               #interation plot on
plt.figure()

for t1 in theta1:
    for t2 in theta2:
        for t3 in theta3:
            #link 1 end point (x1,y1)
            x1 = l1 * math.cos(t1)          #end point of the link 1
            y1 = l1 * math.sin(t1)          #end point of the link 1

            #link 2 end point (x2,y2)
            x2 = x1 + (l2 * math.cos(t2))
            y2 = y1 + (l2 * math.sin(t2))

            #link 3 end point (x3,y3)
            x3 = x2 + (l3 * math.cos(t3))
            y3 = y2 + (l3 * math.sin(t3))


            filename = str(ct) + ".png"
            ct += 1

            #plotting
            plt.clf()                       #Erase the previous plot on the figure
            plt.plot([x0,x1],[y0,y1])
            plt.plot([x1,x2],[y1,y2])
            plt.plot([x2,x3],[y2,y3])
            plt.xlim([0,2.5])
            plt.ylim([0,2.5])
            plt.pause(0.01)
            plt.savefig(filename)

Path of the arm:

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.