# Real-time Neural Networks Implementation Proposal for Microcontrollers
## 4 Results
### Virtual Carlike Robot  
The first validation test case showed small MSEs, close to 1%, with the architecture described in the methodology section: three inputs and two outputs with only five neurons in the hidden layer, (\(H^{1}=5\)). Since it was trained with a maximum distance of 1.0 m, the robot demonstrated great behavior close to obstacles, but in big empty spaces with distances greater than 1.0 m between obstacles, the robot drifted and span around on the same spot until the test was restarted. This showed us that this training dataset was too simple and required more complex data. The test results for this dataset are shown in Figure 8.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline \(H^{1}\) & \(t_{\text{FFM-1 (ms)}}\) & \(t_{\text{FFM-2 (ms)}}\) & \(t_{\text{EM (ms)}}\) & \(t_{\text{BPM-1 (ms)}}\) & \(t_{\text{BPM-2 (ms)}}\) \\ \hline
2 & 0.59 & 0.31 & 0.06 & 0.46 & 1.30 \\
4 & 4.28 & 0.61 & 0.06 & 0.66 & 2.2  
The second dataset test showed much better results, with the virtual robot being able to react quickly to more distant obstacles and also correcting its trajectory faster. The robot was able to run along the map borders smoothly and keep a safe distance between parallel obstacles in the center of the map. However, the virtual robot still collided with the obstacles and sometimes would collide and drag it self along the borders of bigger obstacles, as shown in Figure 9.  
Figure 8: Virtual map with the resulting trajectory of the virtual carlike robot for the first training dataset. Figure 9: Virtual map with the resulting trajectory of the virtual carlike robot for the second training dataset. The dataset for the third validation case resulted in a higher MSE of 2.4%. The carlike robot was faster than in the previous two tests and was able to perform a fast reaction to abrupt changes in proximity to obstacles, as shown in Figure 10. However, in this dataset training made, the robot demonstrated behavior that can be interpreted as overfitting, since it would sometimes react too quickly and start to spin around itself after detecting some obstacles ahead. The overall results show that the datasets did not have enough data and that some more tests were required with even more virtual sensors. The angle between the Front-Sensor (FS) and the virtual horizontal axis of the test map was included. In addition, training tests with two and three more hidden layers (L = 3, 4) and also hundreds of hidden neurons and thousands of iterations were performed, none of which improved the results, actually, this prevented the Neural Network from reaching a training error convergence lower than 20%. The generated binary code from the source in C for the best dataset (third) had 3.07 KB of memory size, which amounts to 1.2% of the 256 KB of program memory of the ATMega2560. This code size is quite compact compared to a similar model implementation, as shown in [28]. The same variables and testing criteria used for the XOR operation were used in this case, with a 16 Mhz of clock frequency. The timing results for the virtual carlike robot were as expected, being smaller than the XOR operation that has a simpler architecture with less inputs and outputs (\(H^{0}=1\) and \(H^{2}=1\)) and also a wide range for \(H^{1}\), Table 5. In addition, as this implementation does not perform online real-time embedded training, only the FFM-1, FFM-2, and FFM-3 modules were used, i.e., FFM-2 and FFM-3 for the cases with more than one hidden layer. The timing results for the first and second datasets were the same. This is expected, since the only factor to influence the execution time is the size of the synaptic weight matrices \(H^{1}\) and \(H^{2}\) that depend only on the amount of inputs, neurons, and samples. Since this was not a batch classification, but a single sample (online classification), the input size remained unchanged as 1 throughout all the three tests. The third case presented a fast timing result, but close to two times the timing results for the first and second cases.