Main Content

simulink.schedule.OrderedSchedule 클래스

네임스페이스: simulink.schedule

모델 분할부의 우선 순위를 포함하는 OrderedSchedule 객체 생성

R2020a 이후

설명

simulink.schedule.OrderedSchedule 객체는 지정된 모델의 분할부의 실행 순서에 대한 표현입니다. 이 객체에는 get_param을 사용하여 모델 파라미터로 액세스하십시오. OrderedSchedule 객체를 사용하여 명령줄을 통해 모델의 분할부의 스케줄을 수정할 수 있습니다.

set_param을 사용하여 모델에 스케줄을 적용할 수 있습니다.

생성

get_param(mdl,'Schedule')은 지정된 모델 mdl에 대해 OrderedSchedule 객체를 만듭니다.

속성

모두 확장

분할부의 우선 순위로, 테이블로 지정됩니다. 여기서,

  • 행 이름은 분할의 이름입니다.

  • 첫 번째 열은 분할의 인덱스입니다. 분할의 순서를 변경하려면 인덱스를 수정하십시오.

  • 두 번째 열은 분할의 유형을 보여줍니다.

  • 세 번째 열은 분할의 트리거를 보여줍니다. 이 열은 분할의 샘플 시간 또는 분할이 실행되는 적중 시간을 나열합니다.

RateSections는 순서 테이블에서 싱글레이트를 갖는 부분을 포함하는 객체로 구성된 배열입니다. RateSections를 사용하여 유효한 그룹 내에서 분할부의 실행 순서를 쉽게 수정할 수 있습니다.

개별 schedule 객체의 용도로, string형으로 지정됩니다.

비주기적 분할에 대한 트리거가 될 수 있는 스케줄 편집기 이벤트. 스케줄 편집기 이벤트는 Stateflow® 차트와 Simulink® 입력 이벤트에서 전송하며, simulink.schedule.Event 객체로 구성된 배열로 지정됩니다.

예제

모두 축소

이 예제에서는 스케줄 편집기 API를 사용하여 스케줄에 대한 작업을 수행합니다. 그런 다음, 함수를 사용하여 무작위 스케줄을 생성하고 시뮬레이션 데이터 인스펙터에서 분석합니다.

모델 열기 및 Schedule 객체 가져오기

Throttle Position Control 시스템의 모델을 열고 get_param을 사용하여 simulink.schedule.OrderedSchedule 객체를 가져옵니다. 이 객체에는 현재 스케줄이 포함되어 있습니다.

model = 'ScheduleEditorAPIWithSubsystemPartitions';
open_system(model);
schedule = get_param(model, 'Schedule')
schedule = 

  OrderedSchedule with properties:

           Order: [9x3 table]
    RateSections: [3x1 simulink.schedule.RateSection]
          Events: [0x1 simulink.schedule.Event]
     Description: ''

Schedule 객체 검토하기

schedule 객체에는 모델 내 분할의 실행 순서가 포함된 Order 속성이 있습니다. Order 속성은 분할 이름, 인덱스, 유형 및 트리거가 포함된 테이블을 표시합니다.

schedule.Order
ans =

  9x3 table

                          Index      Type      Trigger
                          _____    ________    _______

    Cont                    1      Periodic    "0"    
    TPSSecondaryRun5ms      2      Periodic    "0.005"
    MonitorRun5ms           3      Periodic    "0.005"
    ControllerRun5ms        4      Periodic    "0.005"
    ActuatorRun5ms          5      Periodic    "0.005"
    D2                      6      Periodic    "0.005"
    D3                      7      Periodic    "0.01" 
    APPSnsrRun              8      Periodic    "0.01" 
    TPSPrimaryRun10ms       9      Periodic    "0.01" 

Order 테이블의 인덱스 변수를 사용하여 모델의 실행 순서를 변경합니다.

schedule.Order.Index('ActuatorRun5ms') = 2;
schedule.Order
ans =

  9x3 table

                          Index      Type      Trigger
                          _____    ________    _______

    Cont                    1      Periodic    "0"    
    ActuatorRun5ms          2      Periodic    "0.005"
    TPSSecondaryRun5ms      3      Periodic    "0.005"
    MonitorRun5ms           4      Periodic    "0.005"
    ControllerRun5ms        5      Periodic    "0.005"
    D2                      6      Periodic    "0.005"
    D3                      7      Periodic    "0.01" 
    APPSnsrRun              8      Periodic    "0.01" 
    TPSPrimaryRun10ms       9      Periodic    "0.01" 

스케줄을 수정하기 위해 Order 속성 내에서 순서를 이동한 경우 그 결과로 생성되는 스케줄이 유효해야 합니다. 보다 쉽게 스케줄을 수정하고 유효한 순서로 이동시킬 수 있도록 각 분할은 RateSections 속성에서 동일한 레이트를 갖는 분할들로 그룹화됩니다. RateSection 속성의 각 요소에는 동일한 레이트의 분할이 들어있는 순서 테이블이 포함되어 있습니다.

schedule.RateSections(2)
schedule.RateSections(2).Order
ans = 

  RateSection with properties:

     Rate: "0.005"
    Order: [5x3 table]


ans =

  5x3 table

                          Index      Type      Trigger
                          _____    ________    _______

    ActuatorRun5ms          2      Periodic    "0.005"
    TPSSecondaryRun5ms      3      Periodic    "0.005"
    MonitorRun5ms           4      Periodic    "0.005"
    ControllerRun5ms        5      Periodic    "0.005"
    D2                      6      Periodic    "0.005"

인덱스 변수를 사용하여 RateSections 내에서 분할을 이동합니다.

schedule.RateSections(2).Order.Index('ActuatorRun5ms') = 5;
schedule.Order
ans =

  9x3 table

                          Index      Type      Trigger
                          _____    ________    _______

    Cont                    1      Periodic    "0"    
    TPSSecondaryRun5ms      2      Periodic    "0.005"
    MonitorRun5ms           3      Periodic    "0.005"
    ControllerRun5ms        4      Periodic    "0.005"
    ActuatorRun5ms          5      Periodic    "0.005"
    D2                      6      Periodic    "0.005"
    D3                      7      Periodic    "0.01" 
    APPSnsrRun              8      Periodic    "0.01" 
    TPSPrimaryRun10ms       9      Periodic    "0.01" 

무작위 스케줄을 생성하는 함수 만들기

이 섹션에서는 3개의 함수 randomSchedule, generateSimulationInputs, simulateRandomSchedules를 만듭니다.

randomSchedule 함수는 임의 치환을 사용하여 schedule 객체의 인덱스를 수정하여 무작위 스케줄을 만듭니다. schedule 객체의 Order 속성과 RateSections 속성을 사용하여 스케줄 내 분할을 서로 다르게 무작위로 조합된 순서로 이동시킵니다. 이렇게 무작위로 생성된 스케줄을 사용하여 모델을 시뮬레이션하고 비교하여 서로 다른 스케줄이 시뮬레이션에 미치는 효과를 연구합니다. 함수 randomSchedule에서 입력값은 모델 이름입니다. 그런 다음, get_param을 사용하여 모델의 simulink.schedule.OrderedSchedule 객체를 가져옵니다. schedule 객체와 그 속성을 사용하여 스케줄을 수정하고 무작위로 생성된 스케줄을 만듭니다. 모델의 첫 번째 레이트 섹션에 대해 변수 firstExecutionOrder를 만듭니다. rateSections(1).ExecutionOrder = [firstExecutionOrder(1,:); reSchedule(firstExecutionOrder(2:end,:))] 코드 라인은 인덱스의 임의 치환을 만드는 함수 reSchedule을 호출합니다.

type randomSchedule
function schedule = randomSchedule(model)
    % schedule = randomSchedule(model) Produces a
    % simulink.schedule.OrderedSchedule that has a randomized permutation
    % of the model's original execution order schedule
    
    arguments
        model char = bdroot
    end
    
    schedule = get_param(model, 'Schedule');
    
    rateSections = schedule.RateSections;
    firstOrder = rateSections(1).Order;
    
    % This assumes that the slowest discrete rate is at index 1. This may
    % not be the case for all models (ex. JMAAB-B).
    rateSections(1).Order = [firstOrder(1,:); reSchedule(firstOrder(2:end,:))];    
    
    for i=2:length(rateSections)
        rateSections(i).Order = reSchedule(rateSections(i).Order);
    end
    
    schedule.RateSections = rateSections;
end

function out = reSchedule(in)
    numPartitions = height(in);
    in.Index = in.Index(randperm(numPartitions));
    out = in;
end

서로 다른 스케줄이 모델에 미치는 효과를 분석하기 위해 여러 다른 스케줄로 모델을 시뮬레이션합니다. 이 함수에서 Simulink.SimulationInput 객체로 구성된 배열을 만듭니다. Simulink.SimulationInput 객체로 구성된 이 배열을 통해 Simulink.SimulationInput 객체의 setModelParameters 메서드를 사용하여 모델에 스케줄을 적용할 수 있습니다.

type generateSimulationInputs
function in = generateSimulationInputs(model, numSimulations)
    % in = generateSimulationInputs(model, numSimulations) Generates
    % numSimulations Simulink.SimulationInput objects each containing a
    % different, randomized execution order schedule
    arguments
        model char = bdroot
        numSimulations double = 10
    end
    
    in(numSimulations) = Simulink.SimulationInput();
    in = in.setModelName(model);
    for idx = 1:numSimulations
        in(idx) = in(idx).setModelParameter('Schedule', randomSchedule(model));
    end
end

마지막 함수에서 Simulink.SimulationInput 객체로 구성된 배열을 사용하여 여러 시뮬레이션을 실행합니다. 시뮬레이션이 완료되면 시뮬레이션 데이터 인스펙터에서 모든 시뮬레이션의 출력을 플로팅할 수 있습니다.

type simulateRandomSchedules
function out = simulateRandomSchedules(model, numSimulations)
    % out = simulateRandomSchedules(model, numSimulations) Simulates a 
    % model numSimulations number of times.  Each simulation has a
    % randomized execution order schedule.
    arguments
        model char = bdroot
        numSimulations double = 10
    end
        
    in = generateSimulationInputs(model, numSimulations);
    out = sim(in);
    plot(out);
end

함수 실행하기

이제 ScheduleEditorAPIWithSubsystemPartitions 모델에 대해 위 함수를 실행합니다. 먼저 randomSchedule 함수를 사용하여 무작위로 생성된 스케줄을 만들고 generateSimulationInputs 함수를 사용하여 Simulink.SimulationInput 객체로 구성된 배열을 생성한 다음, simulateRandomSchedule 함수를 사용하여 여러 스케줄로 모델을 시뮬레이션하고 비교를 위해 결과를 플로팅합니다. 무작위로 생성된 15개의 스케줄을 사용하여 시뮬레이션을 실행해 보겠습니다.

simulateRandomSchedules(model,15)
[25-Jan-2024 18:30:38] Running simulations...
[25-Jan-2024 18:30:55] Completed 1 of 15 simulation runs
[25-Jan-2024 18:30:58] Completed 2 of 15 simulation runs
[25-Jan-2024 18:31:00] Completed 3 of 15 simulation runs
[25-Jan-2024 18:31:03] Completed 4 of 15 simulation runs
[25-Jan-2024 18:31:05] Completed 5 of 15 simulation runs
[25-Jan-2024 18:31:07] Completed 6 of 15 simulation runs
[25-Jan-2024 18:31:09] Completed 7 of 15 simulation runs
[25-Jan-2024 18:31:10] Completed 8 of 15 simulation runs
[25-Jan-2024 18:31:12] Completed 9 of 15 simulation runs
[25-Jan-2024 18:31:14] Completed 10 of 15 simulation runs
[25-Jan-2024 18:31:16] Completed 11 of 15 simulation runs
[25-Jan-2024 18:31:18] Completed 12 of 15 simulation runs
[25-Jan-2024 18:31:20] Completed 13 of 15 simulation runs
[25-Jan-2024 18:31:22] Completed 14 of 15 simulation runs
[25-Jan-2024 18:31:24] Completed 15 of 15 simulation runs

ans = 

1x15 Simulink.SimulationOutput array


버전 내역

R2020a에 개발됨