| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #!/usr/bin/python3
- # This file was automatically generated from drawio2cbd with the command:
- # /home/red/git/DrawioConvert/__main__.py SinGen.xml -fav -F CBD -e SinGen -E delta=0.1
- from CBD.lib.interface.plottinghandler import PlotHandler, PlotManager, LinePlot
- from CBD.simulator import Simulator
- from SinGen import *
- import matplotlib.pyplot as plt
- DELTA_T = 0.1
- fig = plt.figure(figsize=(15, 5), dpi=100)
- ax = fig.add_subplot(111)
- ax.set_ylim((-1, 1))
- # ax = None
- cbd = SinGen("SinGen")
- manager = PlotManager()
- manager.register("sin", cbd.findBlock("plot")[0], (fig, ax), LinePlot())
- manager.connect('sin', 'update_event', lambda d, axis=ax: axis.set_xlim(PlotHandler.follow(d[0], 10.0, 0.0)))
- plt.show(block=False)
- # plotter = cbd.getBlockByName("plot")
- def term(*_):
- plt.draw()
- plt.pause(0.01)
- return not manager.is_opened()
- # Run the Simulation
- time = 10.0
- sim = Simulator(cbd)
- sim.setRealTime(True)
- sim.setDeltaT(DELTA_T)
- sim.setTerminationCondition(term)
- # plotter.set_animation(fig)
- # plotter.start_animation(fig)
- sim.run(time)
- # plotter.end_animation()
- log = sim.getDurationLog()
- fig2 = plt.figure()
- ax2 = fig2.subplots()
- ax2.set_title("Block Computation [Plotting Manager] (T = {:.2f}, dt = {:.2f})".format(time, DELTA_T))
- ax2.set_xlabel("Iterations")
- ax2.set_ylabel("Time")
- ax2.plot([-1, len(log)], [DELTA_T, DELTA_T], c='red')
- ax2.plot([-1, len(log)], [0.01, 0.01], c='green')
- ax2.bar(range(len(log)), log)
- plt.show()
|