This research aims to systematically solve the obstacle avoidance problem of the long-arm redundant robot painting the inner surface of complex ducts. Firstly, an online collision detection method is proposed based on spatial interpolation. The method is universal for different shapes of ducts, and the accuracy increases with the sample density. Because the position and posture of the robot end link is determined by constraints of the goal position and posture. The obstacle avoidance of end link cannot be performed by redundant degrees of robot. As for inevitable end collision, a method of relaxing the target point attitude constraint is proposed. The collision avoidance direction is used to determine the fastest escape direction of robot end link, and the minimum posture change matrix is calculated for satisfying obstacle avoidance requirements. At the same time, the obstacle avoidance ability of other joints of the redundant robot is optimized, by proposing a optimization algorithm based on the virtual axis of the duct and the fastest escape direction of each joint. The simulation results of the inner surface painting of complex duct verify the effectiveness of the proposed method, solving inevitable end collision problem and improving obstacle avoidance ability of the robot. Compared with the existing methods, the method can deal with the obstacle avoidance problems in more complicated ducts.