I am developing a drone gimbal for a camera in UE which has a limit working range(e.g Pitch, Yaw, Roll -30°~30°). I am using SpringArmComponent with SetWorldRotation() to a specified rotation in tick to perform gimbal behaviour.
To limit its rotation whithin the working range in runtime, I calculate its rotation range in world space according to rotation of the owner actor (drone) first each time, and then use a clamp function to limit the specified rotation into the range(e.g for a owner with FRotator(30, 30, 30), the range in world space would come to be 0°~30°).
This works up only if the range of the owner rotation is from -180 to 180. Unfortunately, by using GetOwner()->GetActorRotation(), I find that there may be a gimbal lock that makes the range of result in pitch going to be [-90,90] with a value of 180 in roll and yaw periodically.
Therefore, is there a way to limit the rotation without gimbal lock? To use Quaternion? But how to use Quaternion to clamp the rotation later? Thank you!
I don’t know if it will work in your specific case, but I found the only way around this without using Qs is to only ever add or subtract rotation. Think of it in that way.
So only use AddLocalRotation.
It’s using the Set… nodes that’s the problem.
Thanks for your reply. I can add or subtract rotation, but I don’t think it will work in my case because how large the value it could add is depended on the working range which is ‘changed’ in world space when its owner rotates. Just imagine a camera gimbal with handle (but only has a work range less than 360 in yaw), which tries to keep a camera front all the time. If you rotate the handle over one circle, the camera rotates finally in yaw.
My case is that the gimbal lock happen(?) when I try to get its rotation, which make me hard to find out the correct working range in world space.
Trying to work out the rotation is the problem.
Can you code your control to only add or remove rotation?
I have no idea and I think it is hard to only add or remove rotation because whether it should add or remove is depended on its owner but not itself. It only perform rotation in world space when its owner rotates large enough (to make the gimbal out of the working range). In other word, it would stop adding or removing rotation in local when it is out of the working range.
So the camera is a component of an actor? And the actor can be in any orientation, but the camera will always move relative to the actor? And you want to limit the Z ( relative to the actor )?
Does that sum it up?
Sums it up quite correctly. The camera is a component attached on the SpringArmComponent and will always try to keep its orientation in world space unless it is out of the working range(limit pitch, yaw, roll) I made relative to a rotating moving actor. Transform Z is not limit as it is on the spring arm and can move by following the actor.
Sorry for my poor description, the gimbal should be designed to work like the arrow in this record vedio first below. In your blueprint, the arrow rotate is always followed by its owner.
In my case, it works up until there is a rotation in yaw, like this:
I can’t see this either, but you can download it by clicking the dots on the botton right, the vids are all in mp4 and can play easily. Otherwise, I have to convert it into compression gif file.
So in the first vid, I see the arrow ( boom ) lagging behind the object. But at one point, it overtakes the object. Is that correct?
In the second vid, it doesn’t follow the object rotation correctly.
Exactly correct. The first one shows what a camera gimbal do in usual while the second one shows the problem I met.
What I would recommend, is basically my code, but in 3 dimensions. I think then, the gimbal will follow the drone with a lag. Any over-rotation will come from the spring arm, not the code.
Is that any good? Or am I missing the point here?
I put your code into a staticmech actor, but it still cannot work even in only one axis. Anything wrong with my code? Thank you!
Record vid is also uploaded here:
I have an actor with a camera on boom. I can pan the camera with the mouse wheel, and twist the actor in X using 0:
I am very sorry, it seems that there is still a misunderstanding between what we discussed above. I find some gif pictures for a camera gimbal in web and the gimbal should be work like this:
In our case, the box/drone is the handle in the picture while the input is the orientation controlled by a motor in the second pic. The pic for limit range is not easy to find but I think it is not difficult to imagine with my vid uploaded before.
Apologies
From the first pic, I see that the camera is basically not moving. In this case, the gimbal corresponds to the drone, and the person to the actor. If the person walks forward, the camera will move, otherwise not.
In the second pic, it’s very much a sort of ‘spring arm’ affair, right? But you want to limit the rotation of the arm, I’m guessing.
I’m thinking about it.
YES. I want to limit the rotation of arm. The camera on a gimbal rotates only if the working range is not enough or a user command to let the motor turn. The key point is how to limit it correctly in UE.
I’m looking at it…