-
Notifications
You must be signed in to change notification settings - Fork 0
/
thurstmapping.m
136 lines (107 loc) · 2.89 KB
/
thurstmapping.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
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
% Calculation of need thrust of desiered force vector
% F = M*T;
% F is a result from a PID or can for example be mapped from a 3D mouse.
% This makes it easy to drop or two motors as well, just remove it from the
% vectors...
%
% Test code for Purdue ROV x8
clear all;
% Desiered force vector
%function T = thurstmapping(F)
F = [5,5,5,1,1,1]';
% Pivot offset
pivoff = [0, 0, 0]'; % m
COM = [1.31, 0.0, 0.31]'; % inches
%pivoff = COM;
COM = [COM COM COM COM COM COM COM COM];
% Thruster locations: X Y Z in INCHES;
%Z is forward/back, y is up/down, X is left/right
loc = [-4.7524, 0, 11.2148;
4.7524, 0, 11.2148;
-4.7524, 0, -7.631;
4.7524, 0, -7.631;
-5.5709, 5.6384, 6.0419;
5.5709, 5.6384, 6.0419;
-5.5709, 5.6384, -2.485; %]';
5.5709, 5.6384, -2.485;];
% Note the transpose! Its on everything in the code
%X is forward/back, Y is to the left/right, Z is up/down
X = loc(:,3);
Y = loc(:,1);
Z = loc(:,2);
loc = [X Y Z]';
loc = loc - COM;
loc = loc * 2.54 / 100;
z = sqrt(1-.342^2);
% Thruster rotations components: X Y Z
rot = [0.342 ,0, z;
-0.342 ,0, z;
0.342 ,0, -z;
-0.342 ,0, -z;
0,1,0;
0,1,0;
0,1,0; %]'; % uncomment to remove one motor
0,1,0;];
X = rot(:,3);
Y = rot(:,1);
Z = rot(:,2);
rot = [X Y Z]';
% Calculate the new Force vector from the new pivot position
F(1:3) = F(1:3) + cross(pivoff,F(4:6));
% Build matrix
% Force
% Force
M = rot;
% Force momentum
M(4:6,:) = cross(rot,loc,1);
M(:,5) = zeros([6 1]);
M(:,8) = zeros([6 1]);
%M(abs(M) < 0.01) = 0;
fid = fopen('results.txt','w');
Tmap = pinv(M);
Tmap(:,4:6) = Tmap(:,4:6)/10; % "Nm" is a lot stronger unit then N
val = round(Tmap*1024);
for y = 1:1:8
fprintf(fid, ['\tmapper_matrices.matrices[%d].t%d = vect6Make(' sprintf('%5d, ',val(y,1:5)) '%5d);\n'], 10, y, val(y,6));
end
fprintf(fid,'\n');
%{
for y = 1:1:8
fprintf(fid, ['\tmapper_matrices.matrices[0].t%d = vect6Make(' sprintf('%5d, ',val(y,1:5)) '%5d);\n'], y, val(y,6));
end
fprintf(fid,'\n');
for x = 1:1:8
M = rot;
% Force momentum
M(4:6,:) = cross(rot,loc,1);
%% is this correct? ask Jacob
M(:,x) = zeros([6 1]); %take the first motor "offline"
% Solve the linear equation system for minimum 2-norm on the thrust
% This spreads out the thrust on as many thruster as possible!
% Taking M\F will allways give two thruster unused.
Tmap = pinv(M);
Tmap(:,4:6) = Tmap(:,4:6)/10; % "Nm" is a lot stronger unit then N
val = round(Tmap*1024);
for y = 1:1:8
fprintf(fid, ['\tmapper_matrices.matrices[%d].t%d = vect6Make(' sprintf('%5d, ',val(y,1:5)) '%5d);\n'], x, y, val(y,6));
end
fprintf(fid,'\n');
end
%T = val*F
%end
fclose(fid);
%}
T = val*F
%{
i2C = floor(1125.2*T);
%fprintf('%d\n',i2C);
Twanted = [32000;
-32000;
32000;
-32000;
0
0
0
0]*748;
Fwanted = pinv(val)*Twanted;
%}