-
-
Notifications
You must be signed in to change notification settings - Fork 40
Watching a simulation variable
After a bdsim model has been created you may want to monitor some additional signals and have them appear in the simulation results. In bdsim we want to watch the signal, or put the signal into the watch list.
Watched signals appear in the simulation results structure as a column of .y, and the name of the signal is the corresponding element of the list .ynames which is a list of the repr() generated output port names.
Note
Early versions of bdsim put the watch variables in different fields, eg. .y0, .y1, .y2 etc. This is difficult to index programmatically, so the this notation is now deprecated.
There are a few different ways we watch a signal.
We simply set the watch parameter to sim.run(). No modification to the model is required. For the program eg1.py
# define the blocks
demand = bd.STEP(T=1, name="demand")
sum = bd.SUM("+-")
gain = bd.GAIN(10)
plant = bd.LTI_SISO(0.5, [2, 1], name="myplant")
scope = bd.SCOPE(styles=["k", "r--"], loc="lower right")
# connect the blocks
bd.connect(demand, sum[0], scope[1])
bd.connect(plant, sum[1])
bd.connect(sum, gain)
bd.connect(gain, plant)
bd.connect(plant, scope[0])
bd.compile() # check the diagram
out = sim.run(bd, watch=[gain, plant[0], "myplant[0]") # <==== watch list setThe watch argument is a list of one or more signals whose value during simulation will be recorded. Each element can be:
- a
Blockreference, interpreted as output port 0. eg.gainin the example above - a
Plugreference (block with port index) eg.plan[0]in the example above - a string of the form
"blockname[i]"— output port i of the named block. eg."myplant[0]"in the example above. This is particularly useful for watching a signal that is embedded deep in some nestedSUBSYSTEMblock for which you do not have an object reference. Signals in these nested blocks all have unique names which can be seen in any report about the system.
Warning
We can only watch block outputs, not block inputs.
Adding the watch option to any graphics block will cause its inputs to be watched. The time series data will appear in the simulation results, not just on screen in a scope.
scope = bd.SCOPE(styles=["k", "r--"], loc="lower right", watch=True)Any signal that is input to WATCH block is added to the watch list. The block itself does nothing during simulation.
Copyright (c) Peter Corke 2020-
- Home
- API reference (Sphinx)
- Block catalog
- Control Systems Magazine article
- Adding blocks to your model
- Block path
- Connecting blocks
- Compiling
- Running
- Watching a simulation variable
- Simulation results
- Runtime options
- Environment variables
- Discrete-time blocks
- Subsystems
- Figures
- Notebook animation
- Animation and movies
- PID control
- Coding patterns
- Block methods and attributes
- Time stepping: integration, animation & events
- Blocks, wires and plugs
- Graphics blocks
- Evaluation
- Runtimes and simulator state
- Creating a new block
- Related packages
Under development on feat/realtime branch, planned for release before end of 2026.