efficient storing of float data in memory.

Hi,
I hope you guys are doing fine. I am doing a project in which I want to find the distance the Roomba moving using encoders, which I did but now I have to store these values. The problem is it gives too many big values so to make them smaller I use meter unit, now the values are floats. Basically I am measuring the distance before every turn the Roomba makes due to obstacle, so sometimes the values are too small and sometimes large. like
28.62m
0.07m
86.5m etc
First I am trying to store in EEPROM memory but I already used it for another purpose of storage. Also search about PROGMEM but it only read. Now I am thinking of like how to store the values efficiently because approximately 200 values of distance data have to be store. Here is my function for finding distance in the meter. Thank you so much and stay safe.

void Rdistance() {

  Roomba.write(149);
  delay(20);
  Roomba.write(2);
  delay(20);
    Roomba.write(43);
   while ( Roomba.available() ) {
    k[val1]=Roomba.read();
     Serial.print(F("velovitz loop"));
    Serial.println(k[val1]);
    val1++;
   }
val=((int)k[0] << 8 | (0xff & (int)k[1]));   
   delay(100);
    Roomba.write(44);
    while ( Roomba.available() ) {
    k[val1]=Roomba.read();
     Serial.print(F("velovitz loop"));
    Serial.println(k[val1]);
    val1++;
   }
vel=((int)k[0] << 8 | (0xff & (int)k[1]));    
Serial.print(F("Left Encoder value is :"));
    Serial.println(val);
    Serial.print(F("right Encoder value is :"));
    Serial.println(vel);
    Left=((val-L1[0])*3.1415*72)/508.8;
    Right=((vel-L1[1])*3.1415*72)/508.8;
    MIT=((Left+Right)/2)*0.001;  //distance in meter
    //EEPROM.update(dist_index,MIT);
    Serial.print(F("Left Encoder value is after :"));
    Serial.println(Left);
    Serial.print(F("right Encoder value is after :"));
    Serial.println(Right);
    Serial.print(F("distacne :"));
    Serial.println(MIT);
    L1[0]=val;
    L1[1]=vel;
    val=0;
    vel=0;
    k[2]={0};
    dist_index +=1;
}

How many significant digits do you want or need the floats to have bearing in mind the application and source of the data ?

Instead of storing floats consider using ints instead by multiplying the float by say 100 before storing to EEPROM and dividing them by 100 for display purposes when read back.

Doing that would halve the number of bytes needed to save each value

HI,
Thank you for taking time. After the decimal point one digit is ok. like 23.9 , 123,6 , 0.6 etc. And the second part ok instead of storing float value we store int, but int also of 2 byte and I am thinking of like we are able to store "maximum" of 1 byte, after all i also want to compress it to smaller then a byte.

but int also of 2 byte

Floats take 4 bytes, not 2 bytes so using ints takes half of the storage space

What range of values do you expect to be saved ?

Yeah, int having half the size of float. As per I understand the question you asked about the range of values. More then 250 values of distance has to be store in the range of 0-255 meters, is that what you asked?

What are you going to do with the data as you record it? Would it be ok to push it to an SD card or a dat logger?

No I dont have to use the SD card or any other device, I used 512 EEPROM bytes to store the sensors values efficiently. Now I can may use the next 512 bytes to store this distance values so it should be reliably other wise I lost the distance data. With this data I plot the trajectory of the robot.

More then 250 values of distance has to be store in the range of 0-255 meters, is that what you asked?

If the values to be stored are in the range 0 to 255 and you need one decimal place then there is no way that you can fit the data into one byte per distance

However, I am amazed that the Roomba will move up to 255 metres before turning. Just how big is this space that you are vacuuming ?

HI,
Well for this I am pre assuming the maximum distance before first turn, ok let us suppose we have 100x100 meter range of area. So maximum is then 100m before first turn. My project is to find the parameter of unknown environment.

You want a Roomba to clean 10000m2?

No, I want the roomba to move around and get the LDR sensor data in a 100 meter area I mean.

TheMemberFormerlyKnownAsAWOL:
You want a Roomba to clean 10000m2?

Or, for the (USA) farmers out there --- almost 2.5 Acres!!!

100 meters is 10,000 cm, If you store meters/100 you are really storing centimeters and if distances are positive only, then you can accommodate up to 65535 cm or 655.35 m. in one uint16_t or int type.

If you need to store 200 of those, you need 400 bytes of storage. Maybe you could find a way to compress your sensor data (perhaps it is not currently stored optimally in EEPROM).

Even 100m seems very high unless you are running the Roomba in a banquet hall. The furthest one could travel in my house is under 15 meters if it happened to be lined up just right to go from one room to another and on into the hallway.

Also, don't you need to record some information regarding the angle of the turn made?

Yeah, I am just taking in to account the worst-case scenario :slight_smile: where if my Prof. test this robot in a corridor then it might go 100m.
For the angle part I fixed the robot to turn 25 degree for each turn, I store 1 bit for right turn and 0 bit for left turn.

ABDanyia:
Yeah, I am just taking in to account the worst-case scenario :slight_smile: where if my Prof. test this robot in a corridor then it might go 100m.
For the angle part I fixed the robot to turn 25 degree for each turn, I store 1 bit for right turn and 0 bit for left turn.

In the situation I mentioned above, you have two spare bits per 16 bit unsigned int (for a max distance of 163.84 m), so you could include the direction bit with the distance integer. That would allow for 327,68 cm. maximum distance.

Yeah you right, but this will take much memory, 2 byte for each direction, maximum of 256 turns a robot will make. One of my project task is also to store this data in memory till that time when the wireless access point is in the range to send data to the server. I compressed my sensor data and for that, data can be stored up to 4 hours and 30 minutes, but now i am stuck in this float to single byte thing.

What do you mean, "this float to single byte thing"? Such a thing does not exist. Small wonder you are stuck. There is no entropy in a distance, it can't be compressed.

Yeah, i know that distance will not be compressed, but is there any possibility that i can store it in flash memory?

ABDanyia:
Yeah, i know that distance will not be compressed, but is there any possibility that i can store it in flash memory?

What board are you using?