sensorC = eye(ndof) Csurface = [[0, 1.0]] Brel = [[0], [2]] # Simple check if h > hControl: print "hControl must be bigger than h" exit(1) # Declaration of the Dynamical System processDS = FirstOrderLinearDS(x0, A) processDS.setComputebFunction("RelayPlugin", "computeB") # Control simulation sim = ControlZOHSimulation(t0, T, h) sim.setSaveOnlyMainSimulation(True) sim.addDynamicalSystem(processDS) # Actuator, Sensor & ControlManager sens = LinearSensor(processDS, sensorC) sim.addSensor(sens, hControl) act = LinearSMCOT2(sens) act.setCsurface(Csurface) act.setB(Brel) sim.addActuator(act, hControl) # Initialization sim.initialize() # Run simulation sim.run() # Get data
x0 = [Xinit, -Xinit] sensorC = eye(ndof) Csurface = [[0, 1.0]] Brel = [[0], [2]] # Simple check if h > hControl: print("hControl must be bigger than h") exit(1) # Declaration of the Dynamical System processDS = FirstOrderLinearDS(x0, A) # Control Simulation sim = ControlZOHSimulation(t0, T, h) sim.setSaveOnlyMainSimulation(True) sim.addDynamicalSystem(processDS) # Actuator, Sensor & ControlManager sens = LinearSensor(processDS, sensorC) sim.addSensor(sens, hControl) act = ExplicitLinearSMC(sens) act.setCsurface(Csurface) act.setB(Brel) sim.addActuator(act, hControl) # Initialization sim.initialize() # Run simulation sim.run() # Get data
def test_smc2(): from siconos.kernel import FirstOrderLinearDS, getMatrix, SimpleMatrix from siconos.control.sensor import LinearSensor from siconos.control.controller import LinearSMCOT2 from siconos.control.simulation import ControlZOHSimulation from numpy import eye, zeros import numpy as np from math import sin from numpy.linalg import norm # Derive our own version of FirstOrderLinearDS class MyFOLDS(FirstOrderLinearDS): def computeb(self, time): t = sin(50*time) u = [t, -t] self.setb(u) # variable declaration ndof = 2 # Number of degrees of freedom of your system t0 = 0.0 # start time T = 1 # end time h = 1.0e-4 # time step for simulation hControl = 1.0e-2 # time step for control Xinit = 1.0 # initial position # Matrix declaration A = zeros((ndof, ndof)) x0 = [Xinit, -Xinit] sensorC = eye(ndof) sensorD = zeros((ndof, ndof)) Brel = np.array([[0], [1]]) Csurface = [[0, 1.0]] # Simple check if h > hControl: print("hControl must be bigger than h") exit(1) # Declaration of the Dynamical System processDS = MyFOLDS(x0, A) # XXX b is not automatically created ... processDS.setb([0, 0]) sim = ControlZOHSimulation(t0, T, h) sim.addDynamicalSystem(processDS) # time discretisation # Actuator, Sensor & ControlManager sens = LinearSensor(processDS, sensorC, sensorD) sim.addSensor(sens, hControl) act = LinearSMCOT2(sens) act.setCsurface(Csurface) act.setB(Brel) sim.addActuator(act, hControl) # Run the simulation sim.initialize() sim.run() # get the results tmpData = sim.data() dataPlot = tmpData # compare with the reference ref = np.loadtxt(os.path.join(working_dir, "data/smc_2.ref.gz")) np.savetxt("smc_2.dat", dataPlot) print("%e" % norm(dataPlot - ref)) if (norm(dataPlot - ref) > 5e-12): print(dataPlot - ref) print("ERROR: The result is rather different from the reference file.") assert norm(dataPlot - ref) < 5e-12