def test_visualizer_call(self): """ test interface for visualizer """ # register a visualizer for testing register_visualizer(BallBeamVisualizer) self.assertEqual([(BallBeamVisualizer, "BallBeamVisualizer")], get_registered_visualizers())
def test_visualizer(self): self.assertRaises(TypeError, register_visualizer, EvalA1) register_visualizer(BallInTubeVisualizer) self.assertIn((BallInTubeVisualizer, "BallInTubeVisualizer"), get_registered_visualizers())
# -*- coding: utf-8 -*- import pymoskito as pm # import custom modules import model import controller import visualizer_mpl # import visualizer_vtk if __name__ == '__main__': # register model pm.register_simulation_module(pm.Model, model.PendulumModel) # register controller pm.register_simulation_module(pm.Controller, controller.BasicController) # register visualizer pm.register_visualizer(visualizer_mpl.MplPendulumVisualizer) # pm.register_visualizer(visualizer_vtk.VtkPendulumVisualizer) # start the program pm.run()
from visualization import TwoPendulumVisualizer from processing import TwoPendulum if __name__ == "__main__": # register own modules register_simulation_module(Model, TwoPendulumModel) register_simulation_module(Model, TwoPendulumRigidBodyModel) register_simulation_module(Model, TwoPendulumModelParLin) register_simulation_module(Controller, LinearStateFeedback) register_simulation_module(Controller, LinearStateFeedbackParLin) register_simulation_module(Controller, LjapunovController) register_simulation_module(Controller, SwingUpController) register_visualizer(TwoPendulumVisualizer) register_processing_module(PostProcessingModule, TwoPendulum) # create an Application instance (needed) app = QApplication([]) if 1: # create Simulator sim = Simulator() # load default config sim.load_regimes_from_file("default.sreg") # apply a regime sim.apply_regime_by_name("test")
for i in range(3): for n in range(3): poke.SetElement(i, n, t[i, n]) poke.SetElement(i, 3, r[i]) actor.PokeMatrix(poke) def update_scene(self, x): """ update the body states """ r_ball, t_ball = self.calc_positions(x) self.set_body_state(self.ballActor, r_ball, t_ball) pm.register_visualizer(BallInTubeVisualizer) except ImportError as e: vtk = None print("BallTube Visualizer:") print(e) print("VTK Visualization not available.") class MplBallInTubeVisualizer(pm.MplVisualizer): def __init__(self, q_widget, q_layout): pm.MplVisualizer.__init__(self, q_widget, q_layout) self.axes.set_xlim(-0.3, 0.3) self.axes.set_ylim(-0.05, 1.55) self.axes.set_aspect("equal")
y1T2_2 = x2_trailer1 + ct2 * car_wheelius + st2 * wheel # rod 2 x1_joint2 = x1_trailer1 - d2 * ct2 x2_joint2 = x2_trailer1 - d2 * st2 # trailer 2 x1_trailer2 = x1_joint2 - l3 * ct3 x2_trailer2 = x2_joint2 - l3 * st3 # trailer 2 wheel 1 x2T1_1 = x1_trailer2 + st3 * car_wheelius - ct3 * wheel y2T1_1 = x2_trailer2 - ct3 * car_wheelius - st3 * wheel x2T1_2 = x1_trailer2 + st3 * car_wheelius + ct3 * wheel y2T1_2 = x2_trailer2 - ct3 * car_wheelius + st3 * wheel # trailer wheel 2 x2T2_1 = x1_trailer2 - st3 * car_wheelius - ct3 * wheel y2T2_1 = x2_trailer2 + ct3 * car_wheelius - st3 * wheel x2T2_2 = x1_trailer2 - st3 * car_wheelius + ct3 * wheel y2T2_2 = x2_trailer2 + ct3 * car_wheelius + st3 * wheel return (xR1_1, yR1_1, xR1_2, yR1_2, xR2_1, yR2_1, xR2_2, yR2_2, x1_joint1, x2_joint1, x1_trailer1, x2_trailer1, x1T1_1, y1T1_1, x1T1_2, y1T1_2, x1T2_1, y1T2_1, x1T2_2, y1T2_2, x1_joint2, x2_joint2, x1_trailer2, x2_trailer2, x2T1_1, y2T1_1, x2T1_2, y2T1_2, x2T2_1, y2T2_1, x2T2_2, y2T2_2) pm.register_visualizer(CarVisualizer)
for i in range(3): for n in range(3): poke.SetElement(i, n, t[i, n]) poke.SetElement(i, 3, r[i]) actor.PokeMatrix(poke) def update_scene(self, x): """ update the body states """ r_beam, t_beam, r_ball, t_ball = self.calc_positions(x) self.set_body_state(self.beamActor, r_beam, t_beam) self.set_body_state(self.ballActor, r_ball, t_ball) pm.register_visualizer(BallBeamVisualizer) except ImportError as e: vtk = None print("BallBeam Visualizer:") print(e) print("VTK Visualization not available.") class MplBallBeamVisualizer(pm.MplVisualizer): def __init__(self, q_widget, q_layout): pm.MplVisualizer.__init__(self, q_widget, q_layout) self.axes.set_xlim(st.x_min_plot, st.x_max_plot) self.axes.set_ylim(st.y_min_plot, st.y_max_plot) self.axes.set_aspect("equal")
# rod 2 x1_joint2 = x1_trailer1 - d2 * ct2 x2_joint2 = x2_trailer1 - d2 * st2 # trailer 2 x1_trailer2 = x1_joint2 - l3 * ct3 x2_trailer2 = x2_joint2 - l3 * st3 # trailer 2 wheel 1 x2T1_1 = x1_trailer2 + st3 * car_wheelius - ct3 * wheel y2T1_1 = x2_trailer2 - ct3 * car_wheelius - st3 * wheel x2T1_2 = x1_trailer2 + st3 * car_wheelius + ct3 * wheel y2T1_2 = x2_trailer2 - ct3 * car_wheelius + st3 * wheel # trailer wheel 2 x2T2_1 = x1_trailer2 - st3 * car_wheelius - ct3 * wheel y2T2_1 = x2_trailer2 + ct3 * car_wheelius - st3 * wheel x2T2_2 = x1_trailer2 - st3 * car_wheelius + ct3 * wheel y2T2_2 = x2_trailer2 + ct3 * car_wheelius + st3 * wheel return (xR1_1, yR1_1, xR1_2, yR1_2, xR2_1, yR2_1, xR2_2, yR2_2, x1_joint1, x2_joint1, x1_trailer1, x2_trailer1, x1T1_1, y1T1_1, x1T1_2, y1T1_2, x1T2_1, y1T2_1, x1T2_2, y1T2_2, x1_joint2, x2_joint2, x1_trailer2, x2_trailer2, x2T1_1, y2T1_1, x2T1_2, y2T1_2, x2T2_1, y2T2_1, x2T2_2, y2T2_2) pm.register_visualizer(CarVisualizer)
from control import LinearStateFeedback, LinearStateFeedbackParLin, LjapunovController, SwingUpController from visualization import TwoPendulumVisualizer from processing import TwoPendulum if __name__ == '__main__': # register own modules register_simulation_module(Model, TwoPendulumModel) register_simulation_module(Model, TwoPendulumRigidBodyModel) register_simulation_module(Model, TwoPendulumModelParLin) register_simulation_module(Controller, LinearStateFeedback) register_simulation_module(Controller, LinearStateFeedbackParLin) register_simulation_module(Controller, LjapunovController) register_simulation_module(Controller, SwingUpController) register_visualizer(TwoPendulumVisualizer) register_processing_module(PostProcessingModule, TwoPendulum) # create an Application instance (needed) app = QApplication([]) if 1: # create Simulator sim = Simulator() # load default config sim.load_regimes_from_file("default.sreg") # apply a regime sim.apply_regime_by_name("test")
PostProcessingModule, \ Model, Controller from model import BallBeamModel from control import FController from visualization import BallBeamVisualizer from postprocessing import EvalA1 __author__ = 'stefan' if __name__ == '__main__': # register own modules register_simulation_module(Model, BallBeamModel) register_simulation_module(Controller, FController) register_processing_module(PostProcessingModule, EvalA1) register_visualizer(BallBeamVisualizer) # create an Application instance (needed) app = QtGui.QApplication([]) if 0: # create simulator sim = Simulator() # load default config sim.load_regimes_from_file("default.sreg") sim.apply_regime_by_name("test-nonlinear") sim.start_simulation() sim.show() QtGui.QApplication.instance().exec_()
t = x[1] r = x[2] for i in range(3): for n in range(3): poke.SetElement(i, n, r[i, n]) poke.SetElement(i, 3, t[i]) actor.PokeMatrix(poke) def update_scene(self, x): """ update the body states """ self.set_body_state(self.calc_positions(x)) pm.register_visualizer(TwoPendulumVisualizer) except ImportError as e: vtk = None print("BallTube Visualizer:") print(e) print("VTK Visualization not available.") class MplTwoPendulumVisualizer(pm.MplVisualizer): def __init__(self, q_widget, q_layout): pm.MplVisualizer.__init__(self, q_widget, q_layout) self.axes.set_xlim(st.x_min_plot, st.x_max_plot) self.axes.set_ylim(st.y_min_plot, st.y_max_plot) self.axes.set_aspect("equal")
from model import BallInTubeModel, BallInTubeSpringModel from control import ExactInputOutputLinearisation, OpenLoop from feedforward import BallInTubeFeedforward from visualization import BallInTubeVisualizer from processing import ErrorProcessor if __name__ == "__main__": # register Modules register_simulation_module(Model, BallInTubeModel) register_simulation_module(Model, BallInTubeSpringModel) register_simulation_module(Controller, ExactInputOutputLinearisation) register_simulation_module(Controller, OpenLoop) register_simulation_module(Feedforward, BallInTubeFeedforward) register_visualizer(BallInTubeVisualizer) register_processing_module(PostProcessingModule, ErrorProcessor) # create an Application instance (needed) app = QtGui.QApplication([]) if 1: # create gui sim = Simulator() # load default config sim.load_regimes_from_file("default.sreg") sim.apply_regime_by_name("test") # gui.start_simulation()