Optimal Control of Self-Powered Systems Using Primal-Dual Techniques