-
Notifications
You must be signed in to change notification settings - Fork 4
/
dataCollection.m
72 lines (63 loc) · 2.71 KB
/
dataCollection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function output_file_str = dataCollection(dataCollection_config_str)
% Author(s): Hongbin LIN, Vincent Hui, Samuel Au
% Created on: 2018-10-05
% Copyright (c) 2018, The Chinese University of Hong Kong
% This software is provided "as is" under BSD License, with
% no warranty. The complete license can be found in LICENSE
% checking if arguments correct
argument_checking(dataCollection_config_str);
% Read JSON Config File
fprintf('Loading JSON File %s\n', dataCollection_config_str);
fid = fopen(dataCollection_config_str);
if fid<3
error('Cannot read file %s', dataCollection_config_str)
end
raw = fread(fid, inf);
str = char(raw');
fclose(fid);
config = jsondecode(str);
ARM_NAME = config.ARM_NAME;
% Create unique date folder to store the collecting data
date_time = datestr(datetime('now'),'mmmm-dd-yyyy-HH-MM-SS');
[MTM_data_path,~,~] = fileparts(dataCollection_config_str);
input_data_path_with_date = [MTM_data_path,'/',date_time];
mkdir(input_data_path_with_date);
% Add addtional info in config file and will output to file
config.date_time = date_time;
% Save wizard JSON file
output_file_str = [input_data_path_with_date, '/', 'dataCollection_info.json'];
fid = fopen(output_file_str,'w');
jsonStr = jsonencode(config);
fwrite(fid, jsonStr);
fclose(fid);
fprintf('Save config file to %s\n', output_file_str);
% Create mtm_arm obj and move every arm in home position for safety reason
mtm_arm = dvrk.mtm(ARM_NAME);
mtm_arm.move_jp([0,0,0,0,0,0,0]).wait();
config_joint_list = setting_dataCollection(config,...
input_data_path_with_date);
% dataCollection
is_collision_checking = false;
is_collecting_data = true;
current_progress = 0.0;
total_data_sets = 0;
for j=1:size(config_joint_list,2)
total_data_sets = total_data_sets + config_joint_list{j}.data_size;
end
one_data_progress_increment = 100 / total_data_sets;
for i=1:size(config_joint_list,2)
current_progress = collect_mtm_one_joint(config_joint_list{i},...
mtm_arm,...
is_collision_checking,...
is_collecting_data,...
current_progress,...
one_data_progress_increment);
end
mtm_arm.move_jp([0,0,0,0,0,0,0]).wait();
delete(mtm_arm);
end
function argument_checking(dataCollection_config_str)
if ~ischar(dataCollection_config_str)
error('Argument dataCollection_config_str should be char array instead of %s', dataCollection_config_str)
end
end