Omni Robot _ Auto Home without any sensor
- baotriet110
- Aug 20, 2020
- 3 min read
Congratulation! You built Omni robot on your own. Now, we will create something fun with the robot. After finishing the project, the robot can run back home automatically without any sensor, but a SD card.
Firstly, take a look.
Components:
A omni robot - if you don't have, please follow the link to make one.
A mini-SD card module
A mini-SD card
(A standard SD card is suitable also)
Let's get started
As you may know that "a stepper motor, also known as step motor or stepping motor, is a brushless DC electric motor that divides a full rotation into a number of equal steps. The motor's position can then be commanded to move and hold at one of these steps without any position sensor for feedback (an open-loop controller)" (Wikipedia). Therefore, we can calculate the moving distance of the robot by calculating the numbers of step which the robot moved.
Making use of the features of AccelStepper library, we can know how many steps the robot move during a second by setting the speed of the robot (step/s). Now, to know the number of steps the robot moved (step), we only need to know the time (s).
After knowing the necessary information (step/s and s), we will write them to a mini SD card then read them back when the auto-home mode is ON.
However, we have a problem that the current library for SD card can only read from the first line to the end instead of the reverse order (from the latest command to the oldest one). For example, It will save 1, 2, 3, then 3, 2 ,1 should be read; not 1, 2, 3.

We have 2 approaches:
+ Fast way:
Count the number of characters of the longest line by hand or by string length (remember to convert char array to string), then set it to MAX.
Open a txt file, then write the same number of characters for each line. If the number of character is shorter than MAX, we should add more character to it.
After that, we will calculate the number of character written into the txt file. Fortunately, it is equal the size of the file (FILE.size()). Next, we can calculate the number of lines by dividing the size of the file to (MAX + 2) (when you write the data to SD card, it will add null string and new line character to the end of the each line).
Finally, we can use FILE.seek() to read whatever lines we want to.
txtFile = SD.open(filename, FILE_READ);
if (txtFile)
{
int numLine = txtFile.size() / 23; // 23 is length of writed data _ 21+2
for (int i = numLine - 1; i >= 0; --i)
{
// Use seek() to point to the line where it should read
txtFile.seek(i * 23);
// Use parseInt() to get the integer number including minus sign
p[0] = txtFile.parseInt();
p[1] = txtFile.parseInt();
p[2] = txtFile.parseInt();
p[3] = txtFile.parseInt();
...
}
...
}
Notice: my MAX is 23. Your MAX number maybe different if your speed is smaller than mine. Be careful. If you need more information, please read the reference link.
Reference: https://www.arduino.cc/en/Reference/SD
+ Slow way: (it is only for research purpose). I tested it. This way is really slow.
You will save different data lines to different txt files, which are names in order. You will need a variable to count the number of written files. Then opening and reading the data from the highest order to the lowest one. Good luck.
One more thing, you should modify the wiring to use ps2 controller and sd card module at the same time.
PS2 receiver:
GND ----------------------> GND
VCC -----------------------> 5V
DAT ----------------------> Abort (pin A0 on Arduino Nano)
CMD ----------------------> Resume (pin A2 on Arduino Nano)
CS -----------------------> Hold (pin A1 on Arduino Nano)
CLK -----------------------> CoolEN (pin A3 on Arduino Nano)
SD card module:
GND ----------------------> GND
VCC -----------------------> 5V
MISO ----------------------> D12
MOSI ----------------------> Z- or Z+ (pin D11 on Arduino Nano)
CS -----------------------> Y- or Y+ (pin D10 on Arduino Nano)
CLK -----------------------> D13
If you have any concern, feel free to contact me. I will try to help you as much as possible. Thank you.
Comments