-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wc.m
More file actions
144 lines (121 loc) · 5.26 KB
/
test_wc.m
File metadata and controls
144 lines (121 loc) · 5.26 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
%% This code is for testing the package of WheelChair to see if the basic function works
clear; clc; close all;
c = distinguishable_colors(20);
addpath("stlTools/");
addpath("path-planning/")
path = fullfile("stl/","1B_room.stl");
[vertices, faces, ~, ~] = stlRead(path);
room.vertices = vertices / 1000;
room.faces = faces;
wc = WheelChair(2, path);
% wc.T_world_wc = [0 -1 0 100;
% 1 0 0 300;
% 0 0 1 0;
% 0 0 0 1];
% wc.T_world_wc = [1 0 0 100;
% 0 1 0 100;
% 0 0 1 100;
% 0 0 0 1];
% wc.spawnWheelChair;
% disp(wc.T_world_wc)
%% Testing code (T_wc_robotBase + Visualization)
[V, F] = wc.boundingBox();
% Define total parameters for the robot
L = 800.0 / 1000; % Total arc length (mm)
theta_total = pi/2; % Total bending angle for the full length (radians), e.g., 60 degrees
phi = 0; % Bending plane orientation (radians), e.g., 45 degrees
nPoints = 100;
T1 = wc.robots(1).fkin(L, -pi/2, pi/4, wc.T_world_wc * wc.T_wc_robotBase);
T2 = wc.robots(2).fkin(L, -pi/2, 0, T1);
% OD = 200;
backbone1 = wc.robots(1).backbone(L, -pi/2, pi/4, wc.T_world_wc * wc.T_wc_robotBase, nPoints);
backbone2 = wc.robots(2).backbone(L, -theta_total, phi, T1, nPoints);
body1 = wc.robots(1).robot_body(backbone1, 2, 20);
body2 = wc.robots(2).robot_body(backbone2, 2, 20);
figure; hold on;
stlPlot(V, F, 'wheelchair visualization');
plot3(backbone1(1,:), backbone1(2,:), backbone1(3,:), 'LineWidth', 2, 'Color', c(11,:));
% hold on;
plot3(backbone2(1,:), backbone2(2,:), backbone2(3,:), 'LineWidth', 2, 'Color', c(12,:));
% plot3(backbone3(1,:), backbone3(2,:), backbone3(3,:), 'LineWidth', 2, 'Color', c(13,:));
surf(body1.X, body1.Y, body1.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(11,:), 'HandleVisibility', 'off');
surf(body2.X, body2.Y, body2.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(12,:), 'HandleVisibility', 'off');
% surf(body3.X, body3.Y, body3.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(13,:), 'HandleVisibility', 'off');
set(gca, 'FontName', 'CMU Serif', 'FontSize', 16)
legend({"Wheelchair","Robot 1", "Robot 2"}, location="southeast")
wc.robots(1).frame(eye(4),0.5); % world frame
wc.robots(1).frame(wc.T_world_wc * wc.T_wc_robotBase, 0.5); % robotBase frame
wc.robots(1).frame(T1, 0.5); % frame at end tip - Robot 1
wc.robots(1).frame(T2, 0.5); % frame at end tip - Robot 2
% robot.frame(T3, 50); % frame at end tip - Robot 3
xlim([-500, 500]);
ylim([-500, 500]);
zlim([-500, 500]);
axis equal;
grid on;
xlabel('X [mm]');
ylabel('Y [mm]');
% zlabel('Z [mm]');
%% Testing boundingBox
% wc.frame(wc.T_world_wc, 100);
% [V, F] = wc.boundingBox();
%
% % fvc = surf2patch(wcBox.X, wcBox.Y, wcBox.Z);
%
% % figure;
% % surf(wcBox.X, wcBox.Y, wcBox.Z, 'HandleVisibility', 'off')
% patch("Faces",F,"Vertices",V, 'faceColor', 'none', ...
% 'lineWidth', 2, 'DisplayName', 'wheelChair' );
% % patch(fvc)
%
% % figure;
% % stlPlot(V, F, 'wheelChair');
% % xlim([-1000, 1000])
% % ylim([-1000, 1000])
% % zlim([-1000, 1000])
%% Testing the stl reading, combining, and spawning wheelchair
% wc.T_world_wc = [eye(3), [0, -1000, 0]'; 0, 0, 0, 1];
wc.spawnWheelChair;
[V, F] = wc.boundingBox();
% create visualization only Vertices and Faces
[VV, FF] = stlAddVerts(wc.Vertices, wc.Faces, wc.Vwc, wc.Fwc);
figure; hold on
stlPlot(room.vertices, room.faces, "Room STL");
figure; hold on;
stlPlot(VV, FF, 'combined');
axis equal;
% Define total parameters for the robot
L = 800.0 / 1000; % Total arc length (mm)
theta_total = pi/2; % Total bending angle for the full length (radians), e.g., 60 degrees
phi = 0; % Bending plane orientation (radians), e.g., 45 degrees
nPoints = 100;
T1 = wc.robots(1).fkin(L, -pi/2, pi/4, wc.T_world_wc * wc.T_wc_robotBase);
T2 = wc.robots(2).fkin(L, -pi/2, 0, T1);
% OD = 200;
backbone1 = wc.robots(1).backbone(L, -pi/2, pi/4, wc.T_world_wc * wc.T_wc_robotBase, nPoints);
backbone2 = wc.robots(2).backbone(L, -theta_total, phi, T1, nPoints);
body1 = wc.robots(1).robot_body(backbone1, 2, 20);
body2 = wc.robots(2).robot_body(backbone2, 2, 20);
% figure;
plot3(backbone1(1,:), backbone1(2,:), backbone1(3,:), 'LineWidth', 2, 'Color', c(11,:));
hold on;
plot3(backbone2(1,:), backbone2(2,:), backbone2(3,:), 'LineWidth', 2, 'Color', c(12,:));
% plot3(backbone3(1,:), backbone3(2,:), backbone3(3,:), 'LineWidth', 2, 'Color', c(13,:));
surf(body1.X, body1.Y, body1.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(11,:), 'HandleVisibility', 'off');
surf(body2.X, body2.Y, body2.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(12,:), 'HandleVisibility', 'off');
% surf(body3.X, body3.Y, body3.Z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', c(13,:), 'HandleVisibility', 'off');
set(gca, 'FontName', 'CMU Serif', 'FontSize', 16)
legend({"obstacles", "Robot 1", "Robot 2"}, location="southeast")
wc.robots(1).frame(eye(4), 0.5); % world frame
wc.robots(1).frame(wc.T_world_wc * wc.T_wc_robotBase, 0.5); % robotBase frame
wc.robots(1).frame(T1, 0.5); % frame at end tip - Robot 1
wc.robots(1).frame(T2, 0.5); % frame at end tip - Robot 2
% robot.frame(T3, 50); % frame at end tip - Robot 3
xlim([-500, 500]);
ylim([-500, 500]);
zlim([-500, 500]);
axis equal;
grid on;
xlabel('X [m]');
ylabel('Y [m]');
zlabel('Z [m]');