Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ross #99

Open
wants to merge 133 commits into
base: found-on-imac
Choose a base branch
from
Open

Ross #99

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
a34e3be
Added flag for gait optimization to system files and switch in gait_g…
zabrock Oct 11, 2018
3c7af8b
Merging Ross's bug fixes into inertial optimization code from master
zabrock Oct 11, 2018
f481ba1
Merge with latest master build
zabrock Oct 16, 2018
f7a63fd
Code runs, but not as Hossein expects - likely an interpolation/start…
zabrock Oct 31, 2018
45eb51a
Need to merge in new fixes from master. Merge branch 'master' into Za…
zabrock Oct 31, 2018
25aa5c5
Running version, but result of inertial optimizer is unexpected.
zabrock Nov 8, 2018
d18d9d7
Merge pull request #84 from OSU-LRAM/Ross
rlhatton Jan 2, 2019
c2a44b8
Merge pull request #85 from OSU-LRAM/Ross
rlhatton Jan 2, 2019
83590c6
Merge pull request #86 from OSU-LRAM/Ross
rlhatton Jan 13, 2019
8d64c1f
Merge pull request #88 from OSU-LRAM/Ross
rlhatton Jan 29, 2019
83e43e2
Merge branch 'master' into Zach's-Branch
zabrock Feb 6, 2019
6036c94
Added inertial first pass code from Ross's Branch
zabrock Apr 2, 2019
e4b6255
Added lie bracket and jacobian derivative calculators, added pullback…
zabrock Apr 5, 2019
ff88af3
renamed fixed jacobian derivative file
zabrock Apr 8, 2019
81cc10d
Added calculator for derivative of full mobile Jacobian
zabrock Apr 8, 2019
478532a
New utilities and functions to calculate mass and coriolis matrices
zabrock May 6, 2019
220c652
debugging modal n-link chain
Aug 13, 2019
87e4c21
got modal code working correctly
Aug 13, 2019
be131a6
working modal linkages, and updated system file examples
Aug 13, 2019
653a44f
Merge pull request #90 from OSU-LRAM/Ross
rlhatton Aug 13, 2019
460a6ea
Functioning version of inertial optimizer, but output doesn't seem to…
zabrock Oct 4, 2019
2e51abe
Version that calculates gradient on its own
zabrock Oct 16, 2019
610dae2
Inertia cost as the square root of torque squared version
zabrock Oct 31, 2019
4e38a20
Committing results of scaling time period to square root of path leng…
zabrock Dec 25, 2019
025c49e
Minimum viable product
zabrock Jan 22, 2020
d9b12d1
Removed old files, updated documentation
zabrock Jan 22, 2020
47173cd
Updating system file for rotational three-link swimmer
zabrock Apr 2, 2020
07c606f
Added default for system type flag in sys_calcsystem and restored def…
zabrock May 6, 2020
cd19ae5
Fixed merge conflicts
zabrock May 6, 2020
54b724a
Merge pull request #91 from OSU-LRAM/inertia-optimizer
sureshr14 May 19, 2020
08cc992
Integrating metric surface option into sysplotter
sureshr14 May 21, 2020
783c791
files missed during previous commit of metric surface button
sureshr14 May 21, 2020
8607436
more files
sureshr14 May 21, 2020
23e7a8a
Fixing issues with optimize gait button
sureshr14 May 22, 2020
8a2c403
added tissot crosses to mfield_draw and metricellipsefield, and secon…
May 26, 2020
690b541
have general baseframe transforms added
May 27, 2020
7200b62
basic multi-chain functionality working; some debugging left
May 28, 2020
8a9faee
debugging optimized-coordinate display
May 28, 2020
efd5bcb
fixed optimized-coordinate display; made internal code use new compos…
May 28, 2020
2d0be1d
branching n-link chain code works for position
May 29, 2020
9df0626
Collected Jacobians working
May 29, 2020
9e6eeb7
some final debugging to do on the conversion factor
May 30, 2020
ebeebc9
branched chain up and running
May 30, 2020
8d7796b
all checks on branched chain seem to have passed
May 30, 2020
0b1d7d2
Merge pull request #92 from OSU-LRAM/Ross
rlhatton May 30, 2020
4b20a89
merged the updates that I had put into the master branch into this re…
May 30, 2020
6eebf3a
Fixing bugs in metric surface option
sureshr14 Jun 17, 2020
db6ecce
fixed backbone conversion functions to match new ability to handle mu…
Jun 17, 2020
b9bdc0a
Merge pull request #94 from OSU-LRAM/Ross
rlhatton Jun 17, 2020
12e325c
Merge pull request #95 from OSU-LRAM/master
rlhatton Jun 17, 2020
084b1bf
fixed indenting
Jun 17, 2020
27c3145
suppressing isomap output
Jun 17, 2020
dcbe2b7
Merge branch 'ReviewBrach-April20' of https://github.com/OSU-LRAM/Geo…
Jun 17, 2020
a1afc74
fixed some plotting bugs, suppressed iteration count in the multi-dim…
Jun 17, 2020
d1e108c
refactored metric conversion and surface plotting. Now need to figure…
Jun 18, 2020
4c0f68f
fixed isomap, made some speed improvements, got contour-on-surface wo…
Jun 19, 2020
03f3a46
made isomap favor domes rathter than bowls
Jun 19, 2020
0939c6d
have shape change overlays workign with ccf_draw
Jun 19, 2020
bf113a2
most of metric field plot refactoring done
Jun 19, 2020
c195fd1
metrics on surfaces now plot, a little clipping where they duck under…
Jun 19, 2020
a93df87
initial vector-field-on-surface working, need to make sure z componen…
Jun 20, 2020
ed0ddc7
got proper mapping of vectors onto surfaces
Jun 20, 2020
2a873e2
vectors on surface working with shape change overlay, now checking wh…
Jun 20, 2020
6483e77
UI tests passed
Jun 20, 2020
990919e
refactored optimalgaitgenerator slightly
Jun 21, 2020
61183b0
Merge pull request #96 from OSU-LRAM/ReviewBrach-April20
rlhatton Jun 21, 2020
9c03386
Merge pull request #97 from OSU-LRAM/master
rlhatton Jun 21, 2020
09376b2
Made metric ellipse field draw in the spot color
rlhatton Nov 15, 2020
faa9ac7
Made inertial calculations work with higher dimension systems
rlhatton Nov 15, 2020
28079f2
Added New Optimization Costs
NathanJustus Nov 19, 2020
0096cd0
Merge pull request #100 from OSU-LRAM/Ross
rlhatton Nov 20, 2020
31b19e1
Multi-Dimensional Fixes
NathanJustus Dec 31, 2020
4deb506
Batch Interp GetVelocities
NathanJustus Jan 5, 2021
3e81da3
Batch Interpolation on Gradients
NathanJustus Jan 7, 2021
1bd5550
Modify default config files
NathanJustus Mar 18, 2021
dec759f
Fixes failed loading of large data files
NathanJustus Mar 18, 2021
ddad04f
Merge branch 'Nathan's-Branch' of https://github.com/OSU-LRAM/Geometr…
NathanJustus Mar 18, 2021
6c309ed
Fixes startup/animation crash
NathanJustus Mar 18, 2021
9f8dcba
Merge pull request #102 from OSU-LRAM/Matlab-r2020b-crashfix
NathanJustus Mar 19, 2021
d9d551d
Fixes Matlab r2020b crash
NathanJustus Mar 22, 2021
e848e9c
Merged optimizer bugfixes and resolved conflicts
NathanJustus Mar 23, 2021
d4b88e8
Stops Saving Optimal Gaits
NathanJustus May 6, 2021
d7075fc
Export Data Button
NathanJustus May 7, 2021
623a589
Fix refresh button autoresize
NathanJustus May 7, 2021
18991eb
Merge pull request #106 from OSU-LRAM/Nathan's-Branch
NathanJustus May 7, 2021
213e780
added old animate_locomotor changes
rlhatton May 18, 2021
8d0c335
Merge pull request #107 from OSU-LRAM/master
rlhatton May 18, 2021
1ebcf91
Merge branch 'Ross' of https://github.com/OSU-LRAM/GeometricSystemPlo…
rlhatton May 18, 2021
c6e12e0
made some changes to display of CCF in high-dim spaces
rlhatton Nov 18, 2021
c98e6aa
Merge pull request #108 from OSU-LRAM/Ross
rlhatton Nov 18, 2021
a8c0540
Generalized hypercube_mesh.m to any number of dimensions
Capprin Jun 29, 2021
be2e702
Updated hypercube_element_shape_functions.m to use arbitrary dimensions
Capprin Jun 29, 2021
7a17043
Added twin-rotor test case
Capprin Nov 17, 2021
6558bd7
Moved SO(3) capability into sysplotter
Capprin Nov 17, 2021
d87fc8c
Moved coordinate optimizers to dedicated folder (requires reconfigura…
Capprin Nov 17, 2021
b03eef6
Added dedicated unit test directory
Capprin Nov 17, 2021
8bcd088
Reorganized some Utilities, Tests
Capprin Nov 17, 2021
c08a342
Updated gitignore
Capprin Nov 17, 2021
0dbc35e
Removed RefPoint, Hemholtz directories from configuration
Capprin Nov 17, 2021
6d8f2b4
Added choice of configuration space, enforced on initialization
Capprin Nov 17, 2021
5b601bb
Bug fix, optimizer choice for Lie groups
Capprin Nov 18, 2021
0b276ff
Made domain-specific changes (wrappers) for updated functions
Capprin Nov 18, 2021
a8b43c4
Updated sys_calcsystem to respect coordinate choice
Capprin Nov 18, 2021
cbf09ed
Removed singularity case (ratios no longer relevant)
Capprin Nov 22, 2021
80ce8cb
Removed unused stretch parameter
Capprin Nov 22, 2021
850a661
Added SO(3) path integration
Capprin Nov 24, 2021
e8cb54d
Did first pass SO(3) bug test, fixed function naming
Capprin Nov 24, 2021
5e087dc
Jumped over drawing for non-SE2 systems
Capprin Nov 24, 2021
20f2128
Updated CCF sign choice for cBVI consistency
Capprin Nov 24, 2021
f886258
Merge pull request #109 from Capprin/more-groups
Capprin Nov 29, 2021
ab8a10a
Merge pull request #110 from OSU-LRAM/master
rlhatton Dec 17, 2021
336e092
fixed metric stretch 2-d overlay bug
rlhatton Dec 17, 2021
93c9365
removed extraneous frame from stretched surface plots
rlhatton Dec 17, 2021
51b22d6
fixed zero-augmentation of gaits being executed by systems with more …
rlhatton Dec 17, 2021
f8c10f9
updated propertyDataMacOS to prevent start-up bug
rlhatton Dec 17, 2021
7e632cd
Merge pull request #111 from OSU-LRAM/Ross
rlhatton Dec 17, 2021
3ee4cf1
rescaled the animation to better fit the snake size
rlhatton Dec 18, 2021
7085903
fixed bug in handling systems with fewer shape variables than the gai…
rlhatton Dec 18, 2021
1cc69f0
initial (non-working) code for locomotor race
rlhatton Dec 18, 2021
458650a
almost have the race working. transform to optimal coordinates has go…
rlhatton Dec 19, 2021
a29615a
racing animation works for viscous swimmers
rlhatton Dec 19, 2021
b6bdce9
split out functions from optimalgaitgenerator
rlhatton Dec 19, 2021
ee60ba2
new calculation for efficiency implemented, numbers in pathlength cos…
rlhatton Dec 19, 2021
dd9bd43
swimming race code operational for drag-based systems
rlhatton Dec 19, 2021
ccdbe78
Fix optimization bugs for 4+D systems
NathanJustus Jan 6, 2022
d269aaf
Merge pull request #113 from OSU-LRAM/master
rlhatton Jan 6, 2022
3b098b1
committing locomotor_race changes
rlhatton Jan 6, 2022
1a07635
Merge branch 'Ross' of github.com:OSU-LRAM/GeometricSystemPlotter int…
rlhatton Jan 6, 2022
c6cf58e
fixed optimization saving and plotting bugs for 5-dof systems
rlhatton Jan 6, 2022
222a89c
some more fixes for processing 5-dof gaits. Optimizer outputs still s…
rlhatton Jan 7, 2022
9f00997
locomotor race files and direction-constrained optimization are present
rlhatton Jan 13, 2022
0da06e6
added prismatic link support in N_link_chain.m and its support files
rlhatton Mar 9, 2022
5cecebf
added a simplification term to N_link_conversion_move_chain
rlhatton Mar 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# OS generated files #
######################
.DS_Store
Expand All @@ -9,7 +10,7 @@ ehthumbs.db
Thumbs.db

# Sysplotter data and configuration files #
######################
###########################################
sysplotter_config.mat
sysplotter_data

Expand All @@ -22,3 +23,6 @@ UserFiles/GenericUser/Shape_Changes/shchf_params_*
UserFiles/GenericUser/Shape_Changes/opt_*
UserFiles/GenericUser/Shape_Changes/shchf_opt_*

# Generated Files #
###################
exp_deriv.m
139 changes: 139 additions & 0 deletions InertialPurgatory/Inertial_connection_discrete.m.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
function [A, h, J, J_full, omega, M_full, local_inertias] = Inertial_connection_discrete(geometry,physics,jointangles)
% Calculate the local connection for for an inertial system (floating in space or
% ideal high-Re fluid)
%
% Inputs:
%
% geometry: Structure containing information about geometry of chain.
% Fields required for this function are:
%
% linklengths: A vector of link lengths defining a kinematic chain
%
% baseframe (optional): Specification of which link on the body should be
% treated as the base frame. Default behavior is to put the base
% frame at the center of the chain, either at the midpoint of the
% middle link, or at the joint between the two middle links and at
% the mean of their orientation. Options for this field are
% specified in the documentation of N_link_chain.
%
% length (optional): Total length of the chain. If specified, the elements of
% will be scaled such that their sum is equal to L. If this field
% is not provided or is entered as an empty matrix, then the links
% will not be scaled.
%
% link_shape: string naming what kind of object the link is
%
% link_shape_parameters: structure containing parameters of link
% shape
%
% physics: Structure containing information about the system's physics.
% Fields are:
%
% fluid_density: density of fluid surrounding object, relative to
% object
%
% jointangles: Angles of the joints between the links, defining the
% chain's current shape.
%
% Outputs:
%
% A: The "local connection" matrix, or "Locomotion Jacobian". This matrix
% maps joint angular velocities ("shape velocities") to body
% velocities of the system's base frame as
%
% g_b = -A * alphadot
%
% with g_b the body velocity and alphadot the joint angular velocity.
%
% (Note the negative sign in this equation; sysplotter code uses the
% classical formulation of the geometric mechanics equations, which
% includes this negative sign.
%
% [h,J,J_full]: location and Jacobians for the links on the chain. These
% are passed through from N_link_chain; see the documentation on that
% function for more details
%
% omega: The "Pfaffian constraint matrix" from which the local connection
% A is calculated. This matrix is a linear map from system body and
% shape velocities to net external forces acting on the base frame,
% which must be zero for all achievable motions of the system
%
% local_inertias: The inertia tensor of the link as measured in its fixed
% coordinate frame, which includes the added mass from the surrounding
% fluid.


%%%%
% First, get the positions of the links in the chain and their
% Jacobians with respect to the system parameters
<<<<<<< HEAD
[h, J, J_full,~,~] = N_link_chain(geometry,jointangles);
=======
if isfield(geometry,'subchains')
[h, J, J_full] = branched_chain(geometry,jointangles);
else
[h, J, J_full] = N_link_chain(geometry,jointangles);
end
>>>>>>> master

%%%%%%%%
% We are modeling low Reynolds number physics as being resistive
% viscous force, with a quasistatic equilibrium condition that inertial
% forces are negligable, so that the viscous drag on the whole system
% is zero at any given time. (The drag is anisotropic, so the system
% can actually be moving even though there is no net force acting on
% it).
%
% Because viscous drag is linear, we can build a linear map from the
% body velocity of a given link to the force and moment acting on the
% link.
%
% Further, because the velocity kinematics from the system's body and
% shape velocities to the body velocity of each link are linearly
% encoded by the Jacobians of the links, we can use these Jacobians to
% pull the drag operators on the links back onto the space of system
% body and shape velocities, giving us a linear map from the system's
% body and shape velocity to the net forces acting on the system
%
% To calculate this linear mapping, we first pre-allocate storage for
% the metric contributions. Each contribution is 3 x m (rows for
% x,y,theta motion, and one column per joint), and there is one
% contribution per link. This structure is of the same dimensions as
% J_full, so we use it as a template.
link_force_maps = J_full;

% Now iterate over each link, calculating the map from system body and
% shape velocities to forces acting on the body
for idx = 1:numel(link_force_maps)

[link_inertias{idx},local_inertias{idx}] = Inertia_link(h.pos(idx,:),... % Position of this link relative to the base frame
J_full{idx},... % Jacobian from body velocity of base link and shape velocity to body velocity of this link
h.lengths(idx),... % Length of this link
geometry.link_shape{idx},... % Shape type of this link
geometry.link_shape_parameters{idx},... % Shape parametes for this link
physics.fluid_density); % Fluid density relative to link

end

if isa(link_inertias{1},'sym')
M_full = sym(zeros(size(link_inertias{1})));
inertia_stack = cat(3,link_inertias{:});
for i = 1:size(inertia_stack,1)
for j = 1:size(inertia_stack,2)
temp = inertia_stack(i,j,:);
M_full(i,j) = sum(temp(:));
end
end
else
% Sum the force-maps for each link to find the total map from system
% body and shape velocities to force actign on the body
M_full = sum(cat(3,link_inertias{:}),3);
end


% Pfaffian is first three rows of M_full
omega = M_full(1:3,:);

% Build the local connection
A = omega(:,1:3)\omega(:,4:end);
end
148 changes: 148 additions & 0 deletions InertialPurgatory/Inertial_tensors_discrete.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
function [A, M_alpha, J_full, Inertia_link_local, M_full] = Inertial_tensors_discrete(geometry,physics,jointangles)
% Calculate the local connection for for an inertial system (floating in space or
% ideal high-Re fluid)
%
% Inputs:
%
% geometry: Structure containing information about geometry of chain.
% Fields required for this function are:
%
% linklengths: A vector of link lengths defining a kinematic chain
%
% baseframe (optional): Specification of which link on the body should be
% treated as the base frame. Default behavior is to put the base
% frame at the center of the chain, either at the midpoint of the
% middle link, or at the joint between the two middle links and at
% the mean of their orientation. Options for this field are
% specified in the documentation of N_link_chain.
%
% length (optional): Total length of the chain. If specified, the elements of
% will be scaled such that their sum is equal to L. If this field
% is not provided or is entered as an empty matrix, then the links
% will not be scaled.
%
% link_shape: string naming what kind of object the link is
%
% link_shape_parameters: structure containing parameters of link
% shape
%
% physics: Structure containing information about the system's physics.
% Fields are:
%
% fluid_density: density of fluid surrounding object, relative to
% object
%
% jointangles: Angles of the joints between the links, defining the
% chain's current shape.
%
% Outputs:
%
% A: The "local connection" matrix, or "Locomotion Jacobian". This matrix
% maps joint angular velocities ("shape velocities") to body
% velocities of the system's base frame as
%
% g_b = -A * alphadot
%
% with g_b the body velocity and alphadot the joint angular velocity.
%
% (Note the negative sign in this equation; sysplotter code uses the
% classical formulation of the geometric mechanics equations, which
% includes this negative sign.
%
% [h,J,J_full]: location and Jacobians for the links on the chain. These
% are passed through from N_link_chain; see the documentation on that
% function for more details
%
% omega: The "Pfaffian constraint matrix" from which the local connection
% A is calculated. This matrix is a linear map from system body and
% shape velocities to net external forces acting on the base frame,
% which must be zero for all achievable motions of the system
%
% local_inertias: The inertia tensor of the link as measured in its fixed
% coordinate frame, which includes the added mass from the surrounding
% fluid.

%%%%
% First, get the positions of the links in the chain and their
% Jacobians with respect to the system parameters
if isfield(geometry,'subchains')
[h, J, J_full] = branched_chain(geometry,jointangles);
else
[h, J, J_full] = N_link_chain(geometry,jointangles);
end

%If examining inter-panel interaction
if isfield(physics,'interaction')
s.geometry = geometry;
s.physics = physics;

%Then, get added mass metric using flat-plate panel method
[M_full,J,J_full,h,Inertia_link_local] = getAddedMass_NLinkChain(jointangles',s);
else


%%%%%%%%
% We are modeling low Reynolds number physics as being resistive
% viscous force, with a quasistatic equilibrium condition that inertial
% forces are negligable, so that the viscous drag on the whole system
% is zero at any given time. (The drag is anisotropic, so the system
% can actually be moving even though there is no net force acting on
% it).
%
% Because viscous drag is linear, we can build a linear map from the
% body velocity of a given link to the force and moment acting on the
% link.
%
% Further, because the velocity kinematics from the system's body and
% shape velocities to the body velocity of each link are linearly
% encoded by the Jacobians of the links, we can use these Jacobians to
% pull the drag operators on the links back onto the space of system
% body and shape velocities, giving us a linear map from the system's
% body and shape velocity to the net forces acting on the system
%
% To calculate this linear mapping, we first pre-allocate storage for
% the metric contributions. Each contribution is 3 x m (rows for
% x,y,theta motion, and one column per joint), and there is one
% contribution per link. This structure is of the same dimensions as
% J_full, so we use it as a template.
link_force_maps = J_full;

% Now iterate over each link, calculating the map from system body and
% shape velocities to forces acting on the body
Inertia_link_system = cell(size(force_maps));
Inertia_link_local = cell(size(force_maps));
for idx = 1:numel(link_force_maps)

[Inertia_link_system{idx},Inertia_link_local{idx}] = Inertia_link(h.pos(idx,:),... % Position of this link relative to the base frame
J_full{idx},... % Jacobian from body velocity of base link and shape velocity to body velocity of this link
h.lengths(idx),... % Length of this link
geometry.link_shape_parameters{idx},... % Shape parametes for this link
physics.fluid_density); % Fluid density relative to link

end

if isa(Inertia_link_system{1},'sym')
M_full = sym(zeros(size(Inertia_link_system{1})));
inertia_stack = cat(3,Inertia_link_system{:});
for i = 1:size(inertia_stack,1)
for j = 1:size(inertia_stack,2)
temp = inertia_stack(i,j,:);
M_full(i,j) = sum(temp(:));
end
end
else
% Sum the force-maps for each link to find the total map from system
% body and shape velocities to force actign on the body
M_full = sum(cat(3,Inertia_link_system{:}),3);
end
end

% Pfaffian is first three rows of M_full
omega = M_full(1:3,:);

% Build the local connection
A = omega(:,1:3)\omega(:,4:end);

M_alpha = [-A' eye(size(A,2))]*M_full*[-A; eye(size(A,2))];

end
18 changes: 18 additions & 0 deletions InertialPurgatory/calc_partial_mass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function dM_alphadalpha = calc_partial_mass(s,shapelist)
% Inputs:
% s: sysplotter system struct for an inertial system
% shapelist: cell containing n values where each value represents the
% system's shape at which dM_alphadalpha should be calculated
% Outputs:
% dM_alphadalpha: Partial derivative of mass with respect to shape
% variables; cell with n matrices, one for each shape variable

% Preallocate output
dM_alphadalpha = cell(size(shapelist));
% Interpolate in the precalculated dM_alphadalpha grid based on values
% in shapelist
for i = 1:length(shapelist)
dM_alphadalpha{i} = cellfun(@(C) interpn(s.grid.coriolis_eval{:},C,...
shapelist{:},'spline'),s.coriolisfield.coriolis_eval.content.dM_alphadalpha{i});
end
end
18 changes: 18 additions & 0 deletions InertialPurgatory/calc_second_partial_mass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function ddM_alphadalpha = calc_second_partial_mass(s,shapelist)
% Inputs:
% s: sysplotter system struct for an inertial system
% shapelist: cell containing n values where each value represents the
% system's shape at which ddM_alphadalpha should be calculated
% Outputs:
% ddM_alphadalpha: Second partial derivative of mass with respect to shape
% variables; n-by-n cell of n-by-n matrices, one for each shape variable

% Preallocate output
ddM_alphadalpha = cell(length(shapelist));
% Interpolate in the precalculated dM_alphadalpha grid based on values
% in shapelist
for i = 1:numel(ddM_alphadalpha)
ddM_alphadalpha{i} = cellfun(@(C) interpn(s.grid.coriolis_eval{:},C,...
shapelist{:},'spline'),s.coriolisfield.coriolis_eval.content.ddM_alphadalpha{i});
end
end
42 changes: 42 additions & 0 deletions InertialPurgatory/coriolis_eval.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function C = coriolis_eval(M,dMdq,A,jointangles,jointvelocities)
dmdalpha = pull_back_partial_mass(M,dMdq,A,jointangles);
C_from_vel = zeros(size(dmdalpha));
jointvelocities = jointvelocities(:);
if isa(dmdalpha,'sym')
C_from_vel = sym(C_from_vel);
end
C_from_pos = C_from_vel;
for i = 1:numel(jointvelocities)
C_from_vel = C_from_vel + dmdalpha{i}*jointvelocities(i);
C_from_pos(i) = -(1/2)*jointvelocities'*dmdalpha{i}*jointvelocities;
end
C_from_vel = C_from_vel*jointvelocities;
C = C_from_pos + C_from_vel;
if isa(C,'sym')
C = simplify(C,10);
end
end

function dmdalpha = pull_back_partial_mass(M,dMdq,A,jointangles)
dAdalpha = {zeros(size(A))};
num_joints = size(A,2);
dAdalpha = repmat(dAdalpha,1,num_joints);
A_interp = zeros(size(A));
for i = 1:numel(A)
% Need some way to make this number-of-joints-agnostic
[da1,da2] = gradient(A{i});
dA = {da1,da2};
for joint = 1:size(A,2)
dAdalpha{joint}(i) = interpn(X,Y,dA{joint},jointangles(1),jointangles(2));
end
A_interp(i) = interpn(X,Y,A{i},jointangles(1),jointangles(2));
end

dmdalpha = cell(size(A,2),1);
for i = 1:numel(dmdalpha)

dmdalpha{i} = [-dAdalpha{i}', zeros(size(A,2))]*M*[-A_interp; eye(size(A,2))] ...
+ [-A_interp', eye(size(A,2))]*dMdq*[-A_interp; eye(size(A,2))] ...
+ [-A_interp', eye(size(A,2))]*M*[-dAdalpha{i}; zeros(size(A,2))];
end
end
Loading