Skip to content
Snippets Groups Projects
Select Git revision
  • 9386643c476e1a5bb551e12b157ae94de154b7fc
  • master default protected
  • v1.0
3 results

gps.m

Blame
  • gps.m 4.26 KiB
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% GPS sensor dynamics %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %STATE  is a struct (called sensor) with the following fields
    %  state   -[string]the current proceural state: no_info, cold_start, read_ephemeris,
    %                   position_available, warm_start_avaialable, warm_start
    %  howLong -[double]when the current procedural state has been entered 
    %  ephExp  -[double]expiration time of ephemeris data
    %  fp      -[int]number of tracked satelliets
    %  eph     -[int]number of satellites for which ephemeris data are available
    
    %INPUTS
    %  -time
    %  -state
    %  -turn on/off (true=turn_ON, false=turn_OFF)
    %  -visible satellites
    
    %OUTPUTS
    %  -state
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    function sensor=gps(time,sensor_in,turn,sv)
    
    %% parameters
    %define how many satellites you need to track given the accuracy requirements
    required_sv= 4;
    %define how long ephemeris data last
    ephDuration=1800.0;
    %define how much time is required to read the ephemeris data
    ttge=59.0;
    %define how much time is required to fetch the satellites signal
    ttfs=0.01;
    
    %% initialize output
    sensor = sensor_in;
    
    %% equations
    %you cannot track satellites that you dont see
    sensor.fp=min(sensor_in.fp,sv);
    sensor.eph=min(sensor_in.eph,sv);
    
    %% events
    ephemeris_expired=(time>sensor.ephExp)||(sensor.eph<required_sv);   %ephemeris data are expired
    lost_visibility=(sensor_in.fp~=sensor.fp)&&(sensor.fp<required_sv);
    fetch_fp=(time-sensor_in.howLong)>=ttfs;
    get_ephemeris=(time-sensor_in.howLong)>ttge;
    
    %% transitions and updates
    %for each of the states handle eventual transitions and updates
    %(i)if any transition is fired, always update the time the surrent state was entered
    %(ii)other updates depend on the spefic transition that is fired
    if strcmp(sensor_in.state,'no_info')
        if(turn)
            sensor.state='cold_start';
            sensor.howLong=time;
        end
    end
    if strcmp(sensor_in.state,'position_available')
        if(get_ephemeris)
            sensor.state='position_available';
            sensor.howLong=time;
            sensor.eph=sv;
            sensor.ephExp=time+ephDuration;
        end
        if(~turn)
            sensor.state='warm_start_available';
            sensor.howLong=time;
            sensor.fp=0;
        end
        if(lost_visibility)
            sensor.state='warm_start';
            sensor.howLong=time;
            %might have to go on to cold_start
                if(ephemeris_expired)
                    sensor.state='cold_start';
                    sensor.howLong=time;
                    sensor.eph=0;
                end
        end
        if(ephemeris_expired)
            sensor.state='read_ephemeris';
            sensor.howLong=time;
            sensor.eph=0;
            %might have to go on to cold_start
                if(lost_visibility)
                    sensor.state='cold_start';
                    sensor.howLong=time;
                end
        end
    end
    if strcmp(sensor_in.state,'read_ephemeris')
        if(get_ephemeris)
            sensor.state='position_available';
            sensor.howLong=time;
            sensor.eph=sv;
            sensor.ephExp=time+ephDuration;
        end
        if(~turn)
            sensor.state='no_info';
            sensor.howLong=time;
            sensor.fp=0;
        end
        if(lost_visibility)
            sensor.state='cold_start';
            sensor.howLong=time;
        end
    end
    if strcmp(sensor_in.state,'warm_start')
        if(lost_visibility)
            sensor.state='warm_start';
            sensor.howLong=time;
        end
        if(fetch_fp)
            sensor.state='position_available';
            sensor.howLong=time;
            sensor.fp=sv;
        end
        if(ephemeris_expired)
            sensor.state='cold_start';
            sensor.howLong=time;
            sensor.eph=0;
        end
        if(~turn)
            sensor.state='warm_start_available';
            sensor.howLong=time;
            sensor.fp=0;
        end
    end
    if strcmp(sensor_in.state,'cold_start')
        if(fetch_fp)
            sensor.state='read_ephemeris';
            sensor.howLong=time;
            sensor.fp=sv;
        end
        if(lost_visibility)
            sensor.state='cold_start';
            sensor.howLong=time;
        end
        if(~turn)
            sensor.state='no_info';
            sensor.howLong=time;
            sensor.fp=0;
        end
    end
    if strcmp(sensor_in.state,'warm_start_available')
        if(turn)
            sensor.state='warm_start';
            sensor.howLong=time;
        end
        if(ephemeris_expired)
            sensor.state='no_info';
            sensor.howLong=time;
            sensor.eph=0;
        end
    end
    
    end