Writing the Software
Time: 1 Hour
Code Verison: 0.1
Before writing the software for MIPR you need to decide how you will upload code to the robot. I will demonstrate how to do this over bluetooth and how to do this over USB at the end of this tutorial. Before you can upload code over bluetooth you need to plug your HC-05 into a bluetooth programmer and change a few parameters. A tutorial on how to create a bluetooth programmer can be seen here. Once you have made the bluetooth programmer follow the below video to change the baud rate of the HC-05 and the POLAR parameter using AT commands. I have put the commands below.
You can buy a Bluetooth programmer from my E-Bay shop instead of making your own.
If you don't want to do this then don't worry you can still program the robot over USB using a FTDI converter. Here is an example of an FTDI converter.
Programming the Motors
Now we will write the software for MIPR. The below sketch is what yo can use to test that your motors and motor driver are connected properly. If they are you will see MIPR move forwards, backwards, left and right.
Copy and paste the above code into Arduino IDE and upload it to you robot to see how it behaves. If your unsure on how to do this a video demonstrating uploading code via USB and Bluetooth can be found at the bottom of this tutorial.
If your robot moves then great everything is connected up. If it moves in the correct directions even better you connected the motors correctly. If your robot moved in different directions you need to check the polarity of the N20 motors, they should have been connected in the same was as the schematic. If you have connected them incorrectly you can either disconnect them and reconnect them in the same way as shown on the schematic (recommended), or change the i1A, i2A, i3A and i4A variables to the actual pins that your motors are connected to. This is how they should be connected;
- 1Y = Left hand motors NEGATIVE terminal, 1A = Digital Pin 4 (1Y's corresponding digital input).
- 2Y = Left hand motors POSITIVE terminal, 2A = Digital Pin 3 (2Y's corresponding digital input).
- 3Y = Right hand motors POSITIVE terminal, 3A = Digital Pin 7 (3Y's corresponding digital input).
- 4Y = Right hand motors NEGATIVE terminal, 4A = Digital Pin 8 (4Y's corresponding digital input).
Programming Bluetooth Commands
Now we have the motors working we need to get the Bluetooth working. We will write some code that will listen for Bluetooth commands and act accordingly. So for instance if we want the robot to go forwards we send the forwards command and the robot will move forwards. This will allow us to control the robot from a phone, tablet or computer.
Delete the previous code and copy and paste the above code into Arduino IDE, upload to MIPR and download the below or equivalent application and try to control MIPR with your phone.
I use this application to control MIPR with my phone. Any Bluetooth application can be used and the relevant commands can be mapped in MIPR's software or on the controller software.
Explaining the Code
Uploading Sketches to the Arduino
Now we have a robot that can be controlled by a mobile phone, tablet or computer. In the next tutorial we will create a battery board for MIPR that will allow us to charge the battery over USB. This tutorial is optional and if your happy using the 2S LiPo you can skip it however I will be adding some sensors measuring to the battery board that will measure the speed of the wheels. This odometry data will be used to estimate distance travelled as part of our kinematic model used in later tutorials. After that we will create our first sensor board that will give MIPR some functionality. In this case we will use some cheap light dependant resistors to make MIPR follow and avoid light.