Control of electric motors and drives via convex optimization