addObserver
Description
adds an observer named observer
= addObserver(ScenarioSim
,ObserverName
,sysObjFileName
)ObserverName
implemented by the System object™ contained in file sysObjFileName
, to the scenario
simulation ScenarioSim
.
Examples
Add Observer to Read Simulation Pace and List of Actors
Create ScenarioSim
, a ScenarioSimulation
object.
rrApp = roadrunner('C:\Project\TestRoute') openScenario(rrApp,'TrajectoryCutIn'); ScenarioSim = createSimulation(rrApp);
Create the class mySysObserver
, which inherits from
matlab.System
base class. The script file containing
mySysObserver
must also share the same name. In the
stepImpl
method, get the list of actors, and the simulation pace of
an existing simulation. Use the resetImpl
method to reset values of
the required variables.
classdef mySysObserver < matlab.System properties(Access=private) mScenarioSimObj; mScenarioSimActorList; mSimulationPace; mIsPacingTurnedOff; 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 % Release the object and its resources function releaseImpl(~) end end end
The System object in file mySysObserver
is added as an observer named
ReadPaceandActors
to the simulation
ScenarioSim
.
observer = addObserver(ScenarioSim,'ReadPaceandActors', 'mysysObserver')
Input Arguments
ScenarioSim
— RoadRunner Scenario simulation
ScenarioSimulation
object
RoadRunner Scenario simulation, specified as a ScenarioSimulation
object.
Example: observer =
addObserver(ScenarioSim,'RedCarObserver',Obj)
ObserverName
— Name of observer
string | character vector
Name of observer, specified as a string or character vector. You must choose a unique name with which to identify the observer.
Example: 'RedCarObserver'
sysObjFileName
— System object file name
string | character vector
Name of file containing the observer System object to add to a simulation, specified as a string or character vector. You
must inherit the code implementation of the observer System object from the matlab.System
base class.
Output Arguments
observer
— Flag to indicate result of addition of observer
0
| 1
Flag to indicate result of addition of observer, returned as 0 or 1. If the observer is not added successfully, the value returned is 0.
Version History
Introduced in R2022a
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)