classdef MyControllerSubsystem < HybridSubsystem % A controller for a bouncing ball modeled as a HybridSubsystem subclass. properties ... end properties(SetAccess = immutable) % The indices for each component in the state vector. p_ndx = 1; % index of the strength of the impulse at the next jump. tau_ndx = 2; % index of the controller timer. target_period = 2.0; end methods function obj = MyControllerSubsystem() % Constructor. state_dim = 2; input_dim = 1; output_dim = 1; output_fnc = @(x) x(1); % Call the constructor of the superclass 'HybridSubsystem' to create % the object. obj = obj@HybridSubsystem(state_dim, input_dim, output_dim, output_fnc); end % To define the data (f, g, C, D) of the system, we implement % the abstract functions from HybridSubsystem.m function xdot = flowMap(~, ~, ~, ~, ~) % Define the value of f(x, u). xdot = [0; 1]; end function xplus = jumpMap(this, x, ~, ~, ~) % Extract the state components and parameters: p = x(this.p_ndx); tau = x(this.tau_ndx); tau_ref = this.target_period; % Define the value of g(x, u): xplus = [max(0, p + 0.5*(tau_ref-tau)); 0]; end function inC = flowSetIndicator(~,~,~,~,~) inC = 1; end function inD = jumpSetIndicator(~, ~, u, ~, ~) % Set 'inD' to 1 if 'x' is in the jump set and to 0 otherwise. inD = u; end end end