0

I'm receiving (rotation times from 4 motors) data from serial port.

I'm using:

fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32') 

Values are binary and have a format(after reading): Example 1:

times =
11012,4443359375
11012,7773826587
11012,7773488505
11012,7773178500

then I calculate a (motorspeed):

%Solve full rotation speed (Hz)
motorspeed = 1./(2.*times); 

and get answer

motorspeed =
45.403
45.413
45.233
45.783

But if I,m using just 1 motor from 4 i get this values: Example 2:

times =
11012,4443359375
6,44429277903543e-39
2,51729256131310e-41
9,80908925027372e-44

and

motorspeed =
45.403
77588032875632144111403251571861040368975872.000
19862609840597303702026941971780138162366447616.000
5097313188235571189218766267134897934598963986432.000
  • Why I,m getting receive a values like 6,44429277903543e-39, I,m just sending a zero via serial interface?

Thank you very much!

Fracture
  • 105
  • 3
  • 14
  • - How can I filtering a answer for all rows? Like C example: ` for(i=0,i1000){ motorspeed[i]=0; } }` – Fracture Nov 20 '18 at 12:45
  • You say you are sending zero through the COM interface. Can you show the code for that? Otherwise, it may well be that very small values are sent in place of zero. In any case, just filter variable *times* with something like `times(times<1e-5)=0;` to set very small values to zero – Brice Nov 20 '18 at 12:50
  • Your answer is in the dupe target: floating point accuracy. Basically your zero is not exactly zero, so compare within tolerance and throw out any `times` numbers you find unlikely (e.g. `times<1e-3`). – Adriaan Nov 20 '18 at 12:52
  • Hei Brice, I'm sending a rotating time calculated with hardware-interrupts. I have a volatile float mean_time, that will be initialized with = 0, and later will be changed by hardware-interrupts. If the motor not rotating - mean_time stay zero. – Fracture Nov 22 '18 at 09:45
  • Hey Adriaan, yes, I understand this. Thank you, filtering works! – Fracture Nov 22 '18 at 09:51

0 Answers0