Either open loop (ie. use mechanical models to predict frame flexing and compensate for them), or closed loop (have sensors to detect realtime head position).
The whole idea of having a frame which is 100% rigid seems like a simplifying assumption that makes everything more expensive, with knock on effects too (eg. making stuff stronger makes them heavier, which in turn means a bigger motor is needed, which uses more power, so a bigger power supply is needed, etc)