In the bolt looseness detection task of the locomotive system, the robot could be used to highly improve the working efficiency and reliability, but faces the complex static obstacles while planning the path for the robotic motion. In this paper, a path optimization technique is proposed to obtain an optimal path with obstacle avoidance for a redundant robot in the static complicated environment. There are three main contributions in this technique. The first is the solving of the inverse kinematics problem for a redundant robot based on the screw theory and the geometric description, which is general to all robots with rotational joints. The second is the modeling of the spatial constraint, where the pseudo distance is defined based on the plane description of the obstacles and calculated using the spatial analytic geometry knowledge. The third is the presentation of the whole path-planning framework based on the above two contributions, which could largely improve the generality of the presented technique. In this framework, the minimum-time path could be obtained while guaranteeing both the motion stability and obstacle avoidance. Moreover, a real setting that includes an obstacle environment and an 8-DOF robot, is taken as an example to better present the technique. Finally, the simulation experiment was performed in Isight software to verify the effectiveness of the path optimization technique.