Get the robot to choose the desired inverse kinematics solution
Introduction
Many applications require the robot to move to 3D poses (e.g. provided from a camera or computed). In application development, you want to control which direction the robot moves to reach the position, while avoiding joint limits, collisions, etc.
If you just make the robot move with a MoveJ to the target position by providing the target 3D pose, you cannot know which of the 8 potential paths the robot will take.
Solution
Use qNear to force the robot to choose a specific path. A way to do that is to define a Waypoint close to the point where you want to move to (you don't have to move to that waypoint)
At line 8, the robot moves to Waypoint_2, the desired way around
In line 13, the robot only knows the 3D pose, and it chooses to move in a different undesired direction around the base
Solution 1: At lines 17 and 18 we compute the inverse kinematics for the target 3D pose with a qNear from Waypoint_2 (which we knew would lead to moving in the right direction
Solution 2: At lines 22 and 23, we set Waypoint_2 to the new position. The generated script code will behind the scenes compute the inverse kinematics with a qNear at the original Waypoint_2