# Notebook from Open-MBEE/SE-Cookbook
Path: SysML2x/TMT Model.ipynb

<code>
package 'TMT'{
    import ScalarValues::*;
    import SI::*;

    package 'Components'{
        block 'TMT Project';
    }

    package 'Concerns'{}
    package 'Management'{}
    package 'Roles'{}
    package 'ViewPoints'{}

    package 'Views'{

    }

    package 'Work Packages'{
        package 'Project Systems Engineering'{
            package '01 Components'{
                package 'Operational'
                {

                    package 'Domain'
                    {
                        block 'TMT Operational Domain to-be'{
                            part 'tMT Mission' : 'Mission'::'TMT Mission to-be';
                        }
                    }

                    package 'Mission'{
                        block 'TMT Mission to-be'{
                            private import 'Operational'::'TMT Observatory System'::'Conceptual Design'::'TMT Observatory System Conceptual'::*;

                            part tMTObservatorySystemBlackBoxSpecification : 'TMT Observatory System'::'Conceptual Design'::'TMT Observatory System Conceptual'{
                                //perform workflow; // needed?
                                action workflow: 'TMT Observation WorkFlow - Conceptual Actual';
                                activity 'TMT Observation WorkFlow - Conceptual Actual'(){
                                    first start;
                                    then action targetSelectionObservationSequencingConceptualActual();
                                    then action initializationCalibrationConceptualActual();
                                    then fork forkNode;
                                    succession forkNode then slewIRIS;
                                    succession forkNode then slewWFOS;

                                    action slewIRIS : 'Slew Target with IRIS and NFIRAOS - Conceptual Actual';
                                    then action acquireIRIS : 'Acquire a target with IRIS and NFIRAOS - Conceptual Actual';
                                    then action ditheringIRIS : 'Dithering a target  with IRIS and NFIRAOS - Conceptual Actual';
                                    then action sequencingObservationsWithIRISandNFIRAOSConceptualActual();
                                    then mergeNode;

                                    action slewWFOS : 'Slew Target with WFOS - Conceptual Actual';
                                    then action acquireWFOS : 'Acquire a target with WFOS - Conceptual Actual';
                                    then action ditheringTargetWFOS();
                                    then action sequencingObservationsWFOS();
                                    then mergeNode;

                                    merge mergeNode;
                                    then action dataManagementConceptualActual();
                                    then action postObservingReductionConceptualActual();
                                    then done;
                                }

                                activity 'Acquire a target with WFOS - Conceptual Actual'(){
                                    first start;
                                    then action startAcquisition(); //sleep 0.1s
                                    then fork fork1;
                                    then decide;
                                        if true then acquireNS; //probability ProbabilityAcqTelPoint
                                        else merge1;

                                    action acquireNS : 'Acquire NS Telescope Pointing Conceptual';
                                    then merge merge1;

                                    then fork fork2;
                                    then decide;
                                        if true then acquireTTF; //probability ProbabilityAcqTTFOIWFS
                                        else merge2;

                                    action acquireTTF : 'Acquire and Lock TTF OIWFS NS Conceptual Actual';
                                    then merge merge2;

                                    then fork fork3;
                                    then action acquisitionFinish(); //sleep 0.1s
                                    then done;
                                } // activity Acquire a target with WFOS - Conceptual Actual

                                activity 'Slew Target with IRIS and NFIRAOS - Conceptual Actual'(){}
                                activity 'Acquire a target with IRIS and NFIRAOS - Conceptual Actual'(){}
                                activity 'Dithering a target  with IRIS and NFIRAOS - Conceptual Actual'(){}
                                activity 'Slew Target with WFOS - Conceptual Actual'(){}
                            } // part tMTObservatorySystemBlackBoxSpecification

                            value ProbabilityAcqTelPoint : Real = 0.0;
                            value ProbabilityBTOOP : Real = 0.0;
                            value ProbabilityChkLaserProp : Real = 0.0;
                            value ProbabilityAcqLckLGS : Real = 0.0;
                            value ProbabilityAcqPwfsFirst : Real = 0.0;
                            value ProbabilityAcqTTFOIWFS : Real = 0.0;
                            value ProbabilityAcqPwfsSecond : Real = 0.0;
                            value ProbabilityAcqTTOIWFSODGW : Real = 0.0;
                            value ProbabilityAcqTruthODGWOIWFS : Real = 0.0;
                            value TotalAcquisitionTime : Real;
                        } // block 'TMT Mission to-be'
                        block 'TMT Mission to-be Group0' :> 'TMT Mission to-be'  {
                            redefines 'TMT Mission to-be'::ProbabilityAcqTelPoint = 1.0;
                            redefines 'TMT Mission to-be'::ProbabilityBTOOP = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityChkLaserProp = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqLckLGS = 1.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqPwfsFirst = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqTTFOIWFS = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqPwfsSecond = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqTTOIWFSODGW = 0.0;
                            redefines 'TMT Mission to-be'::ProbabilityAcqTruthODGWOIWFS = 0.0;
                            redefines 'TMT Mission to-be'::TotalAcquisitionTime;
                        } // block 'TMT Mission to-be Group0'
                        block 'TMT Mission to-be Group1' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Group2' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Group3' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Group4' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Group5' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Group6' :> 'TMT Mission to-be';
                        block 'TMT Mission to-be Random' :> 'TMT Mission to-be';
                    } // package 'Mission'

                    package 'Operational Use Cases'{}

                    package 'TMT Observatory System'
                    {
                        package 'Black Box Specification'
                        {
                            package 'TMT Requirements imported from DOORS'{}
                            block 'TMT Observatpry System Black Box Specification';
                        }

                        package 'Black Box Specifications for Suppliers'
                        {
                            block 'APS Black Box Specification TMT';
                            block 'M1CS Black Box Specification TMT';
                        }

                        package 'Conceptual Design'
                        {
                            block 'Common Services'{
                                port CS2PEASIn;
                                port CS2PEASOut;
                            }
                            block 'Executive Software'{
                                port ESW2PEASIn;
                                port ESW2PEASOut;
                                port GCDataIn;
                                port ESW2TCSOut;
                                port ESW2TCSIn;
                                port ESW2GCOut;
                                port ESW2GCIn;
                                port ESW2AOSeqOut;
                                port ESW2AOSeqIn;
                            }
                            block 'ESW-ACQ'{
                                value numloop : Integer;
                                value i : Integer;
                            }
                            block 'ESW Seq'{}
                            block 'M1 Control System'{
                                port m1cs2PEASIn;
                                port m1cs2PEASOut;
                            }
                            block 'Mount Control System'{}
                            block 'Telescope Control System'{
                                port TCS2PEASIn;
                                port TCS2PEASOut;
                                port guideCamDataIn;
                            }

                            block 'Telescope Control System'{}
                            block 'TMT Observatory System Conceptual'{
                                // perform acquireNS ?
                                action acquireNS: 'Acquire NS Telescope Pointing Conceptual'; // ADDED cause classifier

                                activity 'Acquire NS Telescope Pointing Conceptual'(){
                                    first start;
                                    then action setAcqTime(){ /* TotalAcqTimeAcqTelPoint= simtime */}
                                    then action acquireWFOS: 'Acquire Telescope Pointing w/WFOS Conceptual Actual';
                                    then action setDiff(){/* TotalAcqTimeAcqTelPoint= simtime - TotalAcqTimeAcqTelPoint */}
                                    then done;
                                } // END activity 'Acquire NS Telescope Pointing Conceptual'

                                activity 'Acquire and Lock TTF OIWFS NS Conceptual Actual'(){
                                    first start;
                                    then action 'Start TTF OIWFS Acquisition and Lock'(){/* sleep 1s */}
                                    then merge merge1;
                                    then decide;
                                        if true then merge2; //no dithering step
                                        else merge4; //dithering step

                                    merge merge2;
                                    then action 'OIWFS Continuous Exposure'(){/* sleep 1s */}
                                    then fork fork1;
                                        then merge3;
                                        then action 'Subscribe OIWFS'(in argument);

                                    succession 'Subscribe OIWFS' then 'VIZ OIWFS image';
                                    action 'VIZ OIWFS image'();

                                    merge merge3;
                                    then action 'DETECTOR_EXPOSURE(CONTINUOUS)'(out Pixels){/* sleep 1s */}
                                    then action 'Pixel Processing'(in argument flow from 'DETECTOR_EXPOSURE(CONTINUOUS)'::Pixels, out NGSFlux, out GSOffset, out LockStatus){/* sleep 5 to 10s*/}

                                    succession 'Pixel Processing' then 'GS found?';
                                    succession 'Pixel Processing' then join1;
                                    succession 'Pixel Processing' then join2;

                                    action 'GS found?'(){/* sleep 1s */}
                                    then decide decide1;
                                        if true then 'Found but Faint';//warning probability condition
                                        else merge5;
                                    action 'Found but Faint'();
                                    then decide;
                                        if true then join1;
                                        else 'Adjust exposure time';
                                    action 'Adjust exposure time'();
                                    then merge3;

                                    join join1;
                                    then action 'OFFSET need it?'(){/*sleep 1s*/}
                                    then decide;
                                        if true then 'Offset Telescope';//warning probability condition
                                        else 'Close T/T/F Loop';
                                    action 'Close T/T/F Loop'(){/*sleep 1s*/}
                                    then action 'ENABLE_close loop'(){/*sleep 1s*/}
                                    then action 'Reduce window size'(){/*sleep 2 to 5s*/}
                                    then action 'reduce Window size'(){/*sleep 2 to 5s*/}
                                    then join2;

                                    join join2;
                                    then merge merge4;
                                    then action 'Lock Fail?'(){/*sleep 1s*/}
                                    then decide;
                                        if true then merge6;//warning probability condition
                                        else merge5;

                                    merge merge5;
                                    then action 'Request Backup GS?'(){/*sleep 5 to 10s*/}
                                    then decide;
                                        if true then 'Slew New Guide start(s)';
                                        else merge6;

                                    action 'Slew New Guide start(s)'();
                                    then action 'SlewTarget with WFOS Conceptual Actual'();
                                    then merge1;

                                    action 'Offset Telescope'(){/*sleep 1 to 2s*/}
                                    then merge2;

                                    merge merge6;
                                    then action 'TTF OIWFS Acquisition and Lock Finish'(){/*sleep 1s*/}
                                    then done;
                                } // END activity 'Acquire and Lock TTF OIWFS NS Conceptual Actual'

                                activity 'Acquire Telescope Pointing w/WFOS Conceptual Actual'(){
                                    first start;
                                    then action 'Pointing Acquisition start'(){/* lasts 0.1s */}
                                    then action 'Take images in continuous mod'(out result){/* lasts 0.1s */}
                                    succession  'Take images in continuous mod' then 'Subscribe Instrument';
                                    succession  'Take images in continuous mod' then 'Take image in Continuous Mode';
                                    action 'Subscribe Instrument'(in argument flow from 'Take images in continuous mod'::result);
                                    action 'Take image in Continuous Mode'(out result){/* lasts 1 to 10s */}
                                    then merge mergeNode1;
                                    then action 'Compute Telescope Offset'(in argument flow from 'Take image in Continuous Mode'::result){/* sleep 1s to 5s */}
                                    then action 'Update Pointing model'(out result){/* lasts 0.1s */}
                                    then action 'Update position Mount'(in argument flow from 'Update Pointing model'::result, out result);
                                    then action 'message:Telescope Ready'(in argument flow from 'Update position Mount'::result);
                                    then action 'Target Identify OK?'();
                                    then decide decide1;
                                        if true then 'Offset good< 1 arcrsec';
                                        else 'User manual identification of target';

                                    action 'Offset good< 1 arcrsec'(){/* lasts 1s*/}
                                    then decide decide2;
                                        if true then 'Stop continuous mode';
                                        else loopBack;

                                    merge loopBack;
                                    then mergeNode1;

                                    action 'User manual identification of target'(){/* lasts 1 to 20s */}
                                    then loopBack;

                                    action 'Stop continuous mode'(){/* lasts 0.1s */}
                                    then action 'Stop Continuous mode'(){/* lasts 0.1s */}
                                    then action 'detector stop reading ready'(){/* lasts 0.1s */}
                                    then action 'previously SWAP GS and Target ?'(){/* lasts 0.1s */}
                                    then decide decide3;
                                        if true then 'UNSWAP/Apply Instrument Hotspot and Target/GS';
                                        else mergeNode2;

                                    action 'UNSWAP/Apply Instrument Hotspot and Target/GS'(){/* lasts 0.1s */}
                                    then action 'Update pointing model'(out result){/* lasts 0.1s */}
                                    then action 'update Position Mount'(in argument flow from 'Update pointing model'::result, out result){/*lasts 1 to 5s*/}
                                    then action 'Message Telescope Ready'(in argument flow from 'update Position Mount'::result){/*lasts 0.1s*/}
                                    then merge mergeNode2;
                                    then action 'Pointing Acquisition End'(){/*lasts 0.1s*/}
                                    then done;
                                } // END activity 'Acquire Telescope Pointing w/WFOS Conceptual Actual'

                                part 'eSW-ACQ' : 'ESW-ACQ'{
                                    perform acquireNS::acquireWFOS::'Subscribe Instrument'; // ADDED
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Subscribe Instrument';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'User manual identification of target';
                                }
                                part 'eSW Seq' : 'ESW Seq'{
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::start;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Pointing Acquisition start';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Take images in continuous mod';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Stop continuous mode';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'detector stop reading ready';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'previously SWAP GS and Target ?';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::decide3;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::mergeNode2;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Pointing Acquisition End';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::done;
                                }
                                part 'wFOS-Seq' : 'WFOS Seq'{
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Take image in Continuous Mode';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Stop Continuous mode';
                                }
                                part tcs : 'Telescope Control System'{
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::loopBack;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::mergeNode1;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Compute Telescope Offset';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Update Pointing model';
                                    //perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'message:Telescope Ready'; //warning crashes for unknown reason
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Target Identify OK?';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::decide1;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Offset good< 1 arcrsec';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::decide2;
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'UNSWAP/Apply Instrument Hotspot and Target/GS';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Update pointing model';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Message Telescope Ready';
                                }
                                part mcs : 'Mount Control System'{
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'Update position Mount';
                                    perform 'Acquire Telescope Pointing w/WFOS Conceptual Actual'::'update Position Mount';
                                }
                            }
                        block 'WFOS Seq'{}

                        }
                    }
                }
            }
        }

        //sublevel of Work Package
        package 'Telescope'{
            package '01 Components'{
                package 'Interface Definitions'
                {
                    package 'APS-M1CS'
                    {
                        block 'APS Data';
                        block 'APS to M1CS interface'{/* ports */ }
                        block 'M1CS Data';
                        block 'M1CS to APS interface'{/* ports */ }
                    }
                }

                package 'Operational'
                {
                    package 'Telescope'
                    {
                        package 'Black Box Specification'{
                            block 'Telescope Black Box Specification';
                        }
                    }
                }
            }

            package 'WorkPackages'{
                package 'Control'{
                    package 'Alignment and Phasing System'
                    {
                        package 'APS Optical Bench Development'
                        {
                            package 'Components'{}
                            block 'APS Optical Bench Development';
                        }
                        package 'PEAS-PCS Development'
                        {
                            package 'Components'{}
                            block 'PEAS-PCS Development';
                        }

                        package 'Systems Engineering'{

                            package '01 Components'{
                                package 'Operational'{

                                    package 'APS'{

                                        package 'Black Box Specification'{
                                            package 'Requirements'{
                                                //whole lot of requirements, not impremented yet?
                                            }
                                            package 'Structure'{
                                                block 'APS Operational Blackbox Specification JPL'{
                                                    port PEAS2M1CSOut;
                                                    port PEAS2TCSIn;
                                                    port PEAS2TCSOut;
                                                    port PEAS2ESWIn;
                                                    port PEAS2ESWOut;
                                                    port PEAS2M1CSIn;
                                                    port PEAS2CSIn;
                                                    port PEAS2CSOut;
                                                    port APS2UserIn;
                                                    port APS2UserOut;
                                                    port GC2ESWIn;
                                                    port GC2ESWOut;
                                                    port GCDataOut;
                                                }
                                            }
                                            package 'Use Cases'{}
                                        }

                                        package 'Conceptual Design'
                                        {
                                            private import 'Black Box Specification'::'Structure'::*;
                                            private import 'Mission'::*;

                                            package 'Components'
                                            {
                                                block 'Acquisition Pointing and Tracking Assembly'{
                                                    port APTA2APTLInt;
                                                    port APTA2APTLOut;
                                                    port PEAS2APTIn;
                                                }
                                                block 'APT Loop'{
                                                    port APTIn;
                                                    port APTOut;
                                                    port APTL2APTAOut;
                                                    port APTL2APTAIn;
                                                    port APTDataOut;
                                                }
                                                block 'BeamSplitterStage'{
                                                    port bss2peasOut;
                                                    port bss2peasIn;
                                                }
                                                block 'Internal Source'{
                                                    port IS2PEASIn;
                                                    port IS2PEASOut;
                                                }
                                                block 'K-mirror'{
                                                    port KM2PEASIn;
                                                    port KM2PEASOut;
                                                }
                                                block 'PEAS PIT Tracking'{
                                                    port PIT2PEASIn;
                                                    port PIT2PEASOut;
                                                    port PITT2PITAOut;
                                                    port PITT2PITAIn;
                                                    port PITDataOut; //might need typing (cf SysMLv1 model)
                                                    port PIT2TCSOut;
                                                    port PIT2TCSIn;
                                                    port PIT2KMirrorOut;
                                                    port PIT2KMirrorIn;
                                                    port PIT2SPOut;
                                                    port PIT2SPIn;
                                                }
                                                block 'Procedure Executive and Analysis Software'{
                                                    private import 'Interchange functions'::'External'::'Cmd_M1CS'::*;
                                                    private import 'Interchange functions'::'External'::'Cmd_TCS'::*;
                                                    private import 'Interchange functions'::'Internal'::'Cmd_SH'::*;
                                                    private import 'Interchange functions'::'Operator'::*;
                                                    private import 'PEAS Algorithms'::*;

                                                    port PEAS2SHOut;
                                                    port PEAS2SHIn;
                                                    port PEAS2M1CSOut;
                                                    port PEAS2M1CSIn;
                                                    port PEAS2TCSOut;
                                                    port PEAS2TCSIn;
                                                    port User;
                                                    port PEAS2InsourceIn;
                                                    port PEAS2InsourceOut;
                                                    port PEAS2PITTrackOut;
                                                    port PEAS2PITTrackIn;
                                                    port PEAS2APTLoopOut;
                                                    port PEAS2CSOut;
                                                    port PEAS2CSIn;
                                                    port PEAS2KMOut;
                                                    port PEAS2KMIn;
                                                    port PEAS2SPOut;
                                                    port PEAS2SPIn;
                                                    port PEAS2ESWOut;
                                                    port PEAS2ESWIn;
                                                    port PEAS2APTLoopIn;
                                                    port toMBClock;
                                                    port PEAS2PITDataIn; //might need typing
                                                    port peas2bssOut;
                                                    port peas2bssIn;
                                                    port PEAS2PITOut;
                                                    port PEAS2APTOut;
                                                    port PEAS2PITIn;
                                                    port peas2StimulusOut;
                                                    port peas2StimulusIn;

                                                    action itinializePEAS{
                                                                first start;
                                                                then action : 'Interchange functions'::'External'::'Cmd_M1CS'::'Get_Installed_Segment';
                                                                then action check(out isPhasable): 'PEAS Algorithms'::'Check Mirror Phasebility';
                                                                succession check then setValue;
                                                                succession check then peasInitialize;
                                                                action setValue(p flow from check::isPhasable){/* set isMirrorPhasable=1 */}
                                                                action peasInitialize{/* set peasInitialize=true */}
                                                                //then send 'sendInitComplete' of 'InitComplete'() to <needs a part>;
                                                                then done;
                                                    }
                                                    exhibit smBehavior;
                                                    state smBehavior : PEAS_Behavior;
                                                    state def 'PEAS_Behavior' {
                                                        entry action initial; then Initializing;
                                                        state Initializing{
                                                            do itinializePEAS;
                                                        }
                                                        transition 'Initializing-StandBy'
                                                            first Initializing
                                                            accept 'InitComplete'
                                                            then StandBy;
                                                        state StandBy;
                                                        transition 'StandBy-Finish'
                                                            first StandBy
                                                            accept 'Finished'
                                                            then Done;
                                                        state Done; // Is that "Done" as you would expect in an activity?

                                                        transition 'StandBy-PostSegmentExchAl'
                                                            first StandBy
                                                            accept 'Post-Segment Exchange Alignment'
                                                            then 'Post-Segment Exchange Alignment';
                                                        transition 'PostSegmentExchAl-StandBy'
                                                            first 'Post-Segment Exchange Alignment'
                                                            accept 'Abort'
                                                            then StandBy;

                                                        transition 'StandBy-MaintenanceAlignment'
                                                            first StandBy
                                                            accept 'Maintenance Alignment'
                                                            then 'Maintenance Alignment';
                                                        transition 'MaintenanceAlignment-StandBy'
                                                            first 'Maintenance Alignment'
                                                            accept 'Abort'
                                                            then StandBy;

                                                        transition 'StandBy-TakingOffAxisMeasurements'
                                                            first StandBy
                                                            accept 'Taking Off-Axis Measurements'
                                                            then 'Taking Off-Axis Measurements';
                                                        transition 'TakingOffAxisMeasurements-StandBy'
                                                            first 'Taking Off-Axis Measurements'
                                                            accept 'Abort'
                                                            then StandBy;

                                                        state 'Post-Segment Exchange Alignment' {
                                                            entry action initial; then 'Coarse Tilt Alignment';
                                                            state 'Coarse Tilt Alignment' {
                                                                do coarseTiltAlignment : 'Coarse Tilt Alignment';
                                                            } // end state 'Coarse Tilt Alignment'
                                                            then 'Broad Band Phasing 30um';
                                                            state 'Broad Band Phasing 30um' {
                                                                do broadBandPhasing : 'Broad Band Phasing';
                                                            } // end state 'Broad Band Phasing'
                                                            then 'Minimize Sensor Readings';
                                                            state 'Minimize Sensor Readings' {
                                                                do action minimizeSensorReadings{/* TODO */};
                                                            } // end state 'Minimize Sensor Readings'
                                                            then 'Correcting Rigid Body and Segment Figure Iteration 1';
                                                            state 'Correcting Rigid Body and Segment Figure Iteration 1' {
                                                                do rigidBodySegmentFigureCorrection : 'Rigid Body and Segment Figure correction';
                                                            } // end state 'Rigid Body and Segment Figure Iteration 1'
                                                            then 'Correcting Rigid Body and Segment Figure Iteration 2';
                                                            state 'Correcting Rigid Body and Segment Figure Iteration 2' {
                                                                do rigidBodySegmentFigureCorrection : 'Rigid Body and Segment Figure correction';
                                                            } // end state 'Rigid Body and Segment Figure Iteration 2'
                                                            then 'Broad Band Phasing 3um';
                                                            state 'Broad Band Phasing 3um' {
                                                                do broadBandPhasing : 'Broad Band Phasing';
                                                            } // end state 'Broad Band Phasing'
                                                            then 'Broad Band Phasing 1um';
                                                            state 'Broad Band Phasing 1um' {
                                                                do broadBandPhasing : 'Broad Band Phasing';
                                                            } // end state 'Broad Band Phasing'
                                                            then 'Narrow Band Phasing';
                                                            state 'Narrow Band Phasing'{
                                                                do NBPhasing: 'Narrow Band Phasing';
                                                            }// end 'Narrow Band Phasing'
                                                            then StandBy;
                                                        } // end state 'Post-Segment Exchange Behavior'

                                                        state 'Maintenance Alignment'{
                                                            entry action intial; then 'Correcting Rigid Body and Segment Figure';
                                                            state 'Correcting Rigid Body and Segment Figure'{
                                                                do rBSFcorrection : 'Rigid Body and Segment Figure correction'(/* parameters? */);
                                                            }
                                                            then 'Broad Band Phasing 1um';
                                                            state 'Broad Band Phasing 1um'{
                                                                do BBPhasing: 'Broad Band Phasing';
                                                            }// end 'Broad Band Phasing'

                                                            transition 'BroadBandPhasing-NarrowBandPhasing'
                                                                first 'Broad Band Phasing'
                                                                accept 'Finished' // in the model it is a complicated Opaque Expression
                                                                then 'Narrow Band Phasing';

                                                            state 'Narrow Band Phasing'{
                                                                do NBPhasing: 'Narrow Band Phasing';
                                                            }// end 'Narrow Band Phasing'
                                                            then StandBy;
                                                        } // end state 'Maintenance Alignment'

                                                        state 'Taking Off-Axis Measurements'{
                                                            entry action initial; then 'Acquire Star in Center Field';
                                                            state 'Acquire Star in Center Field'{
                                                                do setupAPS : 'Setup APS, Acquire and Start Guiding';
                                                            }
                                                            transition 'Acquire Star in Center Field-Stopping guiding'
                                                                first 'Acquire Star in Center Field'
                                                                accept 'Finished'
                                                                then 'Stopping guiding';
                                                            state 'Stopping guiding'{
                                                                do commandTCS : 'Command TCS to Stop Guiding'
                                                            }
                                                            transition 'Stopping guiding-Stop PIT Tracking'
                                                                first 'Stopping guiding'
                                                                accept 'Finished'
                                                                then 'Stop PIT Tracking';
                                                            state 'Stop PIT Tracking'{
                                                                do stopPIT : 'Stop PIT Tracking'
                                                            }
                                                            transition 'Stop PIT Tracking-Prepare'
                                                                first 'Stop PIT Tracking'
                                                                accept 'Finished'
                                                                then 'Prepare';
                                                            state 'Prepare'{
                                                                state 'SUBSTATE_1'{
                                                                    entry action initial; then 'Offset Telescope in Field of View';
                                                                    state 'Offset Telescope in Field of View'{
                                                                        do action 'Command Telescope Offset in ADapparent'(){};
                                                                    }
                                                                    transition 'Offset Done'
                                                                        first 'Offset Telescope in Field of View'
                                                                        accept 'FinishedTelOffset'
                                                                        then 'Offset Done';
                                                                    state 'Offset Done';
                                                                }
                                                                state 'SUBSTATE_2'{
                                                                    entry action initial; then 'Moving M3 to bring star back to center field';
                                                                    state 'Moving M3 to bring star back to center field'{
                                                                        do action 'Send M3 Offset'(){};
                                                                    }
                                                                    transition 'M3 Done'
                                                                        first 'Moving M3 to bring star back to center field'
                                                                        accept 'FinishedM3Offset'
                                                                        then 'M3 Done';
                                                                    state 'M3 Done';
                                                                }
                                                                state 'SUBSTATE_3'{
                                                                    entry action initial; then 'Moving M2 to correct Piston';
                                                                    state 'Moving M2 to correct Piston'{
                                                                        do action 'Send M2 PTT Cmd'(){};
                                                                    }
                                                                    transition 'M2 Done'
                                                                        first 'Moving M2 to correct Piston'
                                                                        accept 'FinishedM2Offset'
                                                                        then 'M2 Done';
                                                                    state 'M2 Done';
                                                                }
                                                                state 'SUBSTATE_4'{
                                                                    entry action initial; then 'Correcting Pupil Location with APS';
                                                                    state 'Correcting Pupil Location with APS'{
                                                                        do action 'Move BSS'(){};
                                                                    }
                                                                    transition 'Pupil Done'
                                                                        first 'Correcting Pupil Location with APS'
                                                                        accept 'FinishedPupil'
                                                                        then 'Pupil Done';
                                                                    state 'Pupil Done';
                                                                }
                                                            } // end 'Prepare'
                                                            transition 'Prepare' then 'Start PIT Tracking';
                                                            state 'Start PIT Tracking'{
                                                                do action 'Start PIT Tracking'(){}
                                                            } // end 'Start PIT Tracking'
                                                            transition 'Start PIT Tracking-Measuring zernikes off axis'
                                                                first 'Start PIT Tracking'
                                                                accept 'Finished'
                                                                then 'Measuring zernikes off-axis';
                                                            state 'Measuring zernikes off-axis'{
                                                                do action 'MeasureZernikesLoop'(){}
                                                            } // end 'Measuring zernikes off-axis'
                                                            transition 'Measuring zernikes off axis-Selecting Next Field Point'
                                                                first 'Measuring zernikes off-axis'
                                                                accept 'Finished'
                                                                then 'Selecting Next Field Point'
                                                            state 'Selecting Next Field Point'{
                                                                do action 'SelectNextTarget'
                                                            } // end 'Selecting Next Field Point'

                                                            transition 'Selecting Next Field Point-Stop PIT Tracking'
                                                                first 'Selecting Next Field Point'
                                                                accept 'NextPointInMap'
                                                                then 'Stop PIT Tracking'
                                                            transition 'Selecting Next Field Point-Restoring Positions'
                                                                first 'Selecting Next Field Point'
                                                                accept 'Finished'
                                                                then 'Restoring Positions'

                                                            state 'Restoring Positions'{
                                                                do action 'RestorePositions'(){}
                                                            } // end 'Restoring Positions'
                                                            transition 'Restoring Positions-StandBy'
                                                                first 'Restoring Positions'
                                                                accept 'Finished'
                                                                then 'StandBy'
                                                        } // end 'Taking Off-Axis Measurements'
                                                    } // end statemachineType 'PEAS_Behavior'

                                                    activity 'Coarse Tilt Alignment'(){
                                                        first start;
                                                        then action : 'Setup APS, Acquire and Start Guiding'(){}
                                                        then action (){/* i = 1;*/}
                                                        then merge merge1;
                                                        //TODO Finish
                                                        action : 'Adjust Position According to Spiral Search Pattern'(){}
                                                        action : 'Ask OP to Send Segment PTT'(){}
                                                        action : 'Calculate Centroid Offsets'(){}
                                                        action : 'Calculate Segment PTT'(){}
                                                        action : 'Calculate Telescope Pointing Offset'(){}
                                                        action : 'Check If All Spots Present'(){}
                                                        action : 'Command Telescope Offset in Pixel'(){}
                                                        action : 'Display Results to APS Operator'(){}
                                                        action : 'Find and identify'(){}
                                                        action : 'Move to Previous M1CS Configuration'(){}
                                                        action : 'Save M1CS Configuration'(){}
                                                        action : 'Send Segment PTT'(){}

                                                        action : 'Take SH Exposure'(){}
                                                        action : 'Throw Telescope Alignment Exception'(){}
                                                    } // end activity 'Coarse Tilt Alignment'

                                                    activity 'Adjust Position According to Spiral Search Pattern'(){}
                                                    activity 'Check If All Spots Present'(){}
                                                    activity 'Move to Previous M1CS Configuration'(){}
                                                    activity 'Setup APS, Acquire and Start Guiding'(){}
                                                    activity 'Rigid Body and Segment Figure correction'(in commandWarpingHarness,
                                                                                in doGuide,
                                                                                in doAcquisition){
                                                        // TODO
                                                    }
                                                    activity 'Broad Band Phasing'(in band,
                                                                                in acquireNewStar,
                                                                                in doGuide){

                                                    }
                                                    activity 'Narrow Band Phasing'(){}
                                                    activity 'Command TCS to Stop Guiding'(){}
                                                    activity 'Stop PIT Tracking'(){}
                                                }
                                                block 'Pupil and Image Tracking Assembly'{
                                                    port PITA2PITTIn;
                                                    port PITA2PITTOut;
                                                    port PEAS2PITIn;
                                                    port PEAS2PITOut;
                                                }
                                                block 'SH camera'{
                                                    port CC_SH2PEASIn;
                                                    port CC_SH2PEASOut;
                                                }
                                                block 'Shear plate'{
                                                    port SP2PEASIn;
                                                    port SP2PEASOut;
                                                }
                                                block 'Stimulus'{
                                                    port stimulus2PeasOut;
                                                    port stimulus2PeasIn;
                                                }
                                                value second : s;
                                            }

                                            package 'Interchange functions'
                                            {
                                                package 'External'
                                                {
                                                    package 'Cmd_M1CS'
                                                    {
                                                        private import 'Signals'::'APS External'::'PEAS-CommonService'::*;
                                                        activity 'Calibrate Warping Harness'(){}
                                                        activity 'Get Segment WH Pos'(){}
                                                        activity 'Get_Installed_Segment'(){
                                                            first start;
                                                            then fork fork1;
                                                            succession fork1 then 'Get installed_Segment_Query';
                                                            succession fork1 then 'Get installed_Segment_Ack';
                                                            send 'Get installed_Segment_Query' of 'Get installed_Segment_Query'() to 'Components'::'Procedure Executive and Analysis Software'::PEAS2M1CSOut;
                                                            then join1;
                                                            accept 'Get installed_Segment_Ack'(installedAck :'Get installed_Segment_Ack');
                                                            then join1;
                                                            join join1;
                                                            then done;
                                                        }
                                                        activity 'Save M1CS Configuration'(){}
                                                        activity 'Send Segment PTT'(){}
                                                        activity 'Send Segment WH Cmd'(){}
                                                        activity 'Set WH Strain'(){}
                                                        activity 'Turn Warping Harnesses Off'(){}
                                                        activity 'Turn Warping Harnesses On'(){}
                                                        activity 'Zeroing Sensor Readings'(){}
                                                    }
                                                    package 'Cmd_TCS'
                                                    {
                                                        activity 'Command TCS to Stop Guiding'(){}
                                                        activity 'Command Telescope Offset from PIT'(){}
                                                        activity 'Command Telescope Offset in ADApparent'(){}
                                                        activity 'Command Telescope Offset in Pixel'(){}
                                                        activity 'Offset Pupil Location with M3'(){}
                                                        activity 'Query M2 Position'(){}
                                                        activity 'Save M2CS Configuration'(){}
                                                        activity 'Send M2 PTT Cmd'(){}
                                                    }
                                                }
                                                package 'Internal'
                                                {
                                                    package 'Cmd_SH'
                                                    {
                                                        activity 'Get CCD Temperature'(){}
                                                        activity 'Select Filter SH'(){}
                                                        activity 'Select PupilMask SH'(){}
                                                        activity 'Take SH Exposure'(){}
                                                    }
                                                }
                                                package 'Operator'
                                                {
                                                    activity 'Ask OP to adjustGC'(){}
                                                    activity 'Ask OP to apply WH cmds'(){}
                                                    activity 'Ask OP to select a Star'(){}
                                                    activity 'Ask OP to Send M2  PTT'(){}
                                                    activity 'Ask OP to Send Segment PTT'(){}
                                                    activity 'Display Average Centroid Offsets'(){}
                                                    activity 'Display cmd and RMS'(){}
                                                    activity 'Display Results to APS Operator'(){}
                                                }
                                            }

                                            package 'PEAS Algorithms'
                                            {
                                                activity 'Calculate Average Centroid Offsets'(){}
                                                activity 'Calculate Average M2 PTT'(){}
                                                activity 'Calculate Average Segment PTT'(){}
                                                activity 'Calculate Broadband piston commands'(){}
                                                activity 'Calculate Centroid Offset'(){}
                                                activity 'Calculate Centroid Offsets'(){}
                                                activity 'Calculate Correlation Index'(){}
                                                activity 'Calculate M1 Minimize Sensor Readings'(){}
                                                activity 'Calculate M2 PTT'(){}
                                                activity 'Calculate Phasing Commands'(){}
                                                activity 'Calculate Pupil Registration and Image Offset'(){}
                                                activity 'Calculate RMS for M2 and Segment PTT cmds'(){}
                                                activity 'Calculate Segment Piston Tip Tilt'(){}
                                                activity 'Calculate Segment PTT'(){}
                                                activity 'Calculate Telescope Pointing Offset'(){}
                                                activity 'Calculate WH Commands'(){}
                                                activity 'Check Mirror Phasebility'(out isPhasable){
                                                    first start;
                                                    then action checkMirrorPhasebility;
                                                    then done;
                                                }
                                                activity 'Check PIT is tracking'(){}
                                                activity 'Correct PIT tracking'(){}
                                                activity 'Find and identify'(){}
                                                activity 'Load the existing reference beam map'(){}
                                                activity 'Notify to PEAS'(){}
                                                activity 'Publish Pixel Data'(){}
                                                activity 'Read from DataBase'(){}
                                                activity 'Save Status'(){}
                                                activity 'Save to DataBase'(){}
                                                activity 'Save to PEAS DataBase'(){}
                                                activity 'Set APT Integration Time'(){}
                                                activity 'Set APT ROI'(){}
                                                activity 'Start PIT Tracking'(){}
                                                activity 'Stop PIT Tracking'(){}
                                                activity 'Throw Telescope Alignment Exception'(){}
                                                activity 'Update APT Camera Parameters'(){}
                                                activity 'Wait for Acquisition or Guding'(){}
                                            }

                                            package 'Signals'{
                                                package 'APS External'{
                                                    package 'PEAS-CommonService'{
                                                        value type 'Get installed_Segment_Ack';
                                                        value type 'Get installed_Segment_Query';
                                                    }
                                                }
                                                package 'APS Internal'{
                                                    package 'Control'{
                                                        value type 'Post-Segment Exchange Alignment';
                                                    }
                                                }
                                            }

                                            block 'APS Mission Conceptual' specializes 'APS Mission'{
                                                part 'APS Operational Blackbox' : 'APS Conceptual';
                                                value 'maxPhasingTime' : s = 300.0;
                                            }

                                            block 'APS Conceptual' specializes 'APS Operational Blackbox Specification JPL'{
                                                private import 'Components'::*;

                                                part apt : 'Acquisition Pointing and Tracking Assembly';
                                                part isrc: 'Internal Source';
                                                part sh : 'SH camera';
                                                part ppt: 'PEAS PIT Tracking';
                                                part km : 'K-mirror';
                                                part aptl: 'APT Loop';
                                                part peas : 'Procedure Executive and Analysis Software';
                                                part sp : 'Shear plate';
                                                part pit : 'Pupil and Image Tracking Assembly' ;
                                                part bss: 'BeamSplitterStage';
                                                part stim: 'Stimulus';

                                                connect aptl::APTL2APTAOut to apt::APTA2APTLInt;
                                                connect aptl::APTOut to GC2ESWOut;
                                                connect isrc::IS2PEASOut to peas::PEAS2InsourceIn;
                                                connect ppt::PIT2PEASOut to peas::PEAS2PITTrackIn;
                                                connect ppt::PIT2TCSIn to PEAS2TCSIn;
                                                connect ppt::PITT2PITAOut to pit::PITA2PITTIn;
                                                connect sp::SP2PEASIn to ppt::PIT2SPOut;
                                                connect sp::SP2PEASOut to ppt::PIT2SPIn;
                                                connect apt::APTA2APTLOut to aptl::APTL2APTAIn;
                                                connect GC2ESWIn to aptl::APTIn;
                                                connect GCDataOut to aptl::APTDataOut;
                                                connect km::KM2PEASIn to ppt::PIT2KMirrorOut;
                                                connect km::KM2PEASOut to ppt::PIT2KMirrorIn;
                                                connect km::KM2PEASOut to peas.PEAS2KMIn;
                                                connect peas::PEAS2APTLoopIn to aptl::APTOut;
                                                connect peas::PEAS2APTLoopOut to aptl::APTIn;
                                                connect peas::PEAS2APTOut to apt::PEAS2APTIn;
                                                connect peas::peas2bssIn to bss::bss2peasOut;
                                                connect peas::peas2bssOut to bss::bss2peasIn;
                                                connect peas::PEAS2CSIn to PEAS2CSIn;
                                                connect peas::PEAS2CSOut to PEAS2CSOut;
                                                connect peas::PEAS2ESWOut to PEAS2ESWIn;
                                                connect peas::PEAS2InsourceOut to isrc::IS2PEASIn;
                                                connect peas::PEAS2KMOut to km::KM2PEASIn;
                                                connect peas::PEAS2M1CSOut to PEAS2M1CSOut;
                                                connect peas::PEAS2PITDataIn to ppt::PITDataOut;
                                                connect peas::PEAS2PITOut to pit::PEAS2PITIn;
                                                connect peas::PEAS2PITTrackOut to ppt::PIT2PEASIn;
                                                connect peas::PEAS2SHOut to sh::CC_SH2PEASIn;
                                                connect peas::PEAS2SPIn to sp::SP2PEASOut;
                                                connect peas::PEAS2SPOut to sp::SP2PEASIn;
                                                connect peas::peas2StimulusIn to stim::stimulus2PeasOut;
                                                connect peas::peas2StimulusOut to stim::stimulus2PeasIn;
                                                connect peas::PEAS2TCSOut to PEAS2TCSOut;
                                                connect PEAS2ESWOut to peas::PEAS2ESWIn;
                                                connect PEAS2M1CSIn to peas::PEAS2M1CSIn;
                                                connect PEAS2TCSIn to peas::PEAS2TCSIn;
                                                connect PEAS2TCSOut to ppt::PIT2TCSOut;
                                                connect pit::PEAS2PITOut to peas::PEAS2PITIn;
                                                connect pit::PITA2PITTOut to ppt::PITT2PITAIn;
                                                connect sh::CC_SH2PEASOut to peas::PEAS2SHIn;
                                            }
                                        }

                                        package 'Realization Design'
                                        {
                                             block 'APS Realization' specializes 'Black Box Specification'::'Structure'::'APS Operational Blackbox Specification JPL'{
                                                 part 'summit Installation' : 'Summit Installation';
                                                 part 'dome Installation' : 'Dome Installation';
                                             }
                                             block 'Dome Installation';
                                             block 'Summit Installation';
                                         }
                                    }

                                    package 'Domain'
                                    {
                                        package 'External to Mission'
                                        {
                                            block 'External Constraints';
                                            block 'External Environment';
                                            block 'Maintenance Team';
                                        }
                                        block 'APS Operational Domain to-be'{
                                            part 'aPS Mission' : 'Mission'::'APS Mission';
                                            part 'maintenance Team' : 'External to Mission'::'Maintenance Team';
                                            ref 'external Environmet' : 'External to Mission'::'External Environment';
                                            ref 'external Constraints' : 'External to Mission'::'External Constraints';
                                        }
                                    }

                                    package 'Mission'
                                    {
                                        private import 'APS'::'Black Box Specification'::'Structure'::*;
                                        private import 'Project Systems Engineering'::'01 Components'::'Operational'::'TMT Observatory System'::'Conceptual Design'::*;

                                        package 'Stakeholders'
                                        {
                                            block 'APS User'{
                                                port user2APS;
                                            }
                                        }

                                        block 'APS Mission'{
                                            private import 'Stakeholders'::*;

                                            part cs : 'Common Services';
                                            part usr : 'APS User';
                                            part esw : 'Executive Software';
                                            part tcs : 'Telescope Control System';
                                            part m1cs : 'M1 Control System';
                                            value 'maxPhasingTime' : s = 300;
                                            part 'aPS Operational Blackbox JPL' : 'APS Operational Blackbox Specification JPL';

                                            //Connectors:
                                            // would need to redefine the ports for now (not what we want in the end though)
                                            connect 'aPS Operational Blackbox JPL'::GC2ESWIn to esw::ESW2GCOut;
                                            connect 'aPS Operational Blackbox JPL'::GC2ESWOut to esw::ESW2GCIn;
                                            connect 'aPS Operational Blackbox JPL'::GCDataOut to esw::GCDataIn;
                                            connect 'aPS Operational Blackbox JPL'::GCDataOut to tcs::guideCamDataIn;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2CSIn to cs::CS2PEASOut;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2CSOut to cs::CS2PEASIn;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2ESWIn to esw::ESW2PEASOut;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2ESWOut to esw::ESW2PEASIn;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2M1CSIn to m1cs::m1cs2PEASOut;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2M1CSOut to m1cs::m1cs2PEASIn;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2TCSIn to tcs::TCS2PEASOut;
                                            connect 'aPS Operational Blackbox JPL'::PEAS2TCSOut to tcs::TCS2PEASIn;
                                            connect esw::ESW2TCSOut to tcs::TCS2PEASIn;
                                            connect tcs::TCS2PEASOut to esw::ESW2TCSIn;
                                            connect 'aPS Operational Blackbox JPL'::APS2UserIn to usr::user2APS;

                                        }
                                    }

                                }
                            }

                            package '02 Roles'{}
                            package '03 Processes'{}
                            package '08 ViewPoints'{}
                            package '09 Views'{}
                            package '10 Analysis'{}
                            block 'Systems Engineering';

                        }
                    }
                    package 'Engineering Sensors'{}
                    package 'M1 Control System'{}
                    package 'Mount Control System'{}
                    package 'Power, Lighting, and Grounding'{}
                    package 'Telescope Control System'{}
                    package 'Telescope Safety System'{}
                    package 'Test Instrument Control'{}
                }

                package 'Optics'{

                }

                package 'Telescope Structure'{}
            }
        }
    }
}_____no_output_____// %publish 'TMT'_____no_output_____
</code>