course sun sensor in matlab

Sun sensors are widely used in satellite control systems for determining the sun's position relative to the satellite. Here's an algorithm in MATLAB for course sun sensor:

main.m
%Define Your Inputs
dt = 0.1; %Time step in seconds
SA = [1 0 0]'; %Initial sun-attitude direction

sun_dir = ; %Define your vector for sun direction measurements
ssang = ; %Define angle of opening of sun sensors
n_ss = ; %Define number of sun sensors

%Initialise the Estimated Sun Direction Vector
SEst = SA;

for i = 1:length(time)
    %Calculate the Magnitude of the Error Vector
    errMag = acos(dot(SA,sun_dir(:,i)));
    
    %Update the Estimated Sun Direction Vector
    SEst = SEst + (errMag*dt*cross(SA,sun_dir(:,i)))/norm(cross(SA,sun_dir(:,i)));
    SA = SEst/norm(SEst);
    
    %Perform Sun Sensor Update
    for j = 1:n_ss
        %Calculate Normal Vector of Sun Sensor j
        nj = cross(SA,sun_dir(:,i))/norm(cross(SA,sun_dir(:,i)));
        
        %Calculate Angle Between Sun Sensor and Sun Direction
        theta = acos(dot(nj,Sun_dir(:,i)));
        
        %If the Angle is Within the Sun Sensor's Field of View
        if theta <= ssang
            %Perform Sun Sensor Update
        end
    end
end
1032 chars
34 lines

Note that this algorithm assumes that the sun sensors have a linear response within their field of view. If the sensors have a non-linear response, or have limited field of view, additional logic and mathematical modeling will be required.

gistlibby LogSnag