changes from zurich; my mac
This commit is contained in:
179
Classes/Moveit_wrapper.m
Normal file
179
Classes/Moveit_wrapper.m
Normal file
@@ -0,0 +1,179 @@
|
||||
classdef Moveit_wrapper < handle
|
||||
%
|
||||
|
||||
properties(Access=public)
|
||||
moveit_function_name
|
||||
para
|
||||
state = struct()
|
||||
comment
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
function obj = Moveit_wrapper(moveit_function_name,options)
|
||||
%
|
||||
|
||||
arguments
|
||||
moveit_function_name
|
||||
options.para
|
||||
end
|
||||
|
||||
obj.moveit_function_name = moveit_function_name;
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
% Ensure the function exists
|
||||
if ~exist(obj.moveit_function_name, 'file')
|
||||
error('Function "%s" does not exist.', obj.moveit_function_name);
|
||||
end
|
||||
|
||||
% Step 1: Get default parameters by calling moveit module
|
||||
if isempty(obj.para)
|
||||
global loop;
|
||||
loop = 0; % Request parameter structure
|
||||
[obj.para, obj.comment] = feval(obj.moveit_function_name);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = process(obj,signal_in)
|
||||
|
||||
isSignalClass = 0;
|
||||
if isa(signal_in,"Signal")
|
||||
signalclass_out = signal_in;
|
||||
signal_in = signal_in.signal;
|
||||
isSignalClass = 1;
|
||||
end
|
||||
input_len = length(signal_in);
|
||||
|
||||
signal_in = signal_in.';
|
||||
|
||||
% INIT MOVEIT
|
||||
global loop;
|
||||
loop = 0;
|
||||
signal_out = obj.moveit_init(signal_in);
|
||||
|
||||
% RUN MOVEIT
|
||||
global loop;
|
||||
loop = 1;
|
||||
signal_out = obj.moveit_init(signal_out);
|
||||
|
||||
% CHECK IF SIGNAL CHANGED
|
||||
if input_len ~= length(signal_out)
|
||||
warning(['Signal length changed in moveit function: ', obj.moveit_function_name]);
|
||||
end
|
||||
|
||||
if isSignalClass
|
||||
% append to logbook
|
||||
lbdesc = ['Logbookentry'];
|
||||
signalclass_out = signalclass_out.logbookentry(lbdesc);
|
||||
signalclass_out.signal = signal_out;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function open_settings(obj)
|
||||
% Opens a settings dialog for modifying Moveit parameters with appropriate input types.
|
||||
% Inserts separators when the level value changes.
|
||||
|
||||
fieldNames = fieldnames(obj.para);
|
||||
settingsCell = {};
|
||||
previousLevel = -inf; % Track previous level for separators
|
||||
|
||||
% Create input arguments for settingsdlg
|
||||
for i = 1:numel(fieldNames)
|
||||
fieldName = fieldNames{i};
|
||||
value = obj.para.(fieldName);
|
||||
|
||||
% Get description from comment structure if available
|
||||
if isfield(obj.comment, fieldName)
|
||||
description = obj.comment.(fieldName);
|
||||
else
|
||||
description = fieldName; % Default to field name if no description
|
||||
end
|
||||
|
||||
% Get level for this parameter
|
||||
if isfield(obj.comment.level, fieldName)
|
||||
currentLevel = obj.comment.level.(fieldName);
|
||||
else
|
||||
currentLevel = 1; % Default level
|
||||
end
|
||||
|
||||
% Insert separator if the level changes
|
||||
if currentLevel ~= previousLevel
|
||||
settingsCell{end+1} = 'separator';
|
||||
settingsCell{end+1} = ['Level ', num2str(currentLevel)];
|
||||
end
|
||||
previousLevel = currentLevel;
|
||||
|
||||
% Determine input type from obj.comment.type
|
||||
if
|
||||
inputType = obj.comment.type.(fieldName);
|
||||
else
|
||||
inputType = 'number'; % Default type
|
||||
end
|
||||
|
||||
% Add field description
|
||||
settingsCell{end+1} = {description; fieldName};
|
||||
|
||||
% Define the input type
|
||||
if strcmp(inputType, 'boolean')
|
||||
% Checkbox input
|
||||
settingsCell{end+1} = logical(value); % Enable checkbox
|
||||
elseif contains(inputType, '|')
|
||||
% Dropdown selection (options separated by '|')
|
||||
dropdownOptions = strsplit(inputType, '|');
|
||||
settingsCell{end+1} = dropdownOptions;
|
||||
else
|
||||
% Default: Numeric input
|
||||
settingsCell{end+1} = value;
|
||||
end
|
||||
end
|
||||
|
||||
% Open settings dialog
|
||||
[newValues, button] = settingsdlg(...
|
||||
'title', ['Settings: ', obj.moveit_function_name], ...
|
||||
'description', ['Adjust parameters for ', obj.moveit_function_name], ...
|
||||
settingsCell{:} ...
|
||||
);
|
||||
|
||||
% Update obj.para with new values only if "OK" was pressed
|
||||
if strcmp(button, 'OK')
|
||||
fieldNames = fieldnames(newValues);
|
||||
for i = 1:numel(fieldNames)
|
||||
if fieldNames{i}
|
||||
|
||||
end
|
||||
obj.para.(fieldNames{i}) = newValues.(fieldNames{i});
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
methods (Access=private)
|
||||
|
||||
function data_out = moveit_init(obj,data_in)
|
||||
arguments(Input)
|
||||
obj
|
||||
data_in double
|
||||
end
|
||||
% Step 2: Initialize the function
|
||||
[data_out, obj.state] = feval(obj.moveit_function_name, data_in, obj.state, obj.para);
|
||||
end
|
||||
|
||||
function data_out = moveit_simulation_computation(obj,data_in)
|
||||
arguments(Input)
|
||||
obj
|
||||
data_in double
|
||||
end
|
||||
% Step 3: Process input signal
|
||||
[data_out, obj.state] = feval(obj.moveit_function_name, data_in, obj.state, obj.para);
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
44
Classes/Warehouse_class/classes/StorageParameter.m
Normal file
44
Classes/Warehouse_class/classes/StorageParameter.m
Normal file
@@ -0,0 +1,44 @@
|
||||
classdef StorageParameter < handle
|
||||
%PARAMETER Summary of this class goes here
|
||||
% Detailed explanation goes here
|
||||
|
||||
properties
|
||||
name
|
||||
values
|
||||
indices
|
||||
length
|
||||
getPhysForIndex = dictionary;
|
||||
getIndexForPhys = dictionary;
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = StorageParameter(name, values)
|
||||
%PARAMETER Construct
|
||||
obj.name = name;
|
||||
obj.values = values;
|
||||
obj.indices = [1:numel(obj.values)];
|
||||
obj.length = length(obj.values);
|
||||
obj = obj.buildIndexForPhysDict();
|
||||
obj = obj.buildPhysForIndexDict();
|
||||
end
|
||||
|
||||
function obj = buildPhysForIndexDict(obj)
|
||||
%take Index
|
||||
%return Phys
|
||||
for idx = 1:numel(obj.values)
|
||||
obj.getPhysForIndex(idx) = obj.values(idx);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function obj = buildIndexForPhysDict(obj)
|
||||
%take Phys
|
||||
%return Index
|
||||
for idx = 1:numel(obj.values)
|
||||
obj.getIndexForPhys(obj.values(idx)) = idx;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user