By Eng / Samer Elsawy
بســـــم هللا الرحمن الرحــيم Here, I will show you how to interface Matlab Simulink with SolidWorks. The big advantage of interfacing Matlab with Solidworks is that Matlab can simulates the dynamics of the mechanical models. At the end of this slides you will find it is very easy to design an assembly in SolidWorks and animate it using Matlab. We will start from scratch in a simple manner, and I will show you how to do it step by step. Firstly, you have to be familiar with Matlab Simulink and SolidWorks. Notes:
Your Matlab version must be at least 2008 or higher.
It doesn’t matter that Matlab an SolidWorks have the same versions, (i.e. you can use Matlab 2014 with SolidWorks 2012).
The First Of All First of all, you have to install the SimMechanics link in Matlab.
SimMechanics Link : Is the link between Matlab and SolidWorks, so you can import SolidWorks assemblies to Matlab. You can SimMechanics Links from Mathworks website. (Note : you must have an on Mathworks to be able to SimMechanics link).
Steps 1. Go to (http://www.mathworks.com/), and make . 2. Go to https://www.mathworks.com/products/simmechanics/_s mlink.html You will find at the end of the page (Enter your information to continue), so enter your Email and press continue. 3. After that, you will find all SimMechanics links for all Matlab versions(from Matlab2008a to Matlab2015a). 4. Choose your Matlab version, you will two files (smlink.r2014b.win32 , install_addon.m) (Note: you will choose your platform first(Win32 (PC) Platform , Win64 (PC) Platform , UNIX (64-bit Linux) , Mac OS X (64-bit Intel)).
5. these two file in somewhere in you hard desk. 6. Open your Matlab(as ). 7. Change Matlab Current Directory to the directory where you ed the files. 8. At the MATLAB command line, enter: install_addon('
.zip') - Replacing
with the name of the zip file that you ed (e.g., smlink.r2014b.win64.zip). The command extracts the zip archive files to the MATLAB root directory. - This will take several minutes. 9. Enable the Plug-In Once you have ed and installed the SimMechanics Link plug-in, you must enable it on your SolidWorks application: - At the MATLAB® command prompt, enter smlink_linksw. - Start SolidWorks. - In the Tools menu, select Add-Ins.
- In the Add-Ins dialog box, select the SimMechanics Link check box. A SimMechanics Link menu appears in the SolidWorks menu bar when you start or open a CAD assembly.
NOW You are ready to import your SolidWorks assembly to Matlab, the process will be like this: 1- Open your Solidworks assembly, from toolbar select(SimMechanics Link > Export > SimMechanics first generation ) 2- Open your Matlab, and change the current directory to the folder where you exported the SimMechanics files. 3- In the Matlab command line type the following: mech_import('the name of the file.xml'), and press “Enter”. (Note: you just type the name of the xml file only). 4- Matlab will create the Simulink model automatically, and if you run this model you will find your model animates according to it’s dynamics. 5- Now, you can put forces and torques on ts to achieve the desired motion.
Now, I will show you a simple example on this :
Let us assume we have a Robot arm of two links, and we desire to control it using Matlab Simulink. After we generate SimMechanics files and import them to Matlab, Matlab will generate the Simulink model.
This model is automatically generated by Matlab. If we click (Run) we can see the dynamic behavior of the model.
But, how we can control our model ? We can control our model using actuators (to apply a force or motion on the body or the t) and sensor(to measure the motion of the body or the t). We can use sensors in the control system to get a from the system to the controller. But, before we will talking about how to use them, let us talk first about ts in Simulink. The most two common ts are: - Prismatic
- Revolute
You can find them in : Simulink > Simscape > SimMechanics > First Generation. To imagine this, simply we can represent the previous mechanism in Simulink like that :
Note: You can use “Help” to know the function of every block in the diagram.
Adding actuators and sensors: We can apply a force or motion on a t, and we can also add a sensor to t to estimate the motion of the t (distance or angle). To do that, we must add terminals to the t by double click on the t block and increase the number of terminals.
Let us say we want to add actuator and sensor to the t, this will be like this:
The yellow block is the desired force or motion that we want to apply on the t, it may be a constant value or sine wave or anything we want. We can choose the type of input(motion or force) from the t actuator block.
Note: In case that we choose Motion, the input to the “t Actuator” block must be three dimensional array input(because we can revolute about X or Y or Z axis). So, in this case we will do something like this:
Back to our example After I had generate the Simulink model and add forces and sensors on the ts, the final model :
Here, I applied a Sine wave motion on the two ts, so we can see the two links rotate in a Sine motion(tilting motion), and also added sensors on the two ts to see the outputs on the scopes. You can use this method to simulate control systems such as Inverted Pendulum system, I tried it and that was cool . Hope that was helpful for you, any questions you can me on: https://www.facebook.com/samer.elsawy
والسالم عليكم و رحمة هللا وبركاته