Problem rotating gripper above static point (possible direct IK problem)

Hello,

My starting position of arm is [-300, 200, 300, 180, 0, 0].

I would like to rotate my gripper above current point = I would like to go through yaw values=0, -90, -180, 90

If I go through these yaw angles with motion_type=0, the joint 6 will try to go through limit and will end with error.
If I go through these yaw angles with motion_type=2, the arm start rotating all around at joint1, because inverse kinematics computes joint1 angle in different position:

current serve angles for cartesian position [-300, 200, 300, 180, 0, 0]:
[-213.690053, -16.406818, -34.098552, -0.0, 50.505313, 146.30993, 0.0]
but computed inverse kinematics for identical position:
[146.30993300332835, -16.40681277321326, -34.09853097837308, -5.400791511289653e-06, 50.505338628944465, 146.30993300332835, 0.0]

Notice all values are same, except joint1 is rotated the other way around - I need to avoid that.

Is there any solution for this?

I just need to automatically rotate my tip pointer above static point to verify that TCP offset is correct.

I got the solution: In endless cycle I increase/decrease yaw with small step and I am checking joint 6 angle. If it is over 180/-180 I change direction of yaw change, so there is continuous rotation with variable direction based on joint 6 limits.

Otherwise I still have a question about the inverse kinematics:
If my current cartesian positions is [-300, 200, 300, 180, 0, 0]:
and corresponding joint angles: [-213.690053, -16.406818, -34.098552, -0.0, 50.505313, 146.30993, 0.0]

Why calculated inverse kinematics give those angles (joint1 different position):
[146.30993300332835, -16.40681277321326, -34.09853097837308, -5.400791511289653e-06, 50.505338628944465, 146.30993300332835, 0.0]

There is probably more than one solution for IK, what is the rule for which one is chosen?

Thanks for the feedback, it seems there is a issue with the inverse kinematics method of get_inverse_kinematics(), will look into it and get back to you.