Diffusion MRI is a useful probe of tissue structure. The prototypical diffusion encoding sequence, the single pulsed field gradient, has recently been challenged with the introduction of more general gradient waveforms. Out of these, we focus on q-space trajecory imaging, which generalizes the scalar b-value to a tensor valued property. To take full advantage of its capabilities, it is imperative to respect the constraints imposed by the hardware, while at the same time maximizing the diffusion encoding strength. We formulate this as a constrained optimization problem that accomodates constraints on maximum gradient amplitude, slew rate, coil heating and positioning of radiofrequency pulses. The power of this approach is demonstrated by a c...