The traditional time elastic band(TEB) algorithm is prone to abnormal behaviors such as backsliding and large steering in the messy scene planning, which causes acceleration jumps, unsmooth control commands, and large impacts on robots, which is not conducive to the trajectory tracking of the mobile robot. This paper proposes an improved TEB algorithm, which can plan a safer motion trajectory by adding the hazard penalty factor constraint, reduce the maximum impact in motion by adding the acceleration jump suppression constraint, and reduce the end impact by adding the smooth ends constraint, so as to achieve the smooth and accurate arrival of the target point. Then a graph optimization problem is constructed. Taking the pose and time interval of the robot as the nodes, and the objective function and the constraint function as the edges, and the sparsity of the problem is used to quickly obtain the control amount at the corresponding time point. Finally, the performance of the proposed improved TEB algorithm is verified by a large number of comparison tests of robot operating system simulation and physical experiments of real differential robot planning algorithms. The results show that the improved TEB algorithm can plan safer and smoother trajectory in a complex environment, reduce the impact of the robot, and realize more reasonable movement of the robot.