D435i/D455 IMU Position of the camera in degrees
Hello all,
I have a D435i/D455 here, but unfortunately I can't get to grips with the IMU files right now. Reading out the values is not the problem.
But I would like to know by how many degrees the camera has moved to the original long and I'm not getting anywhere with that right now.
As an example, if I turn the camera horizontally 45 degrees to the left after starting the Python code, I would like to have this displayed by the script.
Does anyone have an idea how this could be done?
Best regards
Peter
-
Hi Peter Toppel One way to implement it may be to create a gyro_start variable to store the original gyro values in. Then create a bool called start. You could set the 'start' bool to True by default. Then place the gyro reading code inside an 'If start = true' block so that the code nested inside the block can only active if start = true. Store the gyro value inside the 'gyro_start' variable. At the end of the code block, set start to False. This should ensure that gyro_start can only be written to on the first loop through the script on the first frame.
Then copy the entire If code block and set its If term to 'If start = false'. This will mean that the code inside this block cannot run until start has been changed from its default state of True to False after the original value is stored. Store the gyro value in the normal 'gyro' variable.
This should ensure that when the script is first run, the 'gyro_start' variable has the original gyro values stored but then can no longer be written to. From that point onwards, the 'gyro' variable will be constantly updating when the camera is rotated. You could therefore print the two variables 'gyro_start' and 'gyro' to show the fixed values stored at the start of the script run, and the live-updating current gyro values from the 'gyro' variable alongside the original values.
Edit: it may be more processing-efficient to put the print instruction for 'gyro_start' inside the "if start = true" code block. Then it will only be printed once instead of constantly printing the same fixed number.
-
Hello, thank you for the input and the idea.
I don't quite 100% understand the approach yet, or I'm failing at the implementation.Have now implemented this as follows (in Python):
import pyrealsense2 as rs
import numpy as np
import time
def initialize_camera():
# start the frames pipe
p = rs.pipeline()
conf = rs.config()
conf.enable_stream(rs.stream.accel)
conf.enable_stream(rs.stream.gyro)
prof = p.start(conf)
return p
def gyro_data(gyro):
return np.asarray([gyro.x, gyro.y, gyro.z])
def accel_data(accel):
return np.asarray([accel.x, accel.y, accel.z])
p = initialize_camera()
first=True
try:
while True:
f = p.wait_for_frames()
accel = accel_data(f[0].as_motion_frame().get_motion_data())
gyro = gyro_data(f[1].as_motion_frame().get_motion_data())
if first==True:
first=False
Start_accel=accel
Start_gyro=gyro
else:
print("accelerometer: ", accel-Start_accel)
#print("gyro: ", gyro)
time.sleep(1)
finally:
p.stop()The result I get now does not make me very happy or the values drift too much.
Am I doing something wrong with the implementation or is there another trick?
Best Regards
Peter
-
I would personally place the 'first=False' line after the Start_accel and Start_gyro lines to ensure that those instructions are carried out before first is set to False so that the code in this If block cannot run again when the script loops around again for the second time onwards.
if first==True:
Start_accel=accel
Start_gyro=gyro
first=False
Using fixed index values (0 for accel and 1 for gyro) instead of setting the indexes dynamically also carries the risk that the accel values will be printed by the gyro print instruction and the gyro values printed by the accel print instruction (i.e the two results are swapped around) as advised by a RealSense team member at the links below.
https://github.com/IntelRealSense/librealsense/issues/6896#issuecomment-665274907
https://github.com/IntelRealSense/librealsense/issues/4018#issuecomment-493919822
In regard to the generated values from the IMU, they are naturally 'noisy' and sensitive. The IMU component in RealSense cameras does not have built-in hardware calibration. The IMU can be calibrated by using the Python IMU tool in the link below and saving the calibration result to the camera hardware once you are satisfied with the result.
https://github.com/IntelRealSense/librealsense/tree/master/tools/rs-imu-calibration
Another approach to refining IMU values is demonstrated in Intel's rs-motion C++ example program, where the 'alpha' value can be increased to weight values towards the gyro instead of the sensitive accel.
https://github.com/IntelRealSense/librealsense/blob/master/examples/motion/rs-motion.cpp#L117
Please sign in to leave a comment.
Comments
3 comments