Attitude control algorithm for satellites