SummaryCollaborative robots have to adapt its motion plan to a dynamic environment and variation of task constraints. Currently, they detect collisions and interrupt or postpone their motion plan to prevent harm to humans or objects. The more advanced strategy proposed in this article uses online trajectory optimization to anticipate potential collisions, task variations, and to adapt the motion plan accordingly. The online trajectory planner pursues a model predictive control approach to account for dynamic motion objectives and constraints during task execution. The prediction model relates reference joint velocities to actual joint positions as an approximation of built‐in robot tracking controllers. The optimal control problem is solved with direct collocation based on a hypergraph structure, which represents the nonlinear program and allows to efficiently adapt to structural changes in the optimization problem caused by moving obstacles. To demonstrate the effectiveness of the approach, the robot imitates pick‐and‐place tasks while avoiding self‐collisions, semistatic, and dynamic obstacles, including a person. The analysis of the approach concerns computation time, constraint violations, and smoothness. It shows that after model identification, order reduction, and validation on the real robot, parallel integrators with compensation for input delays exhibit the best compromise between accuracy and computational complexity. The model predictive controller can successfully approach a moving target configuration without prior knowledge of the reference motion. The results show that pure hard constraints are not sufficient and lead to nonsmooth controls. In combination with soft constraints, which evaluate the proximity of obstacles, smooth and safe trajectories are planned.