%%%%%%%%%%%%%%%%%%       Problem Module       %%%%%%%%%%%%%%%%%%

% DEC 24, 2000

% Variation of problem3
% Performs maneuver -Z (there are 8 faults involved.)
% Plan contains 21 actions, performed in 7 steps.



%%%%%%%%%%%%%%%%%%     Initial Situation    %%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%        COMMON PART       %%%%%%%%%%%%%%%%%%%% 

% Initially, the Helium tanks are pressurized. 
% h(pressurized_by(X,X),0) is true iff tank X is pressurized by X  
% at time 0. 
 
h(pressurized_by(ffh,ffh),0). 
h(pressurized_by(foh,foh),0). 
h(pressurized_by(lfh,lfh),0). 
h(pressurized_by(loh,loh),0). 
h(pressurized_by(rfh,rfh),0). 
h(pressurized_by(roh,roh),0). 

 
% All switches are normally in state GPC initially. 
% h(in_state(D,S),0) is true iff device D is in state S at time 0. 

h(in_state(Sw,gpc),0) :- of_type(Sw,v_switch), 
                         not nh(in_state(Sw,gpc),0).

 
% Valves are all normally closed initially. 

h(in_state(V,closed),0) :- of_type(V,valve),
                           not  h(in_state(V,open),0). 
 
% Except the dummy valves which are always open.

stuck(V,open) :- dummy_valve(V).


%%%%%%%%%%%%%%%%%%      Initial Situation       %%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%% FAULTS and OTHER EXCEPTIONS  %%%%%%%%%%%%%%%%%%%% 

has_leak(ffm2).
has_leak(fom3).
has_leak(lfx345).
%has_leak(rfm4).

has_leak(rom1).


stuck(rfi345a,closed).
stuck(roi345b,closed).
stuck(rfi12,closed).
stuck(lx12,closed).

%stuck(rfm2,closed).
stuck(roi345a,closed).

h(in_state(ffm2,open),0).
h(in_state(fom3,open),0).
h(in_state(lfx345,open),0).
%h(in_state(rfm4,open),0).

h(in_state(rom1,open),0).


%stuck_at(fhca_w99,fhca_g5,0).
 
%%%%%%%%%%%%%%%%%%%%%%%%     GOALS     %%%%%%%%%%%%%%%%%%%%%%%%%% 


% A goal must be specified for every subsystem of the RCS.
% If subsystem 's' is not involved in the goal use done(s).  

% Maneuver -Z 

goal(T,fwd_rcs) :- time(T),
                   pair_of_jets(J1,J2),
                   h(ready_to_fire(J1),T),
                   h(ready_to_fire(J2),T).

goal(T,left_rcs) :- time(T), 
                    jet_of(J,left_rcs),
                    direction(J,down),
                    h(ready_to_fire(J),T).
                    
goal(T,right_rcs) :- time(T), 
                     jet_of(J,right_rcs),
                     direction(J,up),
                     h(ready_to_fire(J),T).                    
                   



         

% Checking plan:

%occurs(flip(fm2,closed),0).
%occurs(flip(fm3,closed),1).
%occurs(flip(fha,open),2).
%occurs(flip(fi12,open),3).
%occurs(flip(fi345,open),4).
%occurs(flip(fm1,open),5).
%occurs(flip(fm4,open),6).

%occurs(flip(rm4,closed),0).
%occurs(flip(rha,open),1).
%occurs(open_roi345a,2).
%occurs(open_rfi345b,3).
%occurs(flip(rx345,open),4).
%occurs(flip(rx12,open),5).
%occurs(flip(rm2,open),6).

%occurs(opena_lfhb,0). 
%occurs(open_loi345b,1). 
%occurs(flip(lm3,open),2). 
%occurs(flip(lm4,open),3). 
%occurs(close_lfx345,4).  
%occurs(flip(li12,open),5). 
%occurs(flip(lm2,open),6).
