Rotate a cube using quaternion

Hello, I’m receiving data from Arduino in the form of a quaternion, and I want to use this quaternion to rotate a cube in Unreal Engine. Can someone guide me on how to achieve this? I would appreciate any advice or examples on how to apply quaternion rotations to objects in Unreal Engine. Thank you!

btw: communication between UE and arduino works.

UE converts quats to rotators so you can just plug it as is. Unless you’re after something more specific.


I’m receiving data from Arduino in the form of a quaternion

Somehow I don’t think you actually do, do you? Perhaps you need to build it first?

Parse it?

1 Like

Hello, thank you for the reply. I’m encountering an issue with my project. The problem is that the cube is continuously rotating instead of tilting based on data from the sensor as intended. I would like some guidance on how to address this. The communication between Unreal Engine and Arduino is functioning correctly. I would appreciate advice or examples on how to ensure that the cube only tilts according to the sensor data. Sorry for my newbie questions, I never used blueprints before (I am pretty new here).

As you can see I used Add Local rotation but also it doesnt works with Add World Rotation. I have in the code 50ms delay between serial.print so I set delay in blueprint to 0.05. But there must be something it doesnt work correctly.

I think my quaternions are correct (I mean values of w,x,y,z) because I used before another software for visualizing 3D object and I get from quat roll,pitch and jaw and it worked. I want to use quat data here because of gimbal lock.

What does the data look like ?
Does the arduino send an absolute rotation, or a delta from previous call ?

If it sends an absolute rotation, then you’ll want to use Set(World/Relative)Rotation, otherwise you’d be constantly adding the rotation every cycle.

If it sends a delta rotation, then Add(World/Local)Rotation should be fine, so if it doesn’t work maybe start looking at the data logged by PrintString’s, and verify that it indeed sends zero when there’s no movement.

If you are running into gimbal issues with Add* functions, try convert to quaternions and multiply quaternions then convert back to rotator :

2 Likes

Thank you for the reply. I am sure I get absolute data. I will try your suggestions. I think the problem is in adding the rotation every cycle. Thanks.

Hello, thank you for all the advice; I appreciate it greatly. It’s working, but I still have a small issue. The data is not always read correctly. I’ve increased the baud rate, but it didn’t completely solve the problem. Can you advise me on how to create a condition, for example, if the difference between the values x and x_old is greater than 0.2, then set x = x_old? Alternatively, create a filter that can clean up incorrect values. Thank you very much.

You can abuse the error tolerance in equality operation to skip updating when it’s “close enough”

1 Like

Alternatively, add smoothing/interpolation should help hiding the artifacts naturally

1 Like