Skip to content

Commit

Permalink
Added DEM example with ThreeParticle/CAE
Browse files Browse the repository at this point in the history
  • Loading branch information
smiller01985 committed May 5, 2023
1 parent b46c993 commit 331aafe
Show file tree
Hide file tree
Showing 77 changed files with 39,360 additions and 0 deletions.
Binary file not shown.
6,055 changes: 6,055 additions & 0 deletions Models/Cosim/B3D_Bucket/Models_B3D/Bucket_Box.inp

Large diffs are not rendered by default.

14,380 changes: 14,380 additions & 0 deletions Models/Cosim/B3D_Bucket/Models_B3D/Bucket_Dig_Cycle.inp

Large diffs are not rendered by default.

14,382 changes: 14,382 additions & 0 deletions Models/Cosim/B3D_Bucket/Models_B3D/Bucket_Dig_Cycle_cohesive.inp

Large diffs are not rendered by default.

4,091 changes: 4,091 additions & 0 deletions Models/Cosim/B3D_Bucket/Models_B3D/Bucket_Dig_Cycle_rocks.inp

Large diffs are not rendered by default.

Binary file added Models/Cosim/B3D_Bucket/Models_SLX/B3D_lib.slx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
% Code to plot simulation results from Excavator_Motion
%% Plot Description:
%
% The plot below shows the force required of the actuators to complete the test.

% Copyright 2016-2023 The MathWorks, Inc.

% Generate new simulation results if they don't exist or if they need to be updated
%if ~exist('simlog', 'var'))
% sim('Excavator_Motion')
% % Model StopFcn callback adds a timestamp to the Simscape simulation data log
%end


% Get simulation results
simlog_DEMLoads_f = simOut.logsout_Excavator_Motion_B3D.get('DEMLoads_f');
simlog_DEMLoads_m = simOut.logsout_Excavator_Motion_B3D.get('DEMLoads_m');

% Reuse figure if it exists, else create new figure
if ~exist('h1_Excavator_B3D_DEM', 'var') || ...
~isgraphics(h1_Excavator_B3D_DEM, 'figure')
h1_Excavator_B3D_DEM = figure('Name', 'Excavator_B3D_DEM');
end
figure(h1_Excavator_B3D_DEM)
clf(h1_Excavator_B3D_DEM)

temp_colororder = get(gca,'defaultAxesColorOrder');

% Plot results
simlog_handles(1) = subplot(2, 1, 1);
plot(simlog_DEMLoads_f.Values.Time, squeeze(simlog_DEMLoads_f.Values.Data(:,1)),...
'LineWidth', 1,'DisplayName','Lateral');
hold on
plot(simlog_DEMLoads_f.Values.Time, squeeze(simlog_DEMLoads_f.Values.Data(:,2)),...
'LineWidth', 1,'DisplayName','Longitudinal');
plot(simlog_DEMLoads_f.Values.Time, squeeze(simlog_DEMLoads_f.Values.Data(:,3)),...
'LineWidth', 1,'DisplayName','Vertical');
hold off
grid on
title('DEM Loads on Bucket CG')
ylabel('Force (N)')
legend('Location','Best')

simlog_handles(2) = subplot(2, 1, 2);
plot(simlog_DEMLoads_m.Values.Time, squeeze(simlog_DEMLoads_m.Values.Data(:,1)),...
'LineWidth', 1,'DisplayName','Global X');
hold on
plot(simlog_DEMLoads_m.Values.Time, squeeze(simlog_DEMLoads_m.Values.Data(:,2)),...
'LineWidth', 1,'DisplayName','Global Y');
plot(simlog_DEMLoads_m.Values.Time, squeeze(simlog_DEMLoads_m.Values.Data(:,3)),...
'LineWidth', 1,'DisplayName','Global Z');
hold off
grid on
ylabel('Moment (N*m)')
xlabel('Time (s)')
linkaxes(simlog_handles,'x')
legend('Location','Best')

% Remove temporary variables
clear simlog_t simlog_handles temp_colororder
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions Models/Cosim/B3D_Bucket/Overview/Excavator_Motion_B3D.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
%% Excavator Design with Simscape(TM): Model Soil Loads
%
% <<Excavator_Motion_B3D_Overview.png>>
%
% (<matlab:web('Excavator_Design_Overview.html') return to Excavator Design Overview>)
%
% This example models an excavator acting against soil loads modeled using
% discrete element modeling in ThreeParticle/CAE(TM) software. The motion of the
% actuators is prescribed, and the simulation calculates the amount of force
% or torque required to execute the motion. Cosimulation is used to
% connect the Simscape Multibody model to ThreeParticle/CAE(TM).
%
% *If you have downloaded the correct release from GitHub*, you can follow
% the steps below to set up cosimulation on your machine. All of the files
% you need to set up the cosimulation are provided in a specific release
% you must obtain from the <https://github.com/simscape/Excavator-Simscape
% GitHub repository>. You will also need <https://www.becker3d.com/
% ThreeParticle/CAE(TM) software> R6.1 and API version 3.1.1 which you can
% obtain in a trial license from BECKER 3D.
%
% Note that the compiled files provided will only work with MATLAB R2023a
% on a Windows 64-bit operating system. To set up this example for other
% versions or operating systems, please contact the authors of this
% submission on the MATLAB Central File Exchange. We worked with
% <https://simutopia.com/ Simutopia(R)> to create this example.
%
% <matlab:try,open_system('Excavator_Motion_B3D'),catch,warning('Model%20Excavator_Motion_B3D.slx%20not%20found.%20Please%20obtain%20the%20correct%20release%20from%20GitHub.'),end Open Excavator with
% ThreeParticle DEM Soil Loads Model>
%
% Copyright 2022-2023 The MathWorks, Inc.

%% Cosimulation Setup
%
% (Note: the compiled files will only work with MATLAB R2023a on a Windows
% 64 bit operating system.)
%
% *1. Copy |\Models\Cosim\util_zmq\zmqdll\libzmq-v143-mt-4_3_5.dll| to the
% "Bin" subfolder within your ThreeParticle installation directory.*
%
% <<Excavator_Motion_B3D_CopyZMQDLL.png>>
%
% *2. Copy |\Models\Cosim\B3D_Bucket\CosimDLL\API_CoSimulation.dll| to the
% |"Bin\API"| subfolder within your ThreeParticle installation directory.*
%
% <<Excavator_Motion_B3D_CopyAPICosimDLL.png>>
%
% *3. Open ThreeParticle/CAE(TM) Software*
%
% *4. Import keyword file
% |\Models\Cosim\B3D_Bucket\Models_B3D\Bucket_Dig_Cycle.inp|*
%
% <<Excavator_Motion_B3D_LoadBucketDigCycle.png>>
%
% *5. In MATLAB, open Simulink model Excavator_Motion_B3D.slx*
%
% *6. Start the simulation in ThreeParticle/CAE(TM) software*
%
% <<Excavator_Motion_B3D_StartThreeParticleSim.png>>
%
% *7. Start the simulation in Simulink*
%
% <<Excavator_Motion_B3D_StartSimulinkSim.png>>
%
% *8. Monitor the progress in animation*
%
% <<Excavator_Motion_B3D_ProgressAnimation.png>>


%% Model
open_system('Excavator_Motion_B3D')
ann_h = find_system('Excavator_Motion_B3D','MatchFilter',@Simulink.match.allVariants,'FindAll', 'on','type','annotation','Tag','ModelFeatures');
for i=1:length(ann_h)
set_param(ann_h(i),'Interpreter','off');
end

%% Excavator Machine Subsystem
%
% <matlab:open_system('Excavator_Motion_B3D');open_system('Excavator_Motion_B3D/Excavator/Machine','force'); Open Subsystem>

set_param('Excavator_Motion_B3D/Excavator/Machine','LinkStatus','none')
open_system('Excavator_Motion_B3D/Excavator/Machine','force')

%% DEM Loads Subsystem
%
% <matlab:open_system('Excavator_Motion_B3D');open_system('Excavator_Motion_B3D/DEM%20Loads','force'); Open Subsystem>

set_param('Excavator_Motion_B3D/DEM Loads','LinkStatus','none')
open_system('Excavator_Motion_B3D/DEM Loads','force')


%% Dig Test
%
% The simulation actuates the excavator arm to dig the bucket into the bed
% of particles which models the soil. The soil loads are plotted below.
%
% <<Excavator_Motion_B3D_results_soil_loads.png>>



%%

%clear all
close all
bdclose all

Binary file not shown.
42 changes: 42 additions & 0 deletions Models/Cosim/util_zmq/addZMQDLLtoSysPath.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function success = addZMQDLLtoSysPath(varargin)

% Defaults
showResult = 0;
success = 0;

% Check for caller inputs
if(nargin>0)
showResult = varargin{1};
end

%% Add the ZMQ DLL to the system path:
p = simulinkproject;
if strcmp(mexext,'mexw64')
zmqdll_list = dir([p.RootFolder '/**/util_zmq/zmqdll/libzmq*.dll']);
if(length(zmqdll_list)==1)
%if exist(fullfile(p.RootFolder,'Models','Cosim','zmq','libzmq','bin','x64','bin','Release','libzmq-v143-mt-4_3_5.dll'),'file')
pathEnvVar = getenv('PATH');
pathcheck = strfind(pathEnvVar,zmqdll_list.folder);
if(isempty(pathcheck))
setenv('PATH',[pathEnvVar ';' zmqdll_list.folder]);
success = 1;
msg = sprintf('%s\n%s','libzmq DLL added to system PATH:',[zmqdll_list.folder filesep zmqdll_list.name]);
else
success = 1;
msg = sprintf('%s\n%s','libzmq DLL already on system PATH:',[zmqdll_list.folder]);
end
elseif(length(zmqdll_list)>1)
success = 0;
msg = ['ZMQ library not added to path. There were ' length(zmqdll_list') ' libzmq DLLs found in subfolders.'];
elseif(isempty(zmqdll_list))
msg = 'ZMQ library not found.';
end
else
success = 0;
msg = 'Non-Windows OS, please add the ZMQ library to your PATH environment variable manually';
end

if(showResult)
disp(msg)
end

Binary file not shown.
37 changes: 37 additions & 0 deletions Scripts_Data/initializeBoxDimensions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
% This script initializes dimensions for the pick-up and dump boxes that
% contain the DEM elements used for the cosimulation example model -
% Excavator_Motion_DEMCosim.slx

% Box outer wall dimensions
boxOuterSurfaceLength = 6; % [m]
boxOuterSurfaceWidth = 9; % [m]
boxThickness = 0.1; % [m]
boxHeight = 3; % [m]

% box inner wall length, width
boxInnerSurfaceLength = boxOuterSurfaceLength-2*boxThickness;
boxInnerSurfaceWidth = boxOuterSurfaceWidth-2*boxThickness;

% create cross-section for the box that is used within the extrude block
% Each row represents a coordinate frame.
% The order of the coordinate frames is such that we start with the outer
% surface and close the loop and then for the inner surface, follow the
% order (start with the closest point with the nearest outer surface point)
% and go in CW direction (that way the left side always represents the
% solid)
boxCrossSectionCoords = [-boxOuterSurfaceLength/2 boxOuterSurfaceWidth/2;
-boxOuterSurfaceLength/2 -boxOuterSurfaceWidth/2;
boxOuterSurfaceLength/2 -boxOuterSurfaceWidth/2;
boxOuterSurfaceLength/2 boxOuterSurfaceWidth/2;
-boxOuterSurfaceLength/2 boxOuterSurfaceWidth/2;
-boxOuterSurfaceLength/2 -boxOuterSurfaceWidth/2+boxThickness;
-boxOuterSurfaceLength/2+boxThickness -boxOuterSurfaceWidth/2+boxThickness;
-boxOuterSurfaceLength/2+boxThickness boxOuterSurfaceWidth/2-boxThickness;
boxOuterSurfaceLength/2-boxThickness boxOuterSurfaceWidth/2-boxThickness;
boxOuterSurfaceLength/2-boxThickness -boxOuterSurfaceWidth/2+boxThickness;
-boxOuterSurfaceLength/2 -boxOuterSurfaceWidth/2+boxThickness];





Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="API_CoSimulation.dll" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="1" type="DIR_SIGNIFIER"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info Ref="Models/Cosim/B3D_Bucket/Models_SLX" Type="Relative"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="b203dfa0-65fc-4f25-8382-5e5f6cbae3ff" type="Reference"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info Ref="Models/Cosim/sfun1part" Type="Relative"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="4ed9ea98-9481-429b-a2e0-a3550e031eaa" type="Reference"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info Ref="Models/Cosim/util_zmq" Type="Relative"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="af1921e4-c0d3-4626-8585-61715e9972b8" type="Reference"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info Type="Basic" GroupUUID="41c320d7-88cb-499c-99fe-a384464b2df6" Visible="1" Icon="" File="Models/Cosim/B3D_Bucket/Models_SLX/Excavator_Motion_B3D.slx" Name="2. Excavator DEM"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="83bc32e2-f4ec-4c85-ba67-f67357c18028" type="EntryPoint"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="addZMQDLLtoSysPath.m" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="zmqdll" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="1" type="DIR_SIGNIFIER"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="CosimDLL" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="Models_B3D" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="Models_SLX" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="libzmq-v143-mt-4_3_5.dll" type="File"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="1" type="DIR_SIGNIFIER"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="5f33d7fa-03ab-41f0-a6df-db1a57eec8f6"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="util_zmq" type="File"/>
Loading

0 comments on commit 331aafe

Please sign in to comment.