An Optimization Based Approach To Autonomous Drifting