FAQ of shapeit
Frequently Asked Questions on installation and use of ShapeIt.
Questions and answers
Before panicking about some error messages that ShapeIt might return, or being disappointed that you can't seem to make ShapeIt work on your pc: take a deep breath, relax, and read the questions on this page. If you recognize one or some of them, I have some good news: the answers are also on this page! So make sure to read those too...
When running shapeit_setup_runonce Matlab returns all kinds of errors and warnings. Should I be worried?
Yes and no. The good news is that as long as somewhere between all error messages there is a message somewhat like
added C:\Program Files\MATLAB\R2010a\toolbox\shapeit to matlab path
the basic functionality of ShapeIt can be used normally. This means it will open, you can load data and start your loopshaping job. So far so good. However, the error messages during installation indicate that the C-files which come with ShapeIt were not compiled correctly. As a consequence the optimization aid (in the full version) will not work, and you cannot use the "Save to Simulink" button. See the question on compiling how to solve this problem. If you didn't get the "added path" message, ShapeIt will not open from outside its directory, which is discussed in the question on the Matlab path.
I can't open ShapeIt. Why does Matlab return "Undefined function or variable" when I type shapeit?
Matlab returns this error since it cannot locate the ShapeIt directory. This means this directory is not properly added to the Matlab path, which should have been done during installation by running shapeit_setup_runonce. Try to run this function again, and see if it returns something like
added C:\Program Files\MATLAB\R2010a\toolbox\shapeit to matlab path
somewhere (or try to use the pathtool routine in Matlab to do this by hand). If it fails, you probably do not have enough rights within Matlab (you're probably using Vista or 7...). See the first part of the question on compiling to solve this.
No, ShapeIt is not broken, and no, you didn't do anything wrong. That is, not now. Something did go wrong during installation of ShapeIt, i.e. the ShapeIt C-files were not compiled. That's why you're now missing the S-functions 'dpd', 'dweakint', 'dleadlag', 'dnotch', 'dlowpass1' and 'dlowpass2'. See the question on compiling for the solution.
Note that ShapeIt itself works perfectly even though you get this error; you're only not able to run the Simulink files that ShapeIt creates (containing so-called DCtools blocks). This shouldn't be a problem though; you know your controller parameters, so you can easily build the controller yourself using the standard Simulink blocks.
The optimization aid doesn't work, as ShapeIt returns error messages. What's going on?
There can be two reasons.
- First, the installation isn't completed as Matlab didn't compile the necessary C-file (in this case costfcn_fast.c). See the question on compiling to solve this.
- Second, you do not have the Genetic Algorithm and Direct Search toolbox installed in Matlab, on which the optimization aid relies. Buy and/or install this toolbox to solve this. There are ideas to replace this toolbox by a free ShapeIt-embedded version somewhere in the far future, but that will probably not help you now...
Remember that ShapeIt can work perfectly without the optimization aid, as it still allows you to use all other functionalities.
Why can't I compile the C-files in the ShapeIt directory?
There can be multiple reasons for this, and they all have to do with your specific Matlab and/or Windows installation. It can be both a matter of rights and the absence of a C-compiler.
You do not have sufficient rights
Compiling (or mexing) C-files produces binary files which are placed inside the ShapeIt directory. This is impossible whenever Windows doesn't allow you to do so. Especially when you're using Windows Vista (or Windows 7) it is very common that Matlab is run without admin-rights, which prevents the creation of files on some parts of your hard disk. Hence, close Matlab, restart it with admin-rights (by right-clicking the Matlab shortcut), go to the ShapeIt directory and run shapeit_setup_runonce again.
You do not have a Matlab-compatible C-compiler
Of course compiling is only possible if you have a suitable compiler. You can identify (and select) the installed compilers by typing mex -setup in Matlab. Normally, any 32-bits Matlab for Windows comes with the Matlab LCC compiler. If you have a different version of Matlab, you probably don't have any and mex -setup will return " None". Possible solutions in that case:
- If you have a Linux installation (either 32-bits or 64-bits) of Matlab: just install the free gcc compiler on your pc (using either a Package Manager or by typing sudo apt-get install gcc in a terminal window), type mex -setup again in Matlab, and then run shapeit_setup_runonce.
- If you have a 64-bits Windows installation: easiest way is to install a 32-bits version of Matlab on your pc and install ShapeIt there. More elegant would be to install a C-compiler on your computer, but good compilers for Windows are often expensive. There are some free alternatives however, which you can find on the MathWorks website. Remember to run mex -setup and shapeit_setup_runonce after installation.
Note that you can check whether compilation went successful by looking for the binary files in your ShapeIt directory. Their extension is either .mexw32 / .mexw64 (32- or 64-bits Windows), .mexglx / .mexa64 (32- or 64-bits Linux) or .mexmaci / .mexmaci64 (32- or 64-bits Macintosh).
Installing / compiling still doesn't work. Am I missing a file simstruc.h?
If you tried everything that is described in the question on compiling, but you still can't seem to compile, you're probably using Windows 7 and a Matlab version older than release 2010bSP1. When you tried to compile or install, Matlab probably returned messages like
fatal error C1083: Cannot open include file: 'simstruc.h': No such file or directory
Could not find include file "simstruc.h".
This may sound very clumsy, but this turns out to be caused by the space in the name of your programs folder: "Program Files". (Actually, it IS clumsy, but you have to blame Microsoft for making such a rookie mistake in their Windows versions...) Instead of removing this space, and thereby messing up all other installed programs, the Mathworks came up with a workaround, which you can read here (you need a MathWorks account to read it). In short:
- Exit Matlab,
- Download a certain zip-file,
- Extract the contents of the zip-file to your Matlab-directory (make sure you have administrator rights to do this).
Restart Matlab, and try to compile again. It should work now.
Installation went perfect! But Matlab still returns weird errors when I try to open ShapeIt. How come?
If typing shapeit in your Matlab command window after successful installation returns errors like
"??? Error: File: C:\Program Files\MATLAB\R2010a\toolbox\shapeit\shapeit.p Line: 534 Column: 13 "identifier" expected, "(" found."
it's time to upgrade your Matlab installation. You're using Matlab 6.5, aren't you? That is so 2003! Read the requirements again: ShapeIt only works for Matlab 7 or higher. Figure handling is done completely different in older versions of Matlab, so ShapeIt will simply not work. Not now, not in future. So upgrade to a newer Matlab. But let's be honest, you should have done that years ago...
Can ShapeIt handle MIMO systems?
No, ShapeIt is designed for SISO loopshaping purposes. You can at most load separate subsystems of your MIMO plant into ShapeIt, but of course this doesn't consider any interaction between the subsystems, which is therefore not very useful to do. If you try to load a MIMO system into ShapeIt it will simply do nothing; it doesn't load your plant (or a part of it), nor does it generate a warning. Hence, be careful there. An error warning will be implemented in a future release.
This export functionality of ShapeIt uses the so-called DCtools controller blockset. The controller blocks in DCtools invoke special C-files included in the ShapeIt installation, which are discrete time approximations of the continuous time controller blocks used in the ShapeIt interface. The discretization is performed using a tustin method with prewarping, based on the sample time provided by your specific Simulink simulation. Since DCtools contains sample based controllers, it can be used in a real-time experiment.
What kind of optimization does ShapeIt use?
The optimization aid uses Genetic algorithms to find the optimum of the controller. This optimum is described by a so-called fitness function or costfunction, which tries to maximize the low-frequent gain and minimize the high-frequent gain, subject to the constraints (bandwidth and margins) defined in the lower left corner of your ShapeIt window. Although Genetic Algorithms are supposed to find global optima, the final solution can still depend on the initial conditions of the optimization. Furthermore, there might still be some small bugs in the efficient C-code implementation of the routine, yielding e.g. a destabilizing controller as optimum. Hence, always analyze your result afterward, and e-mail me if you've found such a bug.