As robot technology becomes more widespread, its applications in various fields such as daily life, industry, and services have significantly increased. In practical scenarios, robots performing machining tasks are often influenced by external factors or system errors, leading to deviations from the intended path and affecting task completion. This paper aims to investigate the problem of deviations from the intended trajectory during the motion of robot manipulators, with a focus on optimizing compensation for the deviation distance. The research involves the use of a locally weighted method to adjust the deviation distance, reducing the impact of measurement errors. Additionally, a physical impact function is proposed, considering physical factors such as moment of inertia, dynamic friction, and centrifugal force on the deviation distance. The research findings indicate that when ro bot manipulators are chamfering corners, the pre compensation algorithm for deviation distance re duces the deviation distance error from an initial uncorrected range of approximately 0 .22 mm to 0 .83 mm to a range of 0 .02 mm to 0 .34 mm, with a reduction in deviation fluctuation of about 52 .46% . This is significant for improving work efficiency and reducing deviation errors.