Autonomous tractor–trailer robots possess a broad spectrum of applications but pose significant challenges in control due to their nonlinear and underactuated dynamics. Unlike the tractor, the motion of the trailer cannot be directly actuated, which often results in a deviation from the intended path. In this study, we introduce a novel method for generating and following trajectories that circumvent obstacles, tailored for a tractor–trailer robotic system constrained by multiple factors. Firstly, leveraging the state information of both the obstacles and the desired trajectory, we formulate an improved trajectory for obstacle avoidance using the nonlinear least squares method. Subsequently, we propose an innovative tracking controller that integrates a universal barrier function with a state transformation strategy. This amalgamation facilitates the accurate tracking of the prescribed trajectory. Our theoretical analysis substantiates that the proposed control methodology ensures exponential convergence of the line-of-sight (LOS) distance and angle tracking errors, while enhancing the transient performance. To validate the efficacy of our approach, we present a series of simulation results, which demonstrate the applicability of the developed control strategy in managing the complex dynamics of tractor–trailer robots.