Optimal trajectory generation and precision tracking control for multi-axis machines