Skip to content

Commit 5a68e5c

Browse files
author
Ross Hatton
committed
fixed scaling handling for non-unit body lengths; cleaned up some dependencies
1 parent b6b3982 commit 5a68e5c

22 files changed

+95
-187
lines changed

ProgramFiles/Geometry/ContinuousBackbone/GeneralCurvature/backbone_from_general_curvature.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
jacobian_sol = ode_multistart(@ode45,@(s,J) J_helper(s,J,dcurvdef,h_norm(s)),all_limits,0,zeros(2*length(dcurvdef(0)),1));
6060

6161
% Concatenate xy and theta jacobians.
62-
J = @(s) cat(1,reshape(L*jacobian_sol(toz(s/L)),2,[],length(s)),permute(J_theta_fun(s/L),[3,2,1]));
62+
J = @(s) cat(1,reshape(L*jacobian_sol(toz(s)),2,[],length(s)),permute(J_theta_fun(s),[3,2,1]));
6363

6464
end
6565

ProgramFiles/Geometry/ContinuousBackbone/ModalCurvature/backbone_from_curvature_bases.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
jacobian_sol = ode_multistart(@ode45,@(s,J) J_helper(s,J,kappa_basis,h_norm(s)),all_limits,0,zeros(2*length(kappa_basis),1));
156156

157157
% Concatenate xy and theta jacobians.
158-
J = @(s) cat(1,reshape(L*jacobian_sol(toz(s/L)),2,[],length(s)),J_theta_fun(s/L));
158+
J = @(s) cat(1,reshape(L*jacobian_sol(toz(s)),2,[],length(s)),J_theta_fun(s));
159159

160160
end
161161

ProgramFiles/Geometry/ContinuousBackbone/backbone.m

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
% sysf_ file. Argument should be the name of
2929
% a system in the current UserFiles folder
3030
%
31-
% length (optional): Total length of the chain. If specified, the elements of
32-
% will be scaled such that their sum is equal to L. If this field
33-
% is not provided or is entered as an empty matrix, then the links
34-
% will not be scaled.
31+
% length (optional): Total length of the backbone. If specified, the elements of
32+
% will be scaled such that their sum is equal to L. If this field
33+
% is not provided or is entered as an empty matrix, then the
34+
% backbone will not be scaled.
3535
%
3636
% shapeparams: A vector of the input parameters taken by the curvature
3737
% function
@@ -132,14 +132,11 @@
132132
%%%%%%
133133
% Calculate the transformation from the original base frame to the new base
134134
% frame
135+
135136
if calc_J
136-
[frame_zero,J_zero] = backbone_conversion_factors(h,J,shapeparams,baseframe);
137+
[frame_zero,J_zero] = backbone_conversion_factors(h,J,shapeparams,baseframe,geometry.length);
137138
else
138-
frame_zero = backbone_conversion_factors(h,[],shapeparams,baseframe);
139-
if strncmp(baseframe,'sysf_',5)
140-
frame_zero(1,3)=geometry.length*frame_zero(1,3);
141-
frame_zero(2,3)=geometry.length*frame_zero(2,3);
142-
end
139+
frame_zero = backbone_conversion_factors(h,[],shapeparams,baseframe,geometry.length);
143140
end
144141

145142
%%%%%%

ProgramFiles/Geometry/ContinuousBackbone/backbone_conversion_factors.m

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
function [frame_zero,J_zero] = backbone_conversion_factors(h,...
22
J,...
33
shapeparams,...
4-
baseframe)
4+
baseframe,...
5+
L)
56
%%%%%%%
67
% This is a helper-function for backbone.
78
%
@@ -234,6 +235,12 @@
234235
frame_mp(idx) = interpn(s.grid.eval{:},... % system evaluation grid
235236
s.B_optimized.eval.Beta{idx},... % Components of the transfomation to m-p coordinates
236237
shapeparams_cell{:}); % Current shape
238+
239+
% Scale the x and y components of the frame
240+
% location
241+
if any(idx==[1 2])
242+
frame_mp(idx) = L*frame_mp(idx)/s.geometry.length;
243+
end
237244

238245
if calc_J
239246
% Iterate over shape components for Jacobian
@@ -246,6 +253,14 @@
246253
J_mp(idx,idx2) = interpn(s.grid.eval{:},... % system evaluation grid
247254
s.B_optimized.eval.gradBeta{idx,idx2},... % Components of the transfomation to m-p coordinates
248255
shapeparams_cell{:}); % Current shape
256+
257+
% Scale the x and y components of the frame
258+
% Jacobian
259+
if any(idx==[1 2])
260+
J_mp(idx,idx2) = L*J_mp(idx,idx2)/s.geometry.length;
261+
end
262+
263+
249264
end
250265
end
251266

@@ -278,10 +293,10 @@
278293
% Get conversion factors for the original baseframe
279294
if calc_J
280295
[frame_original,J_original] =...
281-
backbone_conversion_factors(h,J,shapeparams,baseframe_original);
296+
backbone_conversion_factors(h,J,shapeparams,baseframe_original,L);
282297
else
283298
frame_original =...
284-
backbone_conversion_factors(h,J,shapeparams,baseframe_original);
299+
backbone_conversion_factors(h,J,shapeparams,baseframe_original,L);
285300
end
286301

287302
% Combine original conversion with minimum-perturbation

ProgramFiles/Geometry/NLinkChain/N_link_conversion_factors.m

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
% Decide if there is an even or odd number of joints
4646
N_odd = mod(N_links,2);
4747

48+
% Total length for use in taking weighted averages
49+
L = sum(linklengths);
50+
4851
%%%%%%%%%%%%%%%%%%%
4952

5053

@@ -166,9 +169,6 @@
166169
% of the links, using link-lengths as weighting terms
167170
case 'com-mean'
168171

169-
% Total length for use in taking weighted averages
170-
L = sum(linklengths);
171-
172172
% Convert link positions to row form
173173
chain = mat_to_vec_SE2(chain_m);
174174

@@ -329,7 +329,13 @@
329329
frame_mp(idx) = interpn(s.grid.eval{:},... % system evaluation grid
330330
s.B_optimized.eval.Beta{idx},... % Components of the transfomation to m-p coordinates
331331
jointangles_cell{:}); % Current shape
332-
332+
333+
% Scale the x and y components of the frame
334+
% location
335+
if any(idx==[1 2])
336+
frame_mp(idx) = L*frame_mp(idx)/s.geometry.length;
337+
end
338+
333339
% Iterate over shape components for Jacobian
334340
for idx2 = 1:numel(jointangles)
335341

@@ -341,11 +347,19 @@
341347
s.B_optimized.eval.gradBeta{idx,idx2},... % Components of the transfomation to m-p coordinates
342348
jointangles_cell{:}); % Current shape
343349

350+
% Scale the x and y components of the frame
351+
% Jacobian
352+
if any(idx==[1 2])
353+
J_mp(idx,idx2) = L*J_mp(idx,idx2)/s.geometry.length;
354+
end
344355
end
356+
357+
345358

346359
end
347-
frame_mp(1)=sum(linklengths)*frame_mp(1);
348-
frame_mp(2)=sum(linklengths)*frame_mp(2);
360+
361+
362+
349363
% Convert the transforms that were just found into an
350364
% SE(2) matrix and a body-velocity Jacobian
351365
frame_mp = vec_to_mat_SE2(frame_mp);

ProgramFiles/Physics/LowReynoldsRFT/Continuous_backbone/LowRE_connection_continuous.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
[h,J] = backbone(geometry,shapeparams);
2020

2121
% Itegrate from one halflength before the midpoint to one halflength after it
22-
int_limit = geometry.length*[-0.5 0.5];
22+
int_limit = [-0.5 0.5];
2323

2424
% Now integrate to get the pfaffian
25-
Omega_sol = ode45( @(s,Omega) LowRE_Pfaffian_infinitesimal(s,h(s),J(s),physics.drag_coefficient,physics.drag_ratio),int_limit,zeros(3,3+length(shapeparams)));
25+
Omega_sol = ode45( @(s,Omega) LowRE_Pfaffian_infinitesimal(s,h(s),J(s),geometry.length,physics.drag_coefficient,physics.drag_ratio),int_limit,zeros(3,3+length(shapeparams)));
2626

2727
% Reshape the terms of the Pfaffian into a matrix of the correct dimension
2828
Omega = reshape(deval(Omega_sol,int_limit(end)),3,[]);
@@ -35,19 +35,20 @@
3535
end
3636

3737

38-
function dOmega = LowRE_Pfaffian_infinitesimal(s,h,J,c,drag_ratio) %#ok<INUSL>
38+
function dOmega = LowRE_Pfaffian_infinitesimal(s,h,J,lambda,c,drag_ratio) %#ok<INUSL>
3939
% Calculate the derivative of the local connection as it's built up along
4040
% the backbone
4141

4242
% Convert velocity to local velocity
4343
gdot_to_gcirc_local = TgLginv(h);
4444

4545
% Local drag, based on unit longitudinal drag, lateral according to the ratio, no local
46-
% torsional drag, multiplied by drag coefficient
46+
% torsional drag, multiplied by drag coefficient and local scaled
47+
% differential length
4748
gcirc_local_to_F_local = ...
4849
[-1 0 0;
4950
0 -drag_ratio 0;
50-
0 0 0]*c;
51+
0 0 0]*c*lambda;
5152

5253
% Transfer force to midpoint-tangent frame by transpose of the
5354
% adjoint-inverse action

ProgramFiles/Physics/LowReynoldsRFT/Continuous_backbone/LowRE_metric_continuous.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[A, h, J] = LowRE_local_connection(geometry,physics,shapeparams);
1212

1313
% Integrate along the body for the power metric
14-
Mp_sol = ode45(@(s,Mp) dMetric(s,Mp,A,h(s),J(s),drag_matrix),int_limit,zeros(length(shapeparams)));%zeros(length(shapeparams)^2,1));
14+
Mp_sol = ode45(@(s,Mp) dMetric(s,Mp,A,h(s/geometry.length),J(s/geometry.length),drag_matrix),int_limit,zeros(length(shapeparams)));%zeros(length(shapeparams)^2,1));
1515

1616
% Form the components of the metric into the standard NxN symmetric matrix form
1717
Mp = reshape(deval(Mp_sol,int_limit(end)),length(shapeparams),[]);

ProgramFiles/sys_calcpath.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
%Vectorize the shape change equation if it's an inline function
4747
p = vectorize_shch(p); %#ok<NODEF>
48-
save(infile2,'p')
48+
4949

5050
%get shape change loci
5151
p = find_loci(s,p);

ProgramFiles/sys_calcpath_fcns/se2_integrator_all_terms.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
shape = phi_fun(t);
88
shapelist = num2cell(shape);
99
dshape = dphi_fun(t);
10-
dshape1=dshape;
11-
clear dshape
12-
for i=1:length(dshape);
13-
dshape(i,1)=dshape1(i);
14-
end
10+
dshape1=dshape(:);
1511
n_dim=length(s.vecfield.eval.content.Avec_optimized(1,:));
1612

1713
if length(shape)<n_dim

UserFiles/GenericUser/Systems/curv_triangle_wave_one_period.m

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)