NN Project
NN Project
Introduction
In robotics design there are two main things that you want to calculate: the
forward kinematics and the inverse kinematics. The forward kinematics is
getting the position of the end effector of the robot from knowing the position of
each joint and the inverse as its name says its knowing the position of each joint
having the end effector position
Development
For this project we are controlling an industrial assembly robot that is intended
to work in their 4 front octants
For the database we calculated approximately 5 million values of X-Y-Z
coordinates of the end effector and their respective joint angles all of these
inside the intended working area of the robot, then we randomly selected
approximately 1 million of these values and stored them in an excel file.
Then loaded them all in the backpropagation training algorithm to calculate the
weight and bias for each neuron
Results
Comparison between the neural network results and the inverse kinematics
equations
Once we limited the workspace we compared the results of the neural network
with the results of the actual inverse kinematics equations and we got really
accurate results with an error margin of ± 0.3 maximum
Conclusions
The results of the neural network were satisfactory having a consistent behavior
with a small error. It’s possible to have an even more accurate neural network,
due to the way the database was stored we can only select 1 million of the 5
million data obtained due to the restrictions o max data in the excel file, a future
upgrade to the project could be changing the way the data its stored to being
able to train the neural network with even more data making the controller much
more accurate making possible its commercial application in places where the
accuracy of the controller it’s a much valued featured like in soldering or
assembly applications.
References
Çabuk, Nihat & Bakırcıoğlu, Veli & Sen, Faruk. (2017). Neural Network
Approach for Inverse Kinematic of a 4-DOF Lighting Manipulator.
Alvarez-Rodríguez, Sergio & Peña, Francisco. (2021). n-th Order Sensor
Output to Control k-DoF Serial Robot Arms. Journal of Sensors. 2021. 1-14.
10.1155/2021/8884282.
Fratu, Aurel & Fratu, Mariana. (2022). ROBOT CONTROL FOR AVOID SELF-
COLLISIONS.
Annex
Database generation code
clc
close all
clear all
for k=1:3
r(k)=3;
end
x0=0;
y0=0;
z0=0;
pos=1;
x1=r(1)*cos(a2)*cos(a1);
y1=r(1)*cos(a2)*sin(a1);
z1=r(1)*sin(a2);
x2=x1+r(2)*cos(a2+a3)*cos(a1);
y2=y1+r(2)*cos(a2+a3)*sin(a1);
z2=z1+r(2)*sin(a2+a3);
coordenadas1(pos)=x2;
coordenadas2(pos)=y2;
coordenadas3(pos)=z2;
angulos1(pos)=a2;
angulos2(pos)=a3;
angulos3(pos)=a1;
pos=pos+1;
end
end
end
CORD=[coordenadas1; coordenadas2;coordenadas3];
clear coordenadas1 coordenadas2 coordenadas3
ANG=[angulos1; angulos2;angulos3];
clear angulos1 angulos2 angulos4
%%
rquery=randperm(length(CORD),1498860*.75-75570);
CooA=CORD(:,rquery);
AngA=ANG(:,rquery);
writematrix(CooA',"Coordenadas2.xlsx")
writematrix(AngA',"Grados2.xlsx")
Backpropagation training code
clc
clear
close all
% Final Project
% First we define the patterns
p=readtable('Coordenadas2.xlsx');
P=transpose(table2array(p));
% Later we define the targets
t= readtable('Grados2.xlsx');
T= transpose(table2array(t));
epochs=2;
alpha=0.00013;
%% Training
% Parameters of neural network
S1=200; % number of neurons 1st layer
S2=3; % number of neurons 2nd layer
[m,n]=size(P);
% Random weights an bias
W_1=rand(S1,m);
b_1=rand(S1,1);
W_2=rand(S2,S1);
b_2=rand(S2,1);
n1=1;
for epoch=1:epochs
for k=1:n
% Forward propagation of values
a1=tansig(W_1*P(:,k)+b_1);
a2=purelin(W_2*a1+b_2);
% Calculation of the error
Err=T(:,k)-a2;
error(:,n1)=Err;
n1=n1+1;
% Calculation of sensitivies
s2=-2*1*Err;
s1=(eye(S1).*(1-a1.^2))*W_2'*s2;
% Adjust of the weights and bias
W_2=W_2-alpha*s2*a1';
b_2=b_2-alpha*s2;
W_1=W_1-alpha*s1*P(:,k)';
b_1=b_1-alpha*s1;
end
end
figure
subplot(2,2,1)
plot(error(1,:))
subplot(2,2,2)
plot(error(2,:))
subplot(2,2,3)
plot(error(3,:))
User interface code
clc
Cx=input("Seleccione la coordenada en X: ");
Cy=input("Seleccione la coordenada en Y: ");
Cz=input ("Selccione la coordenada en Z: ");
P=[Cx;Cy;Cz];
a1=tansig(W_1*P+b_1);
a2=purelin(W_2*a1+b_2);
Angulos= rad2deg(a2)