Why I can not get the right joint agnles of the position by "get_inverse_kinematics"?

Let’s explain it with a python example.
You can run the scripts below, please remember to change the IP address before you run, please note the xArm will move forward 100mm on X aixs.

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
arm = XArmAPI('192.168.1.100')
arm.motion_enable(enable=True)
arm.set_mode(0)
arm.set_state(state=0)
arm.reset(wait=True)

#move to point A, get IK of PointC at Point A
arm.set_position(207,0,112,180,0,0,wait=True)
IK_pointA_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

#move to point B, get IK of PointC at Point B
arm.set_position(257,0,112,180,0,0,wait=True)
IK_pointB_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

# #move to point C, get IK of PointC at Point C
arm.set_position(307,0,112,180,0,0,wait=True)
IK_pointC_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

arm.reset(wait=True)


print("IK_pointA_C_joints",IK_pointA_C[1])
arm.set_servo_angle(angle=IK_pointA_C[1],wait=True)
print("real_pointA_C_position",arm.get_position())


print("IK_pointB_C_joints",IK_pointB_C[1])
arm.set_servo_angle(angle=IK_pointB_C[1],wait=True)
print("real_pointB_C_position",arm.get_position())


print("IK_pointC_C_joints",IK_pointC_C[1])
arm.set_servo_angle(angle=IK_pointC_C[1],wait=True)
print("real_pointC_C_position",arm.get_position())

Here is a image to show the relationship of point A/B/C

It suppose to be:
IK_pointA_C_joints=IK_pointB_C_joints=IK_pointC_C_joints
real_pointA_C_position=real_pointB_C_position=real_pointC_C_position

But indeed it’s not.
The IK does not converge if the robot is at point A and you are trying to get the IK of point C which is 100mm far away from point A.

If you need get the correct IK of the point C, the position where you get the IK of point C should be very close to the point C, for instance, in 10mm of point C.
Here is an example, the point D is 5mm from the point C.

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
arm = XArmAPI('192.168.1.100')
arm.motion_enable(enable=True)
arm.set_mode(0)
arm.set_state(state=0)
arm.reset(wait=True)

#move to point A, get IK of PointC at Point A
arm.set_position(207,0,112,180,0,0,wait=True)
IK_pointA_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

#move to point B, get IK of PointC at Point B
arm.set_position(257,0,112,180,0,0,wait=True)
IK_pointB_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

# #move to point C, get IK of PointC at Point C
arm.set_position(307,0,112,180,0,0,wait=True)
IK_pointC_C=arm.get_inverse_kinematics([307,0,112,180,0,0])


# #move to point D, get IK of PointC at Point D
arm.set_position(302,0,112,180,0,0,wait=True)
IK_pointD_C=arm.get_inverse_kinematics([307,0,112,180,0,0])

arm.reset(wait=True)


print("IK_pointA_C_joints",IK_pointA_C[1])
arm.set_servo_angle(angle=IK_pointA_C[1],wait=True)
print("real_pointA_C_position",arm.get_position())


print("IK_pointB_C_joints",IK_pointB_C[1])
arm.set_servo_angle(angle=IK_pointB_C[1],wait=True)
print("real_pointB_C_position",arm.get_position())


print("IK_pointC_C_joints",IK_pointC_C[1])
arm.set_servo_angle(angle=IK_pointC_C[1],wait=True)
print("real_pointC_C_position",arm.get_position())


print("IK_pointD_C_joints",IK_pointD_C[1])
arm.set_servo_angle(angle=IK_pointD_C[1],wait=True)
print("real_pointD_C_position",arm.get_position())

Now we get:
IK_pointC_C_joints=IK_pointD_C_joints
real_pointC_C_position=real_pointD_C_position