ori-drs / allan_variance_ros

ROS compatible tool to generate Allan Deviation plots
BSD 3-Clause "New" or "Revised" License
466 stars 86 forks source link

Getting ValueError: array must not contain infs or NaNs while running analysis.py #43

Open RajS999 opened 8 months ago

RajS999 commented 8 months ago

I am trying to calculate accel and gyro noise and random walk for Intel realsense. I quickly generated imu csv in the format specified here using custom CPP script for just 3 seconds. I wanted to check if it will work or not before recording 20 hours of IMU data.

I created ros bag from csv by running:

rosrun kalibr kalibr_bagcreater --folder ./data/imu_data --output-bag ./data/newbag.bag

Checking the bag created:

root@e9408da6622e:/data# rosbag info /data/data/newbag.bag  
path:        /data/data/newbag.bag 
version:     2.0 
duration:    2.4s 
start:       Dec 30 2023 18:41:25.42 (1703961685.42) 
end:         Dec 30 2023 18:41:27.84 (1703961687.84) 
size:        312.7 KB 
messages:    830 
compression: none [1/1 chunks] 
types:       sensor_msgs/Imu [6a62c6daae103f4ff57a132d6f95cec2] 
topics:      /imu0   830 msgs    : sensor_msgs/Imu 

Then I converted it to allan variance compliant bag by running:

rosrun allan_variance_ros cookbag.py --input /data/data/imu_data/newbag.bag --output /data/data/imu_data/cooked_bag.bag 

Checking the bag created:

root@e9408da6622e:/catkin_ws# rosbag info /data/data/imu_data/cooked_bag.bag  
path:         /data/data/imu_data/cooked_bag.bag 
version:      2.0 
duration:     2.4s 
start:        Dec 30 2023 18:41:25.42 (1703961685.42) 
end:          Dec 30 2023 18:41:27.84 (1703961687.84) 
size:         41.7 KB 
messages:     830 
compression:  lz4 [1/1 chunks; 8.47%] 
uncompressed: 296.1 KB @ 122.5 KB/s 
compressed:    25.1 KB @  10.4 KB/s (8.47%) 
types:        sensor_msgs/Imu [6a62c6daae103f4ff57a132d6f95cec2] 
topics:       /imu0   830 msgs    : sensor_msgs/Imu

I created allan variance config file imu_confog.yaml:

imu_topic: "/imu0"
imu_rate: 346
measure_rate: 346 # since bag contains 830 messages / 2.4 seconds = 345.8333 approx 346
sequence_time: 3 # since bag contains 2.4 seconds worth of data

(I also tried with both rates 400, no luck.)

Here is how my data folder looks like:

image

Then I run allan variance:

root@e9408da6622e:/catkin_ws# rosrun allan_variance_ros allan_variance /data/data/imu_data /data/data/allan_variance/imu_config.yaml

And finally run Analyse.py:

root@e9408da6622e:/catkin_ws# rosrun allan_variance_ros analysis.py --data /data/data/imu_data/allan_variance.csv --config /data/data/allan_variance/imu_config.yaml
/catkin_ws/src/allan_variance_ros/scripts/analysis.py:23: RuntimeWarning: divide by zero encountered in log
  logy = np.log(y)
Traceback (most recent call last):
  File "/catkin_ws/src/allan_variance_ros/scripts/analysis.py", line 101, in <module>
    accel_wn_intercept_x, xfit_wn = get_intercept(period[0:white_noise_break_point], acceleration[0:white_noise_break_point,0], -0.5, 1.0)
  File "/catkin_ws/src/allan_variance_ros/scripts/analysis.py", line 24, in get_intercept
    coeffs, _ = curve_fit(line_func, logx, logy, bounds=([m, -np.inf], [m + 0.001, np.inf]))
  File "/usr/lib/python3/dist-packages/scipy/optimize/minpack.py", line 708, in curve_fit
    ydata = np.asarray_chkfinite(ydata, float)
  File "/usr/lib/python3/dist-packages/numpy/lib/function_base.py", line 495, in asarray_chkfinite
    raise ValueError(
ValueError: array must not contain infs or NaNs

But as you can see it is giving error array must not contain infs or NaNs. Turns out there are some NaNs in allan_variance.csv file generated. What I am doing wrong here?

I have uploaded all bags and csv file on drive here.

RajS999 commented 8 months ago

I guess capturing very tiny amount of data doesnt work. I tried capturing few seconds of data (for quickly checking if the whole pipeline will eventually work or not), even though doc says that we must record at least 1 hour of data, preferably at least 3 hours of data. I recorded data for 21 hours and it worked. Still I will like someone confirm that we should indeed get ValueError: array must not contain infs or NaNs error when working with small amount of data.

abolfazljalali commented 6 months ago

Hi,

Could you solve this issue?

dieumerci7 commented 1 month ago

I cannot explain what is wrong with small amount of data, but I have myself run into this issue with a 65s dataset, and solved it by recording for 3 hours. Checking into allan_variance.csv, I see that it indeed contained NaN values for the small dataset. Probably some statistics can only be calculated when enough data is gathered.