-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with assigning accelerometer values to Gameobjects in unity #10858
Comments
Also, comments regarding code smell and unsafe code are appreciated :) |
Hi @TheHarmacist97 I would recommend first trying to put your snippet inside a FixedUpdate() function instead of Update(), as FixedUpdate() should update about 4x faster than Update and is also especially suited for physics calculations and transforms that involve physics. I do not have any advice to offer about code smell and unsafe code though. The official Unity documentation provides the following short article: https://docs.unity3d.com/ScriptReference/PlayerSettings-allowUnsafeCode.html |
Hey @MartyG-RealSense, thanks for the prompt response I still think Update() should be better for the transform control of the camera, as it is not a physics object(no rigidbody) and FixedUpdate has a default time-step of 0.02s (50 times a second) while normal Update has a smaller time-step. Since we're getting 150+ frames per second at the moment, I feel it's best to use change transforms in the Update() function. Thanks for the advice about unsafe code, although I was asking for the capture of the pipeline and disposal of said resources |
A common practice in Unity is to put camera control code in a LateUpdate() function so that it updates last after all of the Update() code has completed. This results in smoother camera movement. There is some RealSense Unity wrapper advice about pipeline disposal and garbage collection at #1477 and #3896 |
Hi @TheHarmacist97 Do you require further assistance with this case, please? Thanks! |
We're still facing the problem with the accelerometer values as mentioned above. |
In a past Unity project that converted RealSense camera movements into movements of a Unity object such as a camera, I applied the following procedure.
MASTER CAMERA JOINT In each of the X, Y and Z joints I created a individual animation clip that would rotate the object backwards and forwards along the full 360 degree axis. Unity animation clips have a playback timeline value between 0 (start) and 1 (end). So by setting a playback value between 0 and 1, you can cause the animation clip to rotate the object between 0 and 360 degrees on that particular axis that the clip is rotating on (X, Y or Z). The tricky part was converting the values provided by the camera into a numeric scale between 0 and 1 to control the forward and backward playback of the animation timeline. In this case, the best way to do that may be to divide the camera gyro angle by 360, so 360 / 360 = 1, 180 / 360 = 0.5, etc. If your scripting can a gyro angle value in degrees then a simpler method may be to simply apply that value directly to the object's X, Y or Z rotation transform. I personally prefer using animation clips though because they are much more stable, as an object may suddenly wildly change orientation if using raw values if there is a glitch in those values. |
Thanks for the advice @MartyG-RealSense , can we use the accelerometer values to translate the camera's position instead of just rotating it. Also, should we lerp the remapped values of the gyro to reduce the unwanted jitter? |
Perhaps the accel value could be used as a multiplier to make the camera travel from position A to position B faster. For example: X, Y or Z position = X, Y or Z position x 9.80. So as the accel value increases above zero, the object starts moving along the axis as the accel value is added to the position, with greater accel values resulting in faster movement. Using lerp to change smoothly between the previous and current states would be a good idea, yes. |
Hey, I really did not understand your previous comment. We wanted to use the D435i's IMU to emulate the values inside unity as if we were using the D435i as a head-mounted unit. So if the person moves 3 meters toward the left, the camera should also move 3 meters toward the left. |
The 400 Series models such as the D435i do not have the inbuilt abilty to track the pose (position + rotation) of the camera device using its IMU. The RealSense T265 Tracking Camera, which has the same IMU component as the D435i, has that feature and has an official T265-only RealSense Unity wrapper example program for SLAM navigation. There is a YouTube video of it at https://www.youtube.com/watch?v=Hhfw3Z4DQ1A |
Hi @TheHarmacist97 Do you require further assistance with this case, please? Thanks! |
Without buying the T265 camera separately, is there any possible solution to achieve the abovementioned objective? |
My understanding is that it is possible to interface with the functions of the RealSense C# wrapper from within Unity, as described by an expert on the subject of C# and Unity at #1570 (comment) and #8347 (comment) There is ony a limited amount of references though about accessing IMU values via the C# wrapper, like those at #8746 (comment) and #2996 (comment) |
Hi @TheHarmacist97 Do you have an update about this case that you can provide, please? Thanks! |
Case closed due to no further comments received. |
My objective is to use the IMU in D435I to move the ingame camera. This includes translation and rotation of said camera in unity
I've tried the following:
The function OnNewSample(Frame frame) is subscribed to the m_pipeline.OnNewSample event and the RSDevice is running on the Unity Thread. This function is used to capture the IMU values sent by the Realsense device.
To use the captured values, I've added this snippet inside the Update() function that are assigning the data to the cameras
We're facing these problems:
@MartyG-RealSense @dorodnic
The text was updated successfully, but these errors were encountered: