In this work, a trajectory generation method is proposed to meet the functions of boom positioning, load elimination and obstacle avoidance for the limited working space and motion constraints of the rotary crane. The key point of this paper is that when the position of the static obstacle is known, the depth camera can obtain the random starting three-dimensional space coordinates of the load and the random ending three-dimensional space coordinates, and then an obstacle avoidance trajectory can be automatically generated and tracked by the controller.