Line Follower using Neural Nets : Part 1 (Generating Data Set)

Neural Networks are convenient when mapping a function which behaves non-linearly. However, for Training and Testing purpose , Data is the most important piece of the puzzle.

The Neural Network Line Follower to be designed uses 8 Line sensing elements where each will return
 1 : Line Detected
 0 : Line Not Detected

So the possible dataset is the combination of 8 binary units arranged in different pattern leading to a total of
            28 =  256 Samples of data.

I wrote the following MATLAB script to create the data for training the Neural Network.

 function [bin,out]=DataGen(m)  

 % Function to Generate Training Data set for training neural network of a  
 % line follower  
 %    
 %     [bin,out]=DataGen(number of inputs)  
 %       
 % It is a good practice to have an even number of input units for the  
 % NN Network to be trained  
 n=(2^m)-1;              
 bin=decimalToBinaryVector(0:n);   
 [p,q]=size(bin);             
 out=zeros(p,1);   
 bLeft=bin(:,1:(q/2));  
 bRight=bin(:,((q/2)+1):end);  
 wL=bi2de(bLeft,'left-msb');  
 wR=bi2de(bRight,'right-msb');  
  for i=1:p  
    if wL(i)>wR(i)  
      out(i)=-1;  
    end   
    if wL(i)<wR(i)  
      out(i)=1;  
    end  
    if wL(i)==wR(i)  
      out(i)=0;  
    end    
  end  
 end  

Here:
         bin holds the binary input sequence of 8 bits    
         out holds the output corresponding to the input bin

Such that:
          if bin=[1 0 0 0 0 0 0 0]  then out = -1      (Line Sensed on far left : Move Left)
          if bin=[0 0 0 0 0 0 1 0]  then out =  1      (Line sensed on right : Move Right)
          if bin=[0 0 1 0 0 1 0 0]  then out =  0      (Line sensed symetrically : Keep Moving Forward)

For a Neural Network,  0 is pretty much a perfection so it allocates a really small value (~0) such that it can be considered as zero.

From the script above with 8 as a parameter via the following syntax:
           [bin,out]=DataGen(8);
we get:
           bin = 256 X 8 Input Data Matrix
           out = 256 X 1 Output Data Matrix

In the screenshot of the varibles, Left Segment shows the input from the sensors while we have the expected output in the blue bounded box on right:


These Data elements are ready to be used as Training Parameters for our Neural Network.
Further Development to be covered by subsequent posts.

Update 7/Sep/16 : Read Part II: Designing Neural Network

Peace Out.

Used:
Matlab 2016a

RoboAuto : Arduino Bluetooth Joystick for Android™


HC-05 has an added advantage in embedded systems that pretty much every smartphone is equipped with in built Bluetooth hardware.This opens up a large number of possibilities for access and control of embedded systems.

There are apps that do the task of controlling a system via bluetooth however none sufficed to my requirement. So I developed one,

Presenting  
RoboAuto

An Android Application for communication with HC-05 Bluetooth Module.
RoboAuto is a clean and effective app using which you can control your Robots or Devices with a Simple Joystick!
  
What RoboAuto does:

Program Flow

So, You as an embedded developer have to configure your robot only for the commands received from the app!

Here are few screenshots:






RoboAuto connects to the Bluetooth Module using a Wireless Serial Link. Android already provides support for this in their native API.

After a successful connection, characters are sent to the module on actuation of joystick ,buttons or check boxes which can be read and executed by Arduino or other microcontrollers.

Special Thanks to zerokol for his JoystickView Library.
The Joystick sends the following :

Forward: F
Backward: B
Left : L
Right : R

Additionally I have assigned intermediate directions , for example, FL for Front-Left, BR for Backward-Right and so on.
No Changes are to be required on the Embedded side as the UART only parses a single character at a time, giving us simultaneous (in theory) Forward and Left motion. Kind of like what happens in a PWM.

Download RoboAuto here:
Get it on Google Play
Google Play and the Google Play logo are trademarks of Google LLC.

This Post therefore will be updated soon and is worth a bookmark.
UPDATE (22/October/17): Savvy has been renamed to RoboAuto and published on Google Playstore
UPDATE (10/August/16) : Few Screenshots and content have been updated!
UPDATE (25/August/16 ):  Savvy(Now RoboAuto) is available for testing and debugging for FREE
UPDATE (12/September/16): Added Internet Access permission for Google Form Integration.
UPDATE (19/March/17): Fixed a lot of bugs in the layout scale. Renamed "Turn Light" to "Rear Light."

Do report any bugs you encounter.
Credits (19/March/17):  Thank You Shivani for your Feedback on Design Issues

Good Stuff Take Time.

Used:
Android Studio 2.3.3
Lenovo S6600 , Micromax Knight Cameo for Debugging.