def test_control_signal(): Ts = 1e-3 M = 4 digitalControl = DigitalControl(Ts, M) x = np.ones(M) t = Ts np.testing.assert_allclose(np.zeros(M), digitalControl.control_signal()) print(np.asarray(digitalControl.control_signal())) res = digitalControl.control_contribution(t, x) print(np.asarray(digitalControl.control_signal())) print(np.asarray(res)) np.testing.assert_allclose(np.ones(M), digitalControl.control_signal()) np.testing.assert_allclose(np.ones(M), res) res = digitalControl.control_contribution(t+Ts, -x) print(np.asarray(digitalControl.control_signal())) print(np.asarray(res)) np.testing.assert_allclose(np.zeros(M), digitalControl.control_signal()) np.testing.assert_allclose(-np.ones(M), res) res = digitalControl.control_contribution(t, x) print(np.asarray(digitalControl.control_signal())) print(np.asarray(res)) np.testing.assert_allclose(np.zeros(M), digitalControl.control_signal()) np.testing.assert_allclose(-np.ones(M), res)
def test_control_signal(): Ts = 1e-3 epsilon = 1e-9 M = 4 digitalControl = DigitalControl(Ts, M) x = np.ones(M) t = Ts np.testing.assert_allclose(np.ones(M), digitalControl.control_signal()) print("Inital control signal: ", np.asarray(digitalControl.control_signal())) digitalControl.control_update(t + epsilon, x) res = digitalControl.control_contribution(t + epsilon) print( "Control signal after first control contribution call: ", np.asarray(digitalControl.control_signal()), ) print("control contribution response: ", np.asarray(res)) np.testing.assert_allclose(np.ones(M), digitalControl.control_signal()) np.testing.assert_allclose(np.ones(M), res) digitalControl.control_update(t + Ts + epsilon, -x) res = digitalControl.control_contribution(t + Ts + epsilon) print( "control signal after second control contribution update: ", np.asarray(digitalControl.control_signal()), ) print("control contribution response: ", np.asarray(res)) np.testing.assert_allclose(np.zeros(M), digitalControl.control_signal()) np.testing.assert_allclose(-np.ones(M), res) digitalControl.control_update(t + 2 * Ts + epsilon, -x) res = digitalControl.control_contribution(t + 2 * Ts + epsilon) print( "control signal after third control contribution update: ", np.asarray(digitalControl.control_signal()), ) print("control contribution response: ", np.asarray(res)) np.testing.assert_allclose(np.zeros(M), digitalControl.control_signal()) np.testing.assert_allclose(-np.ones(M), res)