Optimal Control for Autonomous Task Execution