Sie sind auf Seite 1von 9

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 doesnt 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 download SimMechanics Links from Mathworks website.

(Note : you must have an account on Mathworks to be able to download


SimMechanics link).
Steps
1. Go to (http://www.mathworks.com/), and make login.
2. Go to
https://www.mathworks.com/products/simmechanics/download_s
mlink.html
You will find at the end of the page (Enter your contact 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 download 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. Download these two file in somewhere in you hard desk.


6. Open your Matlab(as administrator).
7. Change Matlab Current Directory to the directory where you
downloaded the files.
8. At the MATLAB command line, enter:
install_addon('<zip_file_name>.zip')
- Replacing <zip_file_name> with the name of the zip file that you
downloaded (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 downloaded 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 its
dynamics.

5- Now, you can put forces and torques on joints 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 joint) and sensor(to measure the motion of the body or the
joint).

We can use sensors in the control system to get a feedback from the
system to the controller.

But, before we will talking about how to use them, let us talk first about
joints in Simulink.

The most two common joints 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 joint, and we can also add a sensor to
joint to estimate the motion of the joint (distance or angle).

To do that, we must add terminals to the joint by double click on the joint
block and increase the number of terminals.

Let us say we want to add actuator and sensor to the joint, this will be like
this:
The yellow block is the desired force or motion that we want to apply on
the joint, 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 joint actuator
block.

Note:

In case that we choose Motion, the input to the Joint 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
joints, the final model :

Here, I applied a Sine wave motion on the two joints, so we can see the two
links rotate in a Sine motion(tilting motion), and also added sensors on the
two joints 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 contact me on:

https://www.facebook.com/samer.elsawy

Das könnte Ihnen auch gefallen