Skip to content

Commit

Permalink
Initial commit R2017b
Browse files Browse the repository at this point in the history
  • Loading branch information
smiller01985 committed Oct 21, 2019
1 parent ab4046a commit 84830b5
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Optim/obj_sm_four_bar_optim_match_path.m
@@ -1,5 +1,5 @@
function F = obj_sm_four_bar_optim_match_path(mdl,param_v,x_data_des,y_data_des,map_h)
% Objective function to optimize trajectory of four bar linkage
% Objective function to optimize trajectory of four-bar linkage
% Copyright 2017 The MathWorks, Inc.

load_system(mdl);
Expand Down
2 changes: 1 addition & 1 deletion Optim/sm_four_bar_optim_match_path.m
@@ -1,4 +1,4 @@
% Optimization tune four bar linkage to follow a desired trajectory
% Optimization tune four-bar linkage to follow a desired trajectory
% Copyright 2017 MathWorks, Inc.

% Set up model
Expand Down
6 changes: 3 additions & 3 deletions README.txt
@@ -1,9 +1,9 @@
Four Bar Trajectory Optimization
Four-Bar Linkage Optimization
Copyright 2017 The MathWorks, Inc.

Models a four bar linkage in Simscape Multibody. The lengths
Models a four-bar linkage in Simscape Multibody. The lengths
of the links are parameterized using MATLAB variables. Adjusting
those lengths enables the tip of the four bar linkage to follow
those lengths enables the tip of the four-bar linkage to follow
different trajectories. Using optimization algorithms, the
lengths can be automatically tuned so that the tip follows a
desired trajectory.
Expand Down
2 changes: 1 addition & 1 deletion Scripts_Data/sm_four_bar_optim_param_sweep_plot.m
Expand Up @@ -11,7 +11,7 @@
figure(h2_sm_four_bar_optim)
clf(h2_sm_four_bar_optim)
numSims = length(simOut);
title([num2str(numSims) ' Possible Trajectories for Four Bar Linkage'])
title([num2str(numSims) ' Possible Trajectories for Four-Bar Linkage'])
axis equal
grid on
hold on
Expand Down
2 changes: 1 addition & 1 deletion Scripts_Data/sm_four_bar_optim_param_sweep_run.m
@@ -1,4 +1,4 @@
% Parameter sweep for four bar linkage to see possible trajectories
% Parameter sweep for four-bar linkage to see possible trajectories
% Copyright 2017 MathWorks, Inc.

% Fixed lengths
Expand Down
4 changes: 2 additions & 2 deletions Scripts_Data/sm_four_bar_optim_plot1path.m
@@ -1,7 +1,7 @@
% Code to plot simulation results from sm_four_bar_optim
%% Plot Description:
%
% The plot below shows the path of a pointer on the end of a four bar
% The plot below shows the path of a pointer on the end of a four-bar
% linkage. Varying the lengths of the bars will change the trajectory of
% this point.
%
Expand All @@ -28,7 +28,7 @@
% Plot results
plot(xy_pos(:,1),xy_pos(:,2),'LineWidth',1);
axis equal
title('Trajectory of Four Bar Linkage');
title('Trajectory of Four-Bar Linkage');
grid on

% Remove temporary variables
Expand Down
32 changes: 16 additions & 16 deletions html/html/sm_four_bar_optim.html
Expand Up @@ -6,7 +6,7 @@
<!--
This HTML was auto-generated from MATLAB code.
To make changes, update the MATLAB code and republish this document.
--><title>Four Bar Trajectory Optimization</title><meta name="generator" content="MATLAB 9.2"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2017-03-31"><meta name="DC.source" content="sm_four_bar_optim.m"><style type="text/css">
--><title>Four-Bar Linkage Optimization</title><meta name="generator" content="MATLAB 9.3"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2017-09-06"><meta name="DC.source" content="sm_four_bar_optim.m"><style type="text/css">
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}

html { min-height:100%; margin-bottom:1px; }
Expand Down Expand Up @@ -66,49 +66,49 @@



</style></head><body><div class="content"><h1>Four Bar Trajectory Optimization</h1><!--introduction--><p>This examples shows a four bar linkage modeled in Simscape Multibody that is used for an optimization study.</p><p>Mechanical designers often wish to design a four bar linkage that will enable an end effector to follow a certain path. The lengths of the links and the position of the end effector influence the trajectory of the end effector in a complex kinematic relationship. Optimization algorithms can be used to tune those lengths to achieve the desired motion.</p><p>In this example, a parameter sweep is performed to see which trajectories are possible when varying a subset of the lengths. Then those lengths are tuned using optimization algorithms until the resulting trajectory is within tolerances of the desired trajectory.</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#1">Model</a></li><li><a href="#3">Simulation Results from Simscape Logging</a></li><li><a href="#5">Results from Parameter Sweep</a></li><li><a href="#7">Results from Optimization</a></li></ul></div><h2 id="1">Model</h2><img vspace="5" hspace="5" src="sm_four_bar_optim_01.png" style="width:446px;height:369px;" alt=""> <p><img vspace="5" hspace="5" src="sm_four_bar_optim_mechanics_explorer_IMAGE.png" alt=""> </p><h2 id="3">Simulation Results from Simscape Logging</h2><p>The plot below shows the path of a pointer on the end of a four bar linkage. Varying the lengths of the bars will change the trajectory of this point.</p><img vspace="5" hspace="5" src="sm_four_bar_optim_02.png" style="width:560px;height:420px;" alt=""> <h2 id="5">Results from Parameter Sweep</h2><p>Four-bar linkages can be grouped into various cases based on the lengths of their links. See <a href="http://en.wikipedia.org/wiki/File:Linkage_four_bar_fixed.svg">http://en.wikipedia.org/wiki/File:Linkage_four_bar_fixed.svg</a> The resulting trajectories vary quite widely. We will limit the scope of our problem to a crank-rocker mechanism. This means:</p><div><ol><li>Link a (driven link) is the shortest link (a &lt;= min(b,c,d))</li><li>Link b (connecting link) is the longest link (b &gt;= max(a,c,d))</li><li>Link a must be able to rotate 180 degrees (a+b &lt;= c+d)</li></ol></div><img vspace="5" hspace="5" src="sm_four_bar_optim_03.png" style="width:560px;height:420px;" alt=""> <h2 id="7">Results from Optimization</h2><p>Adhering to the same conditions as in the parameter sweep, optimization algorithms are used to find the lengths of Bar A and Bar B that permit the point on the four bar linkage to follow the desired trajectory. Note that the trajectories are translated so that the minimum x and y values of the trajectories are 0. This makes visual inspection of the curves slightly easier.</p><pre class="codeoutput">
</style></head><body><div class="content"><h1>Four-Bar Linkage Optimization</h1><!--introduction--><p>This example shows a four-bar linkage modeled in Simscape Multibody that is optimized using MATLAB.</p><p>Mechanical designers often wish to design a four-bar linkage that will enable an end effector to follow a certain path. The lengths of the links and the position of the end effector influence the trajectory of the end effector in a complex kinematic relationship. Optimization algorithms can be used to tune those lengths to achieve the desired motion.</p><p>In this example, a parameter sweep is performed to see which trajectories are possible when varying a subset of the lengths. Then those lengths are tuned using MATLAB optimization algorithms until the resulting trajectory is within tolerances of the desired trajectory.</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#1">Model</a></li><li><a href="#3">Simulation Results from Simscape Logging</a></li><li><a href="#5">Results from Parameter Sweep</a></li><li><a href="#7">Results from Optimization</a></li></ul></div><h2 id="1">Model</h2><img vspace="5" hspace="5" src="sm_four_bar_optim_01.png" alt=""> <p><img vspace="5" hspace="5" src="sm_four_bar_optim_mechanics_explorer_IMAGE.png" alt=""> </p><h2 id="3">Simulation Results from Simscape Logging</h2><p>The plot below shows the path of a pointer on the end of a four-bar linkage. Varying the lengths of the bars will change the trajectory of this point.</p><img vspace="5" hspace="5" src="sm_four_bar_optim_02.png" alt=""> <h2 id="5">Results from Parameter Sweep</h2><p>Four-bar linkages can be grouped into various cases based on the lengths of their links. See <a href="http://en.wikipedia.org/wiki/File:Linkage_four_bar_fixed.svg">http://en.wikipedia.org/wiki/File:Linkage_four_bar_fixed.svg</a> The resulting trajectories vary quite widely. We will limit the scope of our problem to a crank-rocker mechanism. This means:</p><div><ol><li>Link a (driven link) is the shortest link (a &lt;= min(b,c,d))</li><li>Link b (connecting link) is the longest link (b &gt;= max(a,c,d))</li><li>Link a must be able to rotate 180 degrees (a+b &lt;= c+d)</li></ol></div><img vspace="5" hspace="5" src="sm_four_bar_optim_03.png" alt=""> <h2 id="7">Results from Optimization</h2><p>Adhering to the same conditions as in the parameter sweep, optimization algorithms are used to find the lengths of Bar A and Bar B that permit the point on the four-bar linkage to follow the desired trajectory. Note that the trajectories are translated so that the minimum x and y values of the trajectories are 0. This makes visual inspection of the curves slightly easier.</p><pre class="codeoutput">

Iter Func-count f(x) MeshSize Method
0 1 0.383738 0.215
1 1 0.383738 0.05375 Refine Mesh
2 2 0.00661577 0.1075 Successful Poll
3 2 0.00661577 0.02688 Refine Mesh
3 2 0.00661577 0.02687 Refine Mesh
4 5 0.00272638 0.05375 Successful Poll
5 9 0.000112722 0.1075 Successful Poll
6 11 0.000112722 0.02688 Refine Mesh
6 11 0.000112722 0.02687 Refine Mesh
7 15 2.0582e-05 0.05375 Successful Poll
8 19 2.0582e-05 0.01344 Refine Mesh
9 23 1.67334e-06 0.02688 Successful Poll
9 23 1.67334e-06 0.02687 Successful Poll
10 27 1.67334e-06 0.006719 Refine Mesh
11 31 1.47731e-07 0.01344 Successful Poll
12 35 1.47731e-07 0.003359 Refine Mesh
13 39 1.47731e-07 0.0008398 Refine Mesh
Optimization terminated: mesh size less than options.MeshTolerance.
Elapsed Time = 24.3466
Elapsed Time = 25.6766
Link Initial Final
____ ________ ________

'a' '0.1800' '0.1195'
'b' '0.2500' '0.2651'

</pre><img vspace="5" hspace="5" src="sm_four_bar_optim_04.png" style="width:560px;height:420px;" alt=""> <img vspace="5" hspace="5" src="sm_four_bar_optim_05.png" style="width:560px;height:420px;" alt=""> <img vspace="5" hspace="5" src="sm_four_bar_optim_06.png" style="width:560px;height:420px;" alt=""> <p class="footer">Copyright 2017 The MathWorks, Inc.<br><a href="http://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2017a</a><br></p></div><!--
</pre><img vspace="5" hspace="5" src="sm_four_bar_optim_04.png" alt=""> <img vspace="5" hspace="5" src="sm_four_bar_optim_05.png" alt=""> <img vspace="5" hspace="5" src="sm_four_bar_optim_06.png" alt=""> <p class="footer">Copyright 2017 The MathWorks, Inc.<br><a href="http://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2017b</a><br></p></div><!--
##### SOURCE BEGIN #####
%% Four Bar Trajectory Optimization
%% Four-Bar Linkage Optimization
%
% This examples shows a four bar linkage modeled in Simscape Multibody that
% is used for an optimization study.
% This example shows a four-bar linkage modeled in Simscape Multibody that
% is optimized using MATLAB.
%
% Mechanical designers often wish to design a four bar linkage that will
% Mechanical designers often wish to design a four-bar linkage that will
% enable an end effector to follow a certain path. The lengths of the
% links and the position of the end effector influence the trajectory of
% the end effector in a complex kinematic relationship. Optimization
% algorithms can be used to tune those lengths to achieve the desired
% motion.
%
% In this example, a parameter sweep is performed to see which trajectories
% are possible when varying a subset of the lengths. Then those lengths are
% tuned using optimization algorithms until the resulting trajectory is
% within tolerances of the desired trajectory.
% are possible when varying a subset of the lengths. Then those lengths
% are tuned using MATLAB optimization algorithms until the resulting
% trajectory is within tolerances of the desired trajectory.
%
% Copyright 2017 The MathWorks, Inc.
Expand All @@ -128,7 +128,7 @@
%% Simulation Results from Simscape Logging
%%
%
% The plot below shows the path of a pointer on the end of a four bar
% The plot below shows the path of a pointer on the end of a four-bar
% linkage. Varying the lengths of the bars will change the trajectory of
% this point.
%
Expand Down Expand Up @@ -156,7 +156,7 @@
%
% Adhering to the same conditions as in the parameter sweep, optimization
% algorithms are used to find the lengths of Bar A and Bar B that permit
% the point on the four bar linkage to follow the desired trajectory. Note
% the point on the four-bar linkage to follow the desired trajectory. Note
% that the trajectories are translated so that the minimum x and y values
% of the trajectories are 0. This makes visual inspection of the curves
% slightly easier.
Expand Down
Binary file modified html/html/sm_four_bar_optim.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/html/sm_four_bar_optim_06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions html/sm_four_bar_optim.m
@@ -1,19 +1,19 @@
%% Four Bar Trajectory Optimization
%% Four-Bar Linkage Optimization
%
% This examples shows a four bar linkage modeled in Simscape Multibody that
% is used for an optimization study.
% This example shows a four-bar linkage modeled in Simscape Multibody that
% is optimized using MATLAB.
%
% Mechanical designers often wish to design a four bar linkage that will
% Mechanical designers often wish to design a four-bar linkage that will
% enable an end effector to follow a certain path. The lengths of the
% links and the position of the end effector influence the trajectory of
% the end effector in a complex kinematic relationship. Optimization
% algorithms can be used to tune those lengths to achieve the desired
% motion.
%
% In this example, a parameter sweep is performed to see which trajectories
% are possible when varying a subset of the lengths. Then those lengths are
% tuned using optimization algorithms until the resulting trajectory is
% within tolerances of the desired trajectory.
% are possible when varying a subset of the lengths. Then those lengths
% are tuned using MATLAB optimization algorithms until the resulting
% trajectory is within tolerances of the desired trajectory.
%
% Copyright 2017 The MathWorks, Inc.

Expand All @@ -33,7 +33,7 @@
%% Simulation Results from Simscape Logging
%%
%
% The plot below shows the path of a pointer on the end of a four bar
% The plot below shows the path of a pointer on the end of a four-bar
% linkage. Varying the lengths of the bars will change the trajectory of
% this point.
%
Expand Down Expand Up @@ -61,7 +61,7 @@
%
% Adhering to the same conditions as in the parameter sweep, optimization
% algorithms are used to find the lengths of Bar A and Bar B that permit
% the point on the four bar linkage to follow the desired trajectory. Note
% the point on the four-bar linkage to follow the desired trajectory. Note
% that the trajectories are translated so that the minimum x and y values
% of the trajectories are 0. This makes visual inspection of the curves
% slightly easier.
Expand Down
Binary file modified sm_four_bar_optim.slx
Binary file not shown.

0 comments on commit 84830b5

Please sign in to comment.