addObserver
Description
adds an observer named observer
= addObserver(ScenarioSim
,'ObserverName
',sysObj
)ObserverName
, represented by System object™
sysObj
, to the scenario simulation ScenarioSim
.
Examples
Add Observer to Read Simulation Pace and List of Actors
Create ScenarioSim
, a
Simulink.ScenarioSimulation
object.
rrApp = roadrunner('C:\Project\TestRoute') openScenario(rrApp,'TrajectoryCutIn'); ScenarioSim = createSimulation(rrApp);
Create the class mySysObserver
, which inherits from
matlab.System
base class. 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 represented by mySysObserver
is added as an observer
named ReadPaceandActors
to the simulation
ScenarioSim
.
observer = addObserver(ScenarioSim,'ReadPaceandActors', mysysObserver)
Input Arguments
ScenarioSim
— RoadRunner Scenario simulation
Simulink.ScenarioSimulation
object
RoadRunner Scenario simulation, specified as a Simulink.ScenarioSimulation
object.
Example: observer =
addObserver(ScenarioSim,'RedCarObserver',Obj)
ObserverName
— Name of observation actor
string | character vector
Name of observation actor, specified as a string or character vector.
Example: 'RedCarObserver'
sysObj
— Observer
System object
Observer to add to the simulation, specified as a MATLAB®
System object. You must inherit the code implementation of System object
sysObj
from the matlab.System
base class.
Output Arguments
observer
— Flag to indicate result of addition of observer
1
| 0
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 Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)