Trajectory planning of robotic manipulators in complex environments involves generating smooth and collision-free paths, and key aspects to consider include dynamic environment perception, path planning, trajectory smoothing and optimization, and obstacle avoidance. This paper discusses different algorithms and finally proposes a fusion of the improved Dung Beetle Optimizer (IDBO) algorithm using chaotic mapping, sinusoidal random mutation, and nonlinear convergence strategies with the bidirectional Rapidly exploring Random Tree (RRT) algorithm to achieve manipulator trajectory planning and minimum jerk optimization trajectory. In the experiment, the IDBO algorithm was compared with other heuristic algorithms. The path obtained was shortened by 9.18% on average, and the calculation time was shortened by 33.81% on average. Then, the paper explored Cartesian coordinate space trajectory planning and joint space trajectory planning when the robot was working in 3D space, and verified the superiority of the latter. In controlling the movement of the robot, by combining the minimum angle jerk planning and the bidirectional RRT obstacle avoidance algorithm to drive the joint angle parameters obtained by the spatial trajectory planning, the trajectory of the robot manipulator can be smoother, more efficient, and avoid obstacles in complex 3D space. This research helps improve the performance, safety, and technical support of robots, and is of great research significance.