Closed mstoelzle closed 2 years ago
@xzhan139 I suggest moving to torsional springs for both the hinge joints and fixed joints. Could you please give me some hints about the previous implementation you have tried out?
Do you guys want me to land the PR to address this issue together with #122 or in separate PR (would need to do this first then) ?
Hi, I think these two questions of yours are interconnected - yes, we opted for moment arm type of connection, not the torsional spring connection, and that's exactly why the twisting torques are not constrained in a fixed joint. This was not a critical issue in our example cases, but it would definitely be a problem if you would need the fixed joint to resist twisting torques, like the example you have here. So essentially, all you need is to switch to torsional spring connection. I am not sure if we have the torsional spring connection implemented in Python (I work primarily with C++), if not, this maybe something you can contribute (you can coordinate with Arman on this). But anyways, I can briefly describe how you can do this, similar with the current scheme - Let's start with constraining one direction of a joint, say, we want to constrain the angle between d_1 of both rod to be 90 degrees. What you need to do is to compute the current angle between the two directors, say 'angle_current', and compute the error 'angle_current - 90'. Then apply torque (scaled with error) with opposite directions to the nearest element at the connection on both rods. Be careful: - the coefficient (scaling factor on error) can be sensitive, especially when you have a complex interconnected structure; and make sure torques have the correct directions, so that the effect of both torques is to reduce the error, otherwise it will explode. Once you have one direction fixed, fixing another one you will have a hinge joint, and fixing all three directions you will have a complete fixed joint, resisting to torques in all directions.
Hi @mstoelzle
You are right current implementation of fixed joint only constrains the bending and it allows twist. Currently PyElastica does not have a joint class uses torsional springs, so I think it will be a good addition.
Do you guys want me to land the PR to address this issue together with #122 or in separate PR (would need to do this first then) ?
I think let's make two different PRs so that each PR has minimal review.
I'm adding this issue to docstring for FixedJoints. (aea196b)
Describe the bug
The current implementation of the FixedJoint based a position spring does not constrain any twisting / torsional torques applied to a straight rod. This happens, because the current approach (essentially) computes an error between the tangential vector of rod 1 and tangential error of rod 2. As rotating around the z-axis / tangential vector does not change this vector, the twisting / torsion is not constrained by the FixedJoint.
In the example below, we have the classic example of two rods connected by a FixedJoint. They are both initially in straight configuration and we apply a UniformTorque to the second rod. For a twisting torque, we notice the faulty behaviour, while for a bending torque everything works as expected.
To Reproduce
Environment
Expected behavior
We expect the FixedJoint to constrain all 6 DoF between the two rods: e.g. no translations or rotations. This should also include twisting / torsional movements in straight rod configuration.
Screenshots
Orientation of last node of rod 1 for torsion torque applied to rod 2:
Here, we would expect the rod 1 to rotate a bit around its z-axis to counteract the torsion torque applied at it's tip at the FixedJoint. However, it doesn't move at all.
Orientation of last node of rod 2 for torsion torque applied to rod 2:
Here, we would expect the rod 2 to rotate a bit around its z-axis to counteract the torsion torque. However, it is clearly not constrained at its base and just freely rotates.
Orientation of last node of rod 1 for bending torque applied to rod 2:
Here, we would expect the rod 1 to rotate a bit around its y-axis to counteract the torsion torque applied at it's tip at the FixedJoint. This is exactly what happens and after a few seconds the elastic systems reaches its steady state.
Orientation of last node of rod 12for bending torque applied to rod 2:
Here, we would expect the rod 2 to rotate a bit around its y-axis to counteract the torsion torque applied. This is exactly what happens and after a few seconds the elastic systems reaches its steady state.