I am trying to model a system composed of 2 bodies connected by a revolute joint. The movement is generated by one of the bodies, while the second body follows along and can oscillate like a pendulum around the revolute joint. What I need in this system is a way to lock the revolute joint at any point in time so that the second body is not moving anymore relative to the first body, and it maintains its orientation with respect to the first body at the time of "locking".
I tried the answer described here, however I don't think this solution is appropriate for revolute joints because I obtained a different behaviour than the one expected. As we can see in the animated gif below, the joint is meant to lock at t=200, and it indeed does not allow any relative movement between the two bodies, however at the moment of locking, the second body "glitches" into a perpendicular orientation with respect to the first body, instead of maintaining its natural orientation. On the other hand, the unlocking behaviour (happening at t=800s) is smooth and expected, as we can see that the orientation between the two bodies is gradually changing.
One other option that i considered is actuating the joint so that it keeps a specific angle, but I am not sure how to determine that angle at any moment in time, and I am worried that this actuation may interfere with the natural dynamics happening when the joint should not be locked.
I may have to replace the revolute joint with a spherical one in the future for more freedom in rotation, ideally the solution for locking the joint should work for both types.
Thank you,
Irina