-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_wheelchairDK.m
More file actions
144 lines (115 loc) · 3.99 KB
/
plot_wheelchairDK.m
File metadata and controls
144 lines (115 loc) · 3.99 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
%% ------------------------------------------------------
% Wheelchair: Straight then Circular Motion (Top View)
% COM vs Axle Trajectory + STL at Start/End
% ------------------------------------------------------
clear; clc; close all;
%% ------------------------------------------------------
% Load STL Room
% ------------------------------------------------------
path = fullfile("stl/","PP_room4.stl");
[vertices, faces, ~, ~] = stlRead(path);
room.vertices = vertices * 0.0254; % inch → meter
room.faces = faces;
%% ------------------------------------------------------
% Initialize Wheelchair
% ------------------------------------------------------
wc = WheelChair(3, path);
%% Motion parameters
N_straight = 40;
N_circle = 120;
ds_straight = 0.04; % straight motion
dL_circle = 0.02; % circular motion
dR_circle = 0.05;
%% Storage
N = N_straight + N_circle;
COM_traj = zeros(N+1,2);
axle_traj = zeros(N+1,2);
%% Initial pose
T_start = wc.T_world_wc;
theta = atan2(T_start(2,1), T_start(1,1));
COM_traj(1,:) = T_start(1:2,4)';
axle_traj(1,:) = COM_traj(1,:) - ...
wc.COMoffset * [cos(theta), sin(theta)];
idx = 1;
%% ------------------------------------------------------
% 1) Straight motion
%% ------------------------------------------------------
for k = 1:N_straight
T = wc.drive(ds_straight, ds_straight);
wc.T_world_wc = T;
theta = atan2(T(2,1), T(1,1));
idx = idx + 1;
COM_traj(idx,:) = T(1:2,4)';
axle_traj(idx,:) = COM_traj(idx,:) - ...
wc.COMoffset * [cos(theta), sin(theta)];
end
%% ------------------------------------------------------
% 2) Circular motion
%% ------------------------------------------------------
for k = 1:N_circle
T = wc.drive(dL_circle, dR_circle);
wc.T_world_wc = T;
theta = atan2(T(2,1), T(1,1));
idx = idx + 1;
COM_traj(idx,:) = T(1:2,4)';
axle_traj(idx,:) = COM_traj(idx,:) - ...
wc.COMoffset * [cos(theta), sin(theta)];
end
% Save end pose
T_end = wc.T_world_wc;
%% ------------------------------------------------------
% Plot top view trajectories
%% ------------------------------------------------------
figure('Color','w'); hold on; axis equal; grid on;
set(gca, 'FontName', 'CMU Serif', 'FontSize', 14);
xlabel('X (m)');
ylabel('Y (m)');
title('Wheelchair Differential Kinematics Visualization');
% Trajectories
plot(COM_traj(:,1), COM_traj(:,2), ...
'b-', 'LineWidth', 2);
plot(axle_traj(:,1), axle_traj(:,2), ...
'r-', 'LineWidth', 2);
% Start points
plot(COM_traj(1,1), COM_traj(1,2), ...
'bo', 'MarkerFaceColor','b', 'MarkerSize',6);
plot(axle_traj(1,1), axle_traj(1,2), ...
'ro', 'MarkerFaceColor','r', 'MarkerSize',6);
% End points
plot(COM_traj(end,1), COM_traj(end,2), ...
'bs', 'MarkerFaceColor','b', 'MarkerSize',8);
plot(axle_traj(end,1), axle_traj(end,2), ...
'rs', 'MarkerFaceColor','r', 'MarkerSize',8);
legend({'COM trajectory', ...
'Axle trajectory', ...
'COM start', 'Axle start', ...
'COM end', 'Axle end'}, ...
'Location','northwest', 'FontSize', 10);
%% ------------------------------------------------------
% Draw STL at start and end (top view)
%% ------------------------------------------------------
[V0, F0] = wc.boundingBox(T_start);
[V1, F1] = wc.boundingBox(T_end);
% Start STL
patch('Vertices',V0,'Faces',F0, ...
'FaceColor',[0.6 0.6 0.6], ...
'FaceAlpha',0.3,'EdgeColor','none', 'HandleVisibility','off');
% End STL
patch('Vertices',V1,'Faces',F1, ...
'FaceColor',[0.2 0.8 0.2], ...
'FaceAlpha',0.4,'EdgeColor','none', 'HandleVisibility','off');
% Labels
text(COM_traj(1,1)-0.35, COM_traj(1,2)+0.1, ...
' Start pose', ...
'FontName','CMU Serif', ...
'FontSize',12, ...
'Color',[0.3 0.3 0.3], ...
'FontWeight','bold');
text(COM_traj(end,1), COM_traj(end,2), ...
' End pose', ...
'FontName','CMU Serif', ...
'FontSize',12, ...
'Color',[0 0.5 0], ...
'FontWeight','bold');
% xlim([-1,3])
view(2);