When a robot is required to machine a complex curved workpiece with high precision and speed, the tool path is typically dispersed into a series of points and transmitted to the robot. The conventional trajectory planning method requires frequent starts and stops at each dispersed point to complete the task. This method not only reduces precision but also causes damage to the motors and robot. A real-time look-ahead algorithm is proposed in this paper to improve precision and minimize damage. The proposed algorithm includes a path-smoothing algorithm, a trajectory planning method, and a bidirectional scanning module. The path-smoothing method inserts a quintic Bezier curve between small adjacent line segments to achieve $$G^{2}$$
G
2
continuity at the junctions. The trajectory planning method utilizes a quartic polynomial and a double-quartic polynomial that can achieve a constant velocity at the velocity limitation. The bidirectional scanning module calculates the velocity at each trajectory planning segment point, simplifying calculation complexity and can be run in real time. The feasibility of the proposed algorithm is verified through simulations and experiments, which can be run in real time. In addition, high machining precision can be achieved by adjusting the relevant parameters.