Hello to All,

I have tested and implemented successfully a neural network library for Arduino on the ArduPilot Mega board (APM2560), this is the neuroduino from Ted Hayes.

This library work fast and the implementation is relatively simple:

Neuroduino params: (network array, number of layers, Eta, Theta, debug)

In attached a sample NN program above and the lib...

So, you may begins to add some AI routines on the ArduCopter...

Good neural network tests and enjoy,

Regards, Jean-Louis


Views: 22680


Replies to This Discussion

Thanx, the calculations I believe the code does this:


Could you tell me what are the inputs i.e. angles or actuator numbers? 

I understand the code, I do not understand what should be the inputs and outputs for Arducopter.


Only two layers are allowed, please see if I am correct:

void Neuroduino::simulateNetwork(){
Calculate activations of each output node
int l,j;
for (l=_numLayers-1; l>0; l--) {
// step backwards through layers
// TODO: this will only work for _numLayers = 2! 
for (j=0; j /span> _net.Layer[l]->Units; j++) {
_output[j] = signThreshold(weightedSum(1, j));

Could you kindly show me how to calculate these input/outputs in APM board? And if they are the wrong params, could us suggest their replacements:

time now = tn

Speed of Motor  = Sm ( eg Sm1 Speed of Motor 1)

Delta Roll = Dr = Roll( tn ) - Roll ( desired )

Delta Pitch = Dp= Pitch ( tn ) -  Pitch ( desired )

Delta Yaw = Dy=  Yaw ( tn ) - Yaw ( desired )

Error Roll =  Er = Roll ( desired  ) - Roll (tn-1)

Error  Pitch =  Ep =  Pitch ( desired ) -  Pitch (tn-1)

Error Yaw =  Ey = Yaw ( desired ) - Yaw (tn-1)

Inputs :  Dr ,Dp,Dy,Er,Ep,Ey,Sm1,Sm2,Sm3,Sm4

Outputs : Sm1 (tn+1) , Sm2 (tn+1) , Sm3  (tn+1) , Sm4 (tn+1)

  1.  if( first run  )  initial errors zero
  2. else Calculate Errors of Roll, Pitch and Yaw from ( tn-1 values)
  3. get desired Roll, Pitch and Yaw
  4. read  actual Roll, Pitch and Yaw from sensors
  5. Calculate delta (Roll, Pitch and Yaw)
  6. read actual Speed of Motors from sensors 
  7. Run NN 
  8. get Outputs  ( new Speed of motors ) from NN
  9. Set New Motor speeds
  10. goto 2

Here an interesting video which shows a simulation of quadcopter controlled by a spiking neural network running on the SpiNNaker hardware.

Black = Control mechanism turned off.
Green = Control mechanism turned on.

The four 'blob' indicators show the speed of the four rotors. Red = faster, green = slower.

SpiNNaker is a scalable parallel processing system designed to simulate spiking neural networks in real-time, developed by the APT group at the University of Manchester.

Regards, Jean-Louis

Here is the source code for FANN

src directory has the necessary C files.

The difference between this code and what you posted from Ted Hayes is that Ted's only two layer NN, and the FANN is multi-layer. 

It might be the case that 2-layer NN would be sufficient.

However we need to store the train-data into files and need some GUI for manipulating the training. Both FANN and FANNTool have a lot of useful code. 

fann_data.h contains the struct for the single-layer and the FANN network.

The weights are arranged in arrays of long and their beginning and end are stored into struct pointers for future access.

Basically the FANN network is link list of long arrays.

I do not foresee much memory access wasted cycles, but there is however an impact.


Dear Jean-Louis

I suspect if we tightly coupled a beaglebone board to the APM board, the performance of the CPUs are so high that no specialized hardware for NN simulation would NOT be necessary.  

APM board will be the outer-loop: It calculates where to go next and pass it to the inner-loop

BeagleBone will be the inner-loop: It does the NN network simulations, weight calc and real-time training 


© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service