This paper considers the optimal design of mechatronic systems with configuration-dependent dynamics. An optimal mechatronic design requires that, among the structural and control parameters, an optimal choice has to be made with respect to design specifications in the different domains. Two main challenges are treated in this paper: the non-convex nature of the optimization problem and the difficulty in modeling serial machines with flexible components and their embedded controllers. The optimization problem is treated using the direct design strategy which considers simultaneously structural and control parameters as variables and adopts non-convex optimization algorithms. Linear time-invariant and gain-scheduling PID controllers are add...