% Pre-Processing of Code Generation with Simulink Data Object
% Make signal and parameter objects to define variable specifications (RAM/ROM)
% Resolve signal resolution with DISABLEIMPLICITSIGNALRESOLUTION

% make signal objects
sig.name = { ...
	'timer_en1_0', 'timer_en2_0', 'timer_pen_0', ...		% signals
	'operation_mode', 'motor_number', 'pen_idx', ...		% states (data store memories)
	'theta1m_ref_bl', 'theta2m_ref_bl', 'timer_trj', ...
	'ud_backlash1', 'ud_backlash2', ...						% states (unit delay blocks)
	'ud_engage1', 'ud_engage2', ...
	'ud_flag_enter', 'ud_flag_run', 'ud_flag_pen', ...
	'ud_theta1m_ref', 'ud_theta2m_ref' ...
	};
num_sig = length(sig.name);
for n = 1:num_sig
	cmd = strcat( ...
		sig.name{n}, ' = ', 'mpt.Signal;', ...
		sig.name{n}, '.RTWInfo.CustomAttributes.DefinitionFile = ''nxtscara_ram.c'';', ...
		sig.name{n}, '.RTWInfo.CustomAttributes.HeaderFile = ''nxtscara_ram.h'';' ...
		);
	eval(cmd)
end

% resolve signal resolution
sig.handle = disableimplicitsignalresolution(bdroot(gcb));

% make parameter objects
param.name = { ...
	'backlash1', 'backlash2', 'dthetam_bl', ...
	'engage1_iv', 'engage2_iv', 'num_mode', 'num_motor', ...
	'pwm1_adjst', 'pwm2_adjst', 'pwm3_adjst', 'pwm3_pen', ...
	'pwm1_gain', 'pwm1_offset', 'pwm2_gain', 'pwm2_offset', ...
	'theta1m_max', 'theta2m_max', 'theta1m_iv', 'theta2m_iv', ...
	'time_en1', 'time_en2', 'time_finish', ...
	'time_pwm3', 'time_pen', 'time_table_pen', 'time_wait', ...
	'x_ref', 'y_ref',  ...
	};
num_param = length(param.name);
param.value = cell(1, num_param);
for n = 1:num_param
	cmd = strcat( ...
		'param.value{', num2str(n), '} = ', param.name{n}, ';', ...
		param.name{n}, ' = ', 'mpt.Parameter;', ...
		param.name{n}, '.Value = ', 'param.value{', num2str(n), '};', ...
		param.name{n}, '.RTWInfo.CustomAttributes.DefinitionFile = ''nxtscara_rom.c'';', ...
		param.name{n}, '.RTWInfo.CustomAttributes.HeaderFile = ''nxtscara_rom.h'';' ...
		);
	eval(cmd)
end
