Main Content

removeObserver

Remove observer from scenario simulation

Since R2022a

    Description

    example

    removeObserver(ScenarioSim,ObserverName) removes the observer named ObserverName from the ScenarioSimulation object ScenarioSim.

    Examples

    collapse all

    1. Create ScenarioSim, a ScenarioSimulation object.

      rrApp = roadrunner('C:\RoadRunnerProject');
      openScenario(rrApp,'TrajectoryCutIn');
      ScenarioSim = createSimulation(rrApp);
      
    2. Create the class mySysObserver, which inherits from matlab.System base class. The mySysObserver class represents an observer.

      classdef mysysObserver < matlab.System
      
      properties(Access=private)
      % …
      end
      methods
      % constructor for the System object
      function obj = mysysObserver()
      end
      end
      
      
      methods(Access = protected)
      
      %reset the values
      function resetImpl(obj)
      obj.mScenarioSimObj = Simulink.ScenarioSimulation.find('ScenarioSimulation', ...
        'SystemObject', obj);
      obj.mScenarioSimActorList = [];
      obj.mIsPacingTurnedOff = false;
      end
      
      
      
      % get the required parameter values
      function stepImpl(obj)
      mSimulationPace = obj.mScenarioSimObj.get('SimulationPace');
      mScenarioSimActorList = obj.mScenarioSimObj.get('ActorSimulation');
      end
      end
      end
    3. Add the observer to the scenario.

      obsStatus = addObserver(ScenarioSim,'ReadPaceandActors',mysysObserver);
      
    4. Remove the observer from the scenario.

      removeObserver(ScenarioSim,'ReadPaceandActors');

    Input Arguments

    collapse all

    RoadRunner Scenario simulation, specified as a ScenarioSimulation object.

    Example: removeObserver(ScenarioSim, 'ObservingRedTruck')

    Name of observer to remove, specified as a string or character vector.

    Example: 'ObservingRedTruck'

    Version History

    Introduced in R2022a