Introduction: Redbot and IR Radar Mutualism
This project uses a neural network for the redbot which allows the network to avoid the black lines by using the line sensors and the radar helps to feed the redbot with instructions related to movement (right, forward, left, upwards) in a defined area.
A Neural network is inspired by nature and it mimics at a certain level the way a brain stores information and reacts to various inputs.
The code that was used in the redbot uses a perceptron that is trained through reinforced learning in order to avoid the black lines, it also has a radar that will be mapping and presenting all the redbot movements. This work can be further extended.
Step 1: You Will Need
- Sparkfun's Redbot
- Bluetooth Bee for Redbot
- Arduino UNO
- Servo motor
- Bluetooth (HC-06)
- Ultrasonic sensor (HC-SR04)
- Jumper wires
Step 2: Putting the Stuff Together
This project is made of 2 parts, the first one is a radar and the other one is a redbot, a smal two wheel robot with infrared sensors.
For the radar we will need to put the ultrasonic sensor on top of the servo in order to have the ability to move the ultrasonic sensor to multiple directions and be able to know in which direction is pointing.
After the servo is connected, we will need to include the bluetooth component in order to be able to control our servo motor and ultrasonic sensor from our computer/celphone.
In order to assemble the redbot you can follow this guide.
Step 3: Communicate Via Bluetooth
There multiple guides that explain this process pretty well, for example this instructable does a great job explaining it.
In Linux you can use the bluetooth manager to pair the device, you will find the device and then in the PIN options you can use the 1234 PIN number.
That will take care of pairing the bluetooth device, but you still need to test the connection.
You also need to install blueman, in Ubuntu you can run:
sudo apt-get install blueman
Then run the blueman-manager with sudo privileges
The bluetooth device will appear with the HC-06 name and the MAC address.
Right click the device and click on "Serial device" that will take care of connecting it.
When looking at the arduino IDE you will also find in the Serial port menu the new bluetooth port.
Step 4: Using Python "Core"
A small core was created to manage both devices using Python and pybluez to send instructions to the devices. For example: we can send an 'r' to the radar to start the scan, this is posible using the computer's bluetooth capability (when avaialble). This can also be achieved by obtaining a cheap bluetooth dongle to play around with the library.
First install the pytohn dependecies by using `pip install -r requirements.txt`, afterwards you should be able to run the core.py by running: `python core.py`. What this will do is start scanning the environment and once the object is found within a meter the x and y position will be sent to the computer. This process runs 10 times or X times if you modify the ITERATION_TIMES variable in the script. After this the position of the robot will be displayed on a small scatterplot for each scan.
Step 5: Coding the Neural Network on the Redbot
In order to code this network the model that was done was based on the input of the line follower sensors.
The inputs of the neural network are the 3 line sensors (left sensor, center sensor and right sensor). The weights are multiplied by the inputs and the error calculated.
The Line follower threshold was defined at 800, so, the evaluation was done by comparing it against the output of the line followers:
"if ((left_sensor > LINETHRESHOLD) && (center_sensor > LINETHRESHOLD) && (right_sensor > LINETHRESHOLD) )"
If the above condition was true it would return 1, which means that there is space where the redbot can still move, if not -1 which would mean that it found a black line.
The output of the above method is part of the inputs of the training, where the evaluation is desired action and the second input is the guess based on the feedforward method that was obtained by multiplying the weights and inputs as explained before. These to inputs would be substracted to a error variable which is going to help correcting the movement of the redbot.
Attached you will find the complete code.
Step 6: Running Everything Together
Position the radar on one of the cardboard corners where you'll be running the redbot
Then start the radar which will be start mapping the redbot positions and you will be able to visualize it in your phone or laptop.
Turn on the redbot and it will start the learning while the radar keeps mapping its positions.
We have a be nice policy.
Please be positive and constructive.