When calculating with the tool, the inverse matrix of the tool is subtracted as if it were a base, it should be the other way around. def ikine_6s(self, T, config, ikfunc): .... if tool is not None: T = tool.inv() * T Must be T = T * tool.inv()