PDA

View Full Version : Summary of replies: Autolev and Matlab



Max Donelan
05-12-2003, 09:27 AM
Dear Colleagues,

Thank you to all who responded to my question regarding integrating
Autolev and Matlab. Here is that question again:
"I would like to use Autolev to generate equations of motion that I
could integrate easily and efficiently with Matlab. I am aware that
Autolev will generate C or Fortran code for this purpose but, for a
number of reasons, I prefer to do my operations in Matlab/Simulink. Does
anybody have any advice? Solutions for both quick implementation and
fast simulations would be greatly appreciated."


Many people responded immediately and with very similar contributions:
"I will be out of the office from XX/XX/XX through XX/XX/XX returning
on Monday XX/XX/XX. Actually, I may never return. In the unlikely event
that I do, you should rest assured that I will have too many messages to
answer and will likely put your message straight in the trash. You will
be lucky if I even read the subject line."
(My sarcasm is only a thinly-veiled attempt to hide my embarrassment at
getting excited about the response I believed I had generated in the
Biomch-L community. 15 minutes after sending my question I received 20
responses - this had clearly been a question on everyone's mind).

Otherwise, the main bits of information, advice and opinions were
1. Version 4 of Autolev generates Matlab code. (However, it does not
appear to do event handling unless you change the code substantially).
2. It is possible to write a MEX wrapper function to allow Matlab to
call the Autolev C or Fortran code.
3. Cut and paste equations for Autolev C code into Matlab function that
you call with ODE45.M or one of Matlab's other numerical integrators.
4. For speed, do it in C.

Thanks to all who responded to my query. In particular, thank you to
Fran Sheehan and the two Arizona Brians (Brian Umberger and Bryan St.
Laurent) for the multiple emails and useful advice. I have included all
the email responses after my signature.

Sincerely,

Max

J. Maxwell Donelan
Postdoctoral fellow
Centre for Neuroscience
Department of Physiology
University of Alberta
Edmonton, Alberta
Canada T6G 2H7
www.ualberta.ca/~mdonelan/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Joan Deffeyes [mailto:deffeyes@stanford.edu]
> Sent: April 3, 2003 5:01 PM
> To: mdonelan@ualberta.ca
> Subject: Re: [BIOMCH-L] Autolev and Matlab
>
>
> Autolev can also generate Matlab code, at least version 4.0 can - I
> don't know the history of what older versions can do. You might
> check with the folks at Autolev: Info@Autolev.com.
>
> Joan
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Andy Ruina [mailto:ruina@cornell.edu]
> Sent: April 3, 2003 7:24 PM
> To: mdonelan@ualberta.ca
> Subject: Re: [BIOMCH-L] Autolev and Matlab
>
> Hi Max:
>
> a) Quickly implement the ability to use MEX files on your mac
> with C. This is supposed to work, but no-one I know has found
> this easy.
>
> b) ONe person told me they found some "robotics toolbox" some
> place and got simulations going quickly with that in Matlab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Einar S. Idsų [mailto:esi@itk.ntnu.no]
> Sent: April 4, 2003 12:01 AM
> To: mdonelan@ualberta.ca
> Subject: Re: [BIOMCH-L] Autolev and Matlab
>
>
> Dear Dr. Donelan,
>
> I am unfamiliar with Autolev, but have some experience with
> Matlab. If you can obtain automatically generated C or
> Fortran code from Autolev, then it is quite simple to code a
> MEX wrapper-function in C or Fortran for that function which,
> after compilation in Matlab, will be able to execute like any
> other Matlab-function. The bonus is that you will obtain a
> decade or two quicker code execution as compared to regular
> Matlab functions. You can similarly make S-functions for
> Simulink based on C or Fortran code.
>
> You can obtain more info on this from the Matlab
> documentation and Mathworks's website (e.g.
> http://www.mathworks.com/access/helpdesk_r12p1/help/techdoc/ma
> tlab_external/matlab_external.shtml).
>
> However, if the generated equations are relatively simple,
> then it may be just as simple to recode the C or Fortran
> routines in Matlab's own language.
>
> Hope this was helpful.
>
> Cheers,
> Einar S. Idsų
>
> --
> PhD student Dept. of Engineering Cybernetics
> Phone: +47 (735)90243 NTNU
> Mobile: +47 95870764 Odd Bragstads plass 2D
> Room D-352 N-7491 Trondheim, Norway
> esi@itk.ntnu.no
> http://www.itk.ntnu.no/ansatte/Idsoe_Einar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Sheehan, Frances T [mailto:SHEEHAN@cua.edu]
> Sent: April 4, 2003 7:08 AM
> To: 'Max Donelan '
> Subject: RE: [BIOMCH-L] Autolev and Matlab
>
>
> Yes, in Autolev, you can create C-code using the Ouput command.
>
> Basically, whatever variables or functions you would have put
> into the output command can be placed as a simple line
> command. In that way, Autolev will solve for that varialble
> or function and you can use the output equation to create a
> Matlab code.
>
> Autolev also has the express and evaluate commands to help
> you simplify whatever expression or function you are generating.
>
> I hope that helps;
> fran sheehan
> assistant professor
> the catholic university of america
> washington, dc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: buaka paulin [mailto:paulin_buaka@yahoo.com]
> Sent: April 4, 2003 11:23 AM
> To: Max Donelan; Paul Bourassa
> Subject:
>
>
> Dear Max
>
> I received your below through Mr Bourassa my advisor
> during my master's studies. During this master I used
> equation generated by Autolev and made simulation in
> MatLab/Simulink where it was easy for my work to introduce
> algorithms of control. So. to manipulate the equations
> obtained by Autolev in Matlab/Simulink, what I had done it is
> to rewrite all equations in Simulink diagram code. Simulink
> offers advantage to use Matlab function. So the advice I can
> give you is:
>
> 1. If possible rewrite your different equations
> obtained through Autolev such that each acceleration
> will be isolated in one side of equality;
> 2. In the other side of equality, you will find
> functions which contains terms of velocities,
> displacements, forces, torques and others independent
> terms;
> 3. Use functions & tables in simulink which contains
> functions (Fcn), Matlab Fcn or S-functions to combine
> your variables appearing in fucntions in step 2.
>
> I hope, that it will be possible to have a quickly
> simulation response of your system.
> But if you have any question don't hesitate to contact
> me and I will see if I can help you.
>
> So, good luck.
>
> Sincerly
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Alison Sheets [mailto:alsheets@ucdavis.edu]
> Sent: April 6, 2003 9:46 PM
> To: mdonelan@ualberta.ca
> Subject: AutoLEV and Matlab
>
>
> Max,
>
> We have done a fair amount of modeling using AutoLEV in our
> lab at University of California, Davis. My labmates and I
> have found that the easiest thing is just to use the C or
> Fortran output. For a while I simply copied the equations of
> motion created by AutoLEV, then wrote my own integration
> programs using the ODE45 command. I would simply paste in
> the equations from AutoLEV to be integrated. This method
> (although a bit laborious) worked OK. We eventually found
> that the computation time was too long with Matlab, but was
> managable in C.
>
> Let me know if anyone else has any suggestions!
> Alison Sheets
> Sports Biomechanics Laboratory
> University of California, Davis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
-----Original Message-----
From: Bensaci [mailto:wbensaci@yahoo.com]
Sent: April 7, 2003 5:00 AM
To: mdonelan@ualberta.ca
Subject: Re: [BIOMCH-L] Autolev and Matlab


Hi,

try to use the MAPEL software. It is used for resolving equations.

best regards.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Jeff Chu [mailto:jchu@simbex.com]
> Sent: April 7, 2003 6:41 AM
> To: Max Donelan
> Subject: RE: Autolev and Matlab
>
>
> Hi Max:
> This is pretty straightforward, but requires
> manipulation of Autolev generated code. I used the C
> generated version of Autolev (I believe that fortran code
> will work as well) and will require the compiler toolbox. In
> general, you want to convert the C code into a linked library
> (*.dll) using the mex function in the comipler toolbox. Once
> compiled, you can call this library as you would with any
> other function. Specifically, you will need to manipulate
> the main() header in C to something that is mex friendly and
> add a few lines of code to take care of pointer assignments
> (this is pretty straightforward). For more info, go to
> Mathworks website and search for external interfaces/API.
> Hope this helps, please let me know if you have any further questions.
>
> Best regards,
> Jeff Chu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%
> -----Original Message-----
> From: Brian.Umberger@asu.edu [mailto:Brian.Umberger@asu.edu]
> Sent: April 8, 2003 2:29 PM
> To: Bryan; mdonelan@ualberta.ca
> Subject: RE: [BIOMCH-L] Autolev and Matlab
>
>
> Just for the record, option #1 described by Bryan is not a
> problem when implemented under linux or some other unix
> (i.e., a "real" OS that knows how to manage its own memory
> peoperly). But I think that this option is the farthest from
> what Max is looking for anyway.
>
> --Brian
>
>
>
>
> Quoting Bryan :
>
> > Max (and Brian),
> >
> > There are two ways that I have tried to use Autolev and MATLAB in
> > conjunction. First is to compile the Autolev C-code into an
> > executable
> > (*.exe) and bang out (!) from within MATLAB whenever the
> *.exe needs
> > to be run. This works...sort of. What I found after quite
> a bit of
> > work was that
> > Windows 98 SE (the OS I was running at the time) would run more and
> > more
> > slowly with each call to the *.exe until after a few
> thousand calls the
> > OS
> > would stop. I am guessing that this has something to do with how
> > Windows 98
> > SE manages memory or system resources. If you only need to
> bang out a
> > few
> > times (i.e., a couple hundred) this is a very quick and
> easy solution to
> > the
> > problem. This was not good for me as I required a few
> > hundred-thousand
> > calls. So the next option was to compile the Autolev
> C-code as a *.dll
> > and
> > call it from within MATLAB. This takes a little more
> effort but works
> > like
> > a charm.
> >
> > There are two points that I should make. First, I do not
> know if all
> > operating systems will respond in the same fashion as Windows 98 SE
> > did. I now run Windows XP but saw no reason to go back and
> check it
> > out. Second,
> > both of my solutions use the integrator that is coded in the Autolev
> > C-file.
> > If you want to use a different integrator I would take
> Brian's comments
> > into
> > consideration (if I understand him correctly) and code it into the
> > C-file
> > directly and NOT code it into MATLAB. I would not code any
> of the EOM
> > in
> > MATLAB either. My guess is that the *.dll will execute faster (and
> > you
> > don't have to worry about debugging).
> >
> > If you have any questions drop me a line and I'll try to
> help as much
> > as I am able.
> >
> > Bryan
> >
> >
> > -----Original Message-----
> > From: Brian Umberger [mailto:brian.umberger@asu.edu]
> > Sent: Monday, April 07, 2003 4:58 PM
> > To: mdonelan@UALBERTA.CA
> > Cc: Bryan St. Laurent
> > Subject: Re: [BIOMCH-L] Autolev and Matlab
> >
> >
> > Hey Max,
> >
> > Brian Umberger from ASU here. So how's it going? Tired of freezing
> > your butt off in Edmonton yet?
> >
> > We have a master's student (Bryan St. Laurent - he is just
> about done)
> > here in the lab who may be able to help you out a little bit. If I
> > understand what you are asking, then I don't think he did
> exactly what
> > you want, but it was pretty close. At the risk of
> volunteering someone
> > else to help you out, I've copied Bryan on this message to you. You
> > two can take this up if it looks like Bryan might have anything to
> > offer that could be of use to you.
> >
> > As you probably know, there are ways to make the
> integration in Matlab
> > go quicker or slower, but if you are talking about doing the actual
> > integration of the Autolev generated EOM in Matlab, you
> will never be
> > able to touch the speed of using a dedicated subroutine
> complied into
> > the same executable with the EOM. The integrator that Autolev can
> > generate is ok, but I have also interfaced the Autolev code
> with some
> > of the higher quality integrators available on netlib with good
> > results.
> >
> > Gotta go, but just wondering if you will be at ASB in Toledo this
> > year. If so I will see you then. Later,
> >
> > Brian
> >
> > --
> > Brian Umberger
> > Biomechanics Laboratory
> > Arizona State University
> > Tempe, AZ 85287-0404
> > Phone/Fax: 480-965-7528/8108
> > E-mail: brian.umberger@asu.edu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
%%%%%

---------------------------------------------------------------
To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl
For information and archives: http://isb.ri.ccf.org/biomch-l
---------------------------------------------------------------