- Home /
Help around an approach to a "Virtual Motion Table" in Unity
Hello there,
I am testing possibillites for having Unity generate test input for simulation of a software component needing yaw, pitch and roll input. And it seems I am having some problems with fetching the right data, especially I have problems with the correlation between position and speed using Rigidbody objects.
The idea so far has been to make a cube as a table, and then place another cube on top of that one as the object to generate movement for. I add a rigidbody object to both of them, and connect them with a fixed joint with infinite "bindings". I remove all drag, and I freeze their position to only do rotations as the first test. I then try to read angular velocity data and position rotation from the test cube on the top. This data I then send into and DLL I have built waiting for interesting data.
In a FixedUpdate()-function I generate a sinus signal to rotate the the table. I use the RigidBody.AddRelativeTorque() to update the physics. This torque is added to the main table. As mentioned I then try to fetch cool data to input into my software that I want to test.
This is the data I have tried grabbing:
currentInputPlatformData.YawLocalPos = Mathf.Deg2Rad * ObjectOnTableTransform.localRotation.eulerAngles.y;
currentInputPlatformData.YawPos = Mathf.Deg2Rad * ObjectOnTableTransform.rotation.eulerAngles.y;
currentInputPlatformData.YawSpeed = ObjectOnTablePhysics.angularVelocity.y;
currentInputPlatformData.PitchLocalPos = Mathf.Deg2Rad * ObjectOnTableTransform.localRotation.eulerAngles.x;
currentInputPlatformData.PitchPos = Mathf.Deg2Rad * ObjectOnTableTransform.rotation.eulerAngles.x;
currentInputPlatformData.PitchSpeed = ObjectOnTablePhysics.angularVelocity.x;
currentInputPlatformData.RollLocalPos = Mathf.Deg2Rad * ObjectOnTableTransform.localRotation.eulerAngles.z;
currentInputPlatformData.RollPos = Mathf.Deg2Rad * ObjectOnTableTransform.rotation.eulerAngles.z;
currentInputPlatformData.RollSpeed = ObjectOnTablePhysics.angularVelocity.z;
When only doing rotation in "Yaw", meaning around the Y-axis in Unity everything works great! :) I integrate the currentInputPlatformData.YawSpeed and it matches perfectly the currentInputPlatformData.YawPos over time.
However, when I start doing rotations in pitch or roll nothing matches up. I wonder if I am mixing up what I am comparing? Something local and something in world coordinates perhaps? Is the approach for getting angular velocity and rotation position a sensible one in context for yaw, roll, pitch?
On a side note I have also tried to get translations in the same manner, and this seem to work well. I get the Heave, Sway and Surge I am expecting.
Best regards,