## 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:
x1 = l1*nm.cos(a1)
y1 = l1*nm.sin(a1)

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

Below is the animation of the code.

2R Robotic Arm Simulation

### Simulating the motion of a pendulum using 2nd order ODE in Python Arjun Bhat · 2019-12-09 17:11:02

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

### Air standard cycle graph plotting in Python Arjun Bhat · 2019-11-20 17:11:18

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

### Parsing NASA Thermodynamic data for multiple specified Gas Species and Calculating the Thermodynamic Properties Arjun Bhat · 2019-09-11 20:25:18

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

### Optimization of a function using Genetic Algorithm in MATLAB Arjun Bhat · 2019-09-03 08:51:45

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

### Simulating the motion of a pendulum using 2nd order ODE in MATLAB Arjun Bhat · 2019-08-13 18:30:48

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

### Plotting of an Otto Cycle graph in MATLAB Arjun Bhat · 2019-08-12 19:40:08

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

### 2R Robotic Arm Simulation using MATLAB Arjun Bhat · 2019-07-28 08:19:59

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