Hi all ![]()
first have a good day ![]()
Okay,
so, rather than using bulky slow inverse kinematics, i trained a neural network, and trying to implement/use it on arduino uno using a library called "neurona" really awesome work. and just having 1 problem to get a successful compile. i searched for solutions, but couldn't solve it yet. thx for da help ![]()
note: feel free to use my code for your project
but please refer me. and, for this to work for you, you will need different "weights", in case you didn't know what is that, search and learn about "neural networks" and you'll hopefully undderstand ![]()
back to business..
neurona library documentation:
link
made by this awesome guy:
guy's website
teh code:
//Created by Basim Hassoun :) Bassome3000@yahoo.com
#include <Neurona.h>
#include <Servo.h>
#define NET_INPUTS 2
#define NET_OUTPUTS 2
#define NET_LAYERS 3
int layerSizes[] = {8, 8, NET_OUTPUTS, -1};
double const initW[] = {-0.780818846468546,0.819939097546774,1.28483741801587,-1.4143372141435,0.991541304785358,1.18939647553196,-1.17285951809301,0.728834204444012,1.06152829308505,-1.41232314423645,0.687756021131475,1.15087383678558,-1.13057435226533,1.40191176816871,1.4306808027041,-0.676485440589465,0.867653444638317,1.53610843912487,-1.23600438652824,0.575153984166447,1.5074555269135,-1.11038201789695,1.07185749456402,1.45675933004452,-0.988117454787524,1.17453360050837,1.56194008968489,1.21776960690607,1.7374307080759,2.01163389212214,0.93830118514384,1.24562345496322,1.43043494745649,-0.948480547341933,0.855180088212604,1.65304541697929,1.46285255930438,1.76680989571366,0.955131337821628,1.46083730785215,1.55705201038212,1.54882146952858,-0.625822226519316,1.20643324294161,2.09146902071791,1.19365314602431,1.50470666046328,1.83575746642344,1.46909437879821,1.31688051046609,1.14705704042292,-1.00110502757509,1.04802932575992,1.29933762927292,1.14798124887891,1.89007962377314,1.22033190669872,0.963425265622633,1.93386191813067,1.74350932905072,-1.14672497792063,1.49991104624217,1.60466078500928,1.06425055801941,1.1046946495777,1.76298979213811,1.02856080754557,1.08829556928221,1.89522470195988,-0.704037589851766,1.67661806122618,1.40229257541806,1.19766532392011,1.71089251646295,1.64657800943244,1.74807423125232,1.09568233685099,1.14698039304863,-0.96748254657911,1.61798802943076,1.78436012756749,0.946979993119857,1.84095251302554,1.33962333789886,1.60847949584739,1.29019739072903,0.983943508568669,-0.529060504536127,1.22791547549618,1.20956442922674,2.01853004110464,1.34959342333665,1.63400467652879,1.21277532342701,1.48322164857948,1.7273417110715,-0.429534231004237,-0.109143732306363,0.797480598287655,-0.17590977761641,0.384868679109865,0.795845835082236,0.697190671711955,0.0817590528848695,0.178664365665113,-0.0668999337285525,0.506306400903056,0.877441039204564,1.10692192888758,0.878967580186269,0.359416979470113,0.457803443595253,0.451267213384991,0.277143303657784};
MLP mlp(NET_INPUTS,NET_OUTPUTS,layerSizes,MLP::LOGISTIC,initW,false);
int x; //in mm, from 0 to 360 mm
int y; //in mm, from 0 to 360 mm
double xModified; //from 0 to 1, maps to, from 0 to 360 mm
double yModified; //from 0 to 1, maps to, from 0 to 360 mm
int Theta1; //in 360 degrees
int Theta2; //in 360 degrees
double Theta1Modified; // from 0 to 1, maps to, from 0 to 180 degrees
double Theta2Modified; // from 0 to 1, maps to, from 0 to 180 degrees
double NNOutput[2];
boolean XIsRead = false;
Servo Servo1;
Servo Servo2;
int Servo1_Position;
int Servo2_Position;
//void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
void setup() {
Servo1.attach(10);
Servo2.attach(11);
Serial.begin(9600);
Serial.print("Hi :)\nplease input x, in 3 digit format ###");
}
void loop() {
if(!XIsRead){
if(Serial.available() > 3){
x =100*Serial.read();
x += 10*Serial.read();
x += 1* Serial.read();
Serial.println("\nx =");
Serial.print(x);
Serial.println("\nplease input y, in 3 digit format ###");
XIsRead = true;
}
}
if(XIsRead){
if(Serial.available() > 3){
y =100*Serial.read();
y += 10*Serial.read();
y += 1* Serial.read();
Serial.println("\ny =");
Serial.print(y);
Serial.println("\nplease input x, in 3 digit format ###");
XIsRead = false;
}
}
//calculating Theta 1 and Theta 2 from the recived x and y coordinates
xModified = (x + 180)/ 360;
yModified = (y + 180)/ 360;
NNOutput = mlp.forward({-1.0, xModified , yModified});
//{Theta1Modified, Theta2Modified}
Theta1 = (Theta1Modified * 180); //convert from NN out in "0-1 format" to a 0-180 fromat
Theta2 = (Theta2Modified * 180); //convert from NN out in "0-1 format" to a 0-180 fromat
//calibration, adding safety, and sending the position to the servos
Servo1_Position = map(Theta1, 0, 1, 0, 180); //converting from 0-1 to 0-180
Servo1_Position = Servo1_Position - 11; //for calibration
if(Servo1_Position > 163) //adding safety
Servo1_Position = 163; //adding safety
if(Servo1_Position < 3) //adding safety
Servo1_Position = 3; //adding safety
Servo1.write(Servo1_Position);//finally sending to the servo
Servo2_Position = map(Theta2, 0, 1, 0, 180);//converting from 0-1 to 0-180
Servo2_Position = Servo2_Position - 17; //for calibration
if(Servo2_Position > 154) //adding safety
Servo2_Position = 154; //adding safety
if(Servo2_Position > 3) //adding safety
Servo2_Position = 3; //adding safety
Servo2.write(Servo2_Position);//finally sending to the servo
}
aaaand teh error:
C:\Users\Basim\Desktop\MLP_Arm_control\MLP_Arm_control.ino: In function 'void loop()':
MLP_Arm_control:80: error: no matching function for call to 'MLP::forward(<brace-enclosed initializer list>)'
NNOutput = mlp.forward({-1.0, xModified , yModified});
^
C:\Users\Basim\Desktop\MLP_Arm_control\MLP_Arm_control.ino:80:55: note: candidate is:
In file included from C:\Users\Basim\Documents\Arduino\libraries\Neurona\src/Neurona.h:28:0,
from C:\Users\Basim\Desktop\MLP_Arm_control\MLP_Arm_control.ino:3:
C:\Users\Basim\Documents\Arduino\libraries\Neurona\src/arch/MLP.h:67:11: note: double* MLP::forward(double*)
double* forward(double *sample);
^
C:\Users\Basim\Documents\Arduino\libraries\Neurona\src/arch/MLP.h:67:11: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'double*'
exit status 1
no matching function for call to 'MLP::forward(<brace-enclosed initializer list>)'
note: i tried
NNOutput = mlp.forward({-1.0, xModified , yModified});
NNOutput[] = mlp.forward({-1.0, xModified , yModified});
*NNOutput = mlp.forward({-1.0, xModified , yModified});
declared a random integer "a" to test...
{a, Theta1Modified, Theta2Modified} = mlp.forward({-1.0, xModified , yModified});
{Theta1Modified, Theta2Modified} = mlp.forward({-1.0, xModified , yModified});
in line 37, i was planning to play with these things which i'm not experienced with:
//void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
i was planning to modify it as i see proper, based on my search for solutions.
thanks again for teh help
looking forward to hear your opinions