D455 IMU Sampling Rate Issue
Hi,
I am recording data from the Intel RealSense D455 IMU. However, the issue is that the saved CSV file shows an unusual sampling rate. I set the sampling rate to 100 Hz for the accelerometer and 200 Hz for the gyroscope, but for both, I ended up with approximately 6,000 samples over 10 seconds of recording, which corresponds to 600 Hz.
I used the following code. Could you please help me understand why I am not getting 100 Hz and 200 Hz for the accelerometer and gyroscope, respectively?
Here are some accelerometer data:
Time | X | Y | Z |
0 | 0.137293 | -0.22555 | -9.7282 |
0.141606092 | 0.11768 | -0.22555 | -9.7282 |
0.141606092 | 0.127486 | -0.22555 | -9.74781 |
0.141606092 | 0.127486 | -0.22555 | -9.74781 |
0.141606092 | 0.127486 | -0.22555 | -9.74781 |
0.143036127 | 0.127486 | -0.22555 | -9.75762 |
0.143036127 | 0.127486 | -0.22555 | -9.75762 |
0.143036127 | 0.127486 | -0.22555 | -9.75762 |
0.143036127 | 0.127486 | -0.22555 | -9.74781 |
0.143036127 | 0.127486 | -0.22555 | -9.74781 |
0.144280195 | 0.127486 | -0.22555 | -9.74781 |
0.144280195 | 0.127486 | -0.22555 | -9.70858 |
0.144280195 | 0.127486 | -0.22555 | -9.70858 |
0.144280195 | 0.127486 | -0.22555 | -9.70858 |
0.144280195 | 0.127486 | -0.23536 | -9.7282 |
0.155295372 | 0.127486 | -0.23536 | -9.7282 |
0.155295372 | 0.127486 | -0.23536 | -9.7282 |
0.155967712 | 0.11768 | -0.22555 | -9.7282 |
0.279539585 | 0.11768 | -0.22555 | -9.7282 |
0.279539585 | 0.11768 | -0.22555 | -9.7282 |
0.279539585 | 0.11768 | -0.23536 | -9.7282 |
import pyrealsense2 as rs
import csv
import time
# Configure the pipeline to enable accelerometer and gyroscope streams
pipeline = rs.pipeline()
config = rs.config()
# Enable IMU streams
config.enable_stream(rs.stream.accel, rs.format.motion_xyz32f, 100)
config.enable_stream(rs.stream.gyro, rs.format.motion_xyz32f, 200) # Gyroscope
# Start pipeline
profile = pipeline.start(config)
# Open CSV files for writing
accel_file = open('accel_data.csv', 'w', newline='')
gyro_file = open('gyro_data.csv', 'w', newline='')
accel_writer = csv.writer(accel_file)
gyro_writer = csv.writer(gyro_file)
# Write headers
accel_writer.writerow(["timestamp", "ax", "ay", "az"])
gyro_writer.writerow(["timestamp", "gx", "gy", "gz"])
try:
# Capture data for a certain duration or number of frames
# For example, capture for 10 seconds:
start_time = time.time()
duration = 10.0 # seconds
while (time.time() - start_time) < duration:
frames = pipeline.wait_for_frames()
# The IMU data is a set of separate frames.
for f in frames:
if f.is_motion_frame():
# Check type of motion frame
frame_type = f.profile.stream_type()
# Extract timestamp and motion data
ts = f.get_timestamp() # milliseconds
data = f.as_motion_frame().get_motion_data()
if frame_type == rs.stream.gyro:
# Gyro data in rad/s
gx, gy, gz = data.x, data.y, data.z
gyro_writer.writerow([ts, gx, gy, gz])
elif frame_type == rs.stream.accel:
# Accel data in m/s^2
ax, ay, az = data.x, data.y, data.z
accel_writer.writerow([ts, ax, ay, az])
finally:
# Stop pipeline and close files
pipeline.stop()
accel_file.close()
gyro_file.close()
print("Data capture complete. CSV files saved.")
-
Hi Hamedtaheri A RealSense development team member advised at the link below that writing to .csv was "extremely not efficient" and recommended saving data to a .bag file instead and then extracting .csv from the bag file.
https://github.com/IntelRealSense/librealsense/issues/1485#issuecomment-380728118
-
Thanks MartyG, I tried saving data to a .bag file and got the same issue.
import pyrealsense2 as rs
import time
# Configure pipeline
pipeline = rs.pipeline()
config = rs.config()
# Enable IMU streams
# Gyro at 200 Hz and Accel at 100 Hz
config.enable_stream(rs.stream.gyro, rs.format.motion_xyz32f, 200)
config.enable_stream(rs.stream.accel, rs.format.motion_xyz32f, 100)
# Record directly to a .bag file
config.enable_record_to_file("imu_data.bag")
# Start streaming
profile = pipeline.start(config)
# Record for 10 seconds
duration = 10.0
start_time = time.time()
try:
while (time.time() - start_time) < duration:
# Grab frames. The data is automatically recorded to the .bag file.
frames = pipeline.wait_for_frames()
except KeyboardInterrupt:
pass
finally:
# Stop the pipeline
pipeline.stop()
print("Recording complete. Data saved to imu_data.bag") -
I tested my IMU with different settings for the accelerometer and gyroscope, and observed the following accelerometer outputs:
• desired_accel_rate = 200, desired_gyro_rate = 400
Accelerometer output: 100Hz
• desired_accel_rate = 100, desired_gyro_rate = 400
Accelerometer output: 85Hz
• desired_accel_rate = 100, desired_gyro_rate = 200
Accelerometer output: 75HzBased on a suggestion to test at 250Hz, I encountered the following error:
Profile = pipeline.start(config)
RuntimeError: Couldn't resolve requestsIt seems my IMU does not support 250Hz for the accelerometer.
Please sign in to leave a comment.
Comments
5 comments