Forward Kinematics of a 2R Robotic Arm in Python

Objective:

The project involves simulating a 2-joint robotic arm.

 

Code and Description:

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

# Lengths
l1 = 1
l2 = 0.5

# Angles

ang1 = nm.radians(nm.linspace(0, 90, 19))
ang2 = nm.radians(nm.linspace(0, 90, 19))

# Origin
x0 = 0
y0 = 0

count = 1

for a1 in ang1:
	for a2 in ang2:
		# Link 1
		x1 = l1*nm.cos(a1)
		y1 = l1*nm.sin(a1)

		# Link 2
		x2 = x1 + l2*nm.cos(a2)
		y2 = y1 + l2*nm.sin(a2)

		filename = 'arm_' + str(count) + '.png'
		count = count + 1

		plt.figure()
		plt.plot([x0, x1], [y0, y1])
		plt.plot([x1, x2], [y1, y2])
		plt.xlim([-0.25, 1.5])
		plt.ylim([0, 1.5])
		plt.savefig(filename)

Firstly, we are going to run the simulation for positions of the arm at angles from 0 to 90 degrees. Lengths are taken as 1 and 0.5. 

Angle 1 is the angle of the base link 1 and angle 2 is that of link 2, connected to the manipulator. We are simulating positions at every instance of angle 1 of link 1.

The inside nested loop simulates link 2, that is, the manipulator-connected-link, by plotting it's position at different inclinations for a single inclination of link 1. The positions are calculated and lines are plotted, which become the arms.

Animation is then saved using savefig to print multiple images, and then an mp4 video is compiled using imagemagick:

magick arm_%d.png[1-361] 2RRobotArmAnimPython.mp4

(361 frames were generated and then compiled)

 

Output screenshot:

 

 

Errors and Correction:

Below are some errors:

1. math lib instead of numpy

Solution: numpy called and used

 

2. Syntax error in plot command

 

Solution: added commas

 

Below is the animation of the code.

2R Robotic Arm Simulation


Projects by Arjun Bhat

This project explores the simulation of the motion of a pendulum for the equation of damped vibration of a pendulum. Below is the equation (taken from "Challenges" page): The above equation is solved using ODE function, and then odeint is used to get an ar Read more

Project involves plotting an Otto Cycle graph in MATLAB The goal is to plot all strokes for a petrol operating by the otto cycle from intake, compression, power to exhaust, including both adiabatic curves. Description: The Otto Cycle is the idealised cycle that descr Read more

Flow over bicycle in Python
Arjun Bhat · 2019-11-18 16:09:30

Objective: To calculate the drag force for various drag coefficient and velocity values for a certain geometry.   Introduction: Drag force is the force exerted by the air as the vehicle moves through it. The force exerted is directly proportional to the square Read more

Aim: To parse the NASA Thermodynamc Properties data file, calculate thermodynamic properties and plot the characteristics. Introduction: NASA's thermodynamic properties file consists of multiple species of gases, their respective operating temperature ranges, and Read more

The project aims at optimization of a stalagmite function and finding the global maxima. For this, we will be using the concept of genetic algorithm. Following are the steps used to optimise the function: Code the function given in a separate function code. This is Read more

Curve Fitting using MATLAB
Arjun Bhat · 2019-08-19 20:20:53

Project aims at finding the best fit curve for a given data and finding the error between the original and said curve. The data being used is that of Specific heat (Cp) vs Temeperature. Plot will be made to show variation of Cp with Temp first.  Code: % Data cp Read more

This project explores the simulation of the motion of a pendulum for the equation of damped vibration of a pendulum. Below is the equation (taken from "Challenges" page): An attempt is made to solve the above equation, and then call it using ode45 to get an array of Read more

Project involves plotting an Otto Cycle graph in MATLAB The goal is to plot all strokes for a petrol operating by the otto cycle from intake, compression, power to exhaust, including both adiabatic curves. Description: The Otto Cycle is the idealised cycle that descr Read more

Code and Description: The project involves simulating a 2-joint robotic arm. % Lengths l1 = 1; l2 = 0.5; % Angles ang1 = linspace (0, 90, 20); ang2 = linspace (0, 90, 20); count = 1; % loop for i = 1:length(ang1) ANG1 = ang1(i); for j = 1:length(ang2 Read more


Loading...

The End