From: Adhika Lie on 3 Feb 2010 20:14 I am building a nonlinear 6DoF aircraft equation of motion using MATLAB and Simulink. So far, I have a function (in M-file) running that would calculate the first derivative of the motion variables (airspeed, AoA and Sideslip, rotation rates, euler angles, and position). I would like to put this function into Simulink for control design (Stability Augmentation System, Autopilot, etc). I found the embedded MATLAB function that I may be able to use to put a user-defined function that takes some input and spits out the derivatives as the output. However, I encountered some problems here. 1. I have also created a script file that generates all the aircraft parameters (geometry, force and moment coefficients) in a structure. I found out that I could not pass this structure into embedded MATLAB function. I have tried using the model explorer and change the input type into "parameters" but I always get an error saying that the data type is not supported. Is there any workaround for this issue without my changing all the variables name? I browsed through MATLAB and Simulink's help and found out that the embedded function works with structure local to the function. However I could not find any reference that tells me how to have structure coming into the function. 2. For my ultimate purpose that is to "embed" my user-defined function into simulink, I wonder is Embedded MATLAB function something that is suitable for this or do you have any better recommendation for this purpose? Thanks a lot!
From: Michael Hosea on 3 Feb 2010 23:34 Seems to work fine for me, although I didn't check it in an official release version. This worked fine function y = fcn(u,s) %#eml y = u + s.a + s.b; Here s is a Parameter (either tunable or not). I defined s in my workspace via >> s = struct('a',13,'b',17) s = a: 13 b: 17 Is it possible that your structure isn't defined properly when you're building the model or isn't really just a structure? What version are you using (because I think support for tunable structure parameters might have been added more recently than non-tunable)? Note that you can always use an extrinsic MATLAB function that fetches data from the workspace (although you can't generate code with RTW in that case). -- Mike "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message news:hkd71g$5d4$1(a)fred.mathworks.com... >I am building a nonlinear 6DoF aircraft equation of motion using MATLAB and >Simulink. > > So far, I have a function (in M-file) running that would calculate the > first derivative of the motion variables (airspeed, AoA and Sideslip, > rotation rates, euler angles, and position). I would like to put this > function into Simulink for control design (Stability Augmentation System, > Autopilot, etc). > I found the embedded MATLAB function that I may be able to use to put a > user-defined function that takes some input and spits out the derivatives > as the output. However, I encountered some problems here. > > 1. I have also created a script file that generates all the aircraft > parameters (geometry, force and moment coefficients) in a structure. I > found out that I could not pass this structure into embedded MATLAB > function. I have tried using the model explorer and change the input type > into "parameters" but I always get an error saying that the data type is > not supported. Is there any workaround for this issue without my changing > all the variables name? > > I browsed through MATLAB and Simulink's help and found out that the > embedded function works with structure local to the function. However I > could not find any reference that tells me how to have structure coming > into the function. > > 2. For my ultimate purpose that is to "embed" my user-defined function > into simulink, I wonder is Embedded MATLAB function something that is > suitable for this or do you have any better recommendation for this > purpose? > > Thanks a lot!
From: Adhika Lie on 3 Feb 2010 23:56 Hi Michael, I use MATLAB R2007a and the Simulink that came with it. I have done exactly like you did but it did not work out for me. I definte the structure the way you did, from both the MATLAB command line and from Model Workspace -> Model Workspace -> From M file and then I type the command to generate the structure. But when I run the simulink, I always get the error message: Parameter s (#126) has a value of an unsupported type Adhika "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message <hkdinp$lc9$1(a)fred.mathworks.com>... > Seems to work fine for me, although I didn't check it in an official release > version. This worked fine > > function y = fcn(u,s) > > %#eml > > > y = u + s.a + s.b; > > Here s is a Parameter (either tunable or not). I defined s in my workspace > via > > >> s = struct('a',13,'b',17) > s = > a: 13 > b: 17 > > Is it possible that your structure isn't defined properly when you're > building the model or isn't really just a structure? What version are you > using (because I think support for tunable structure parameters might have > been added more recently than non-tunable)? Note that you can always use an > extrinsic MATLAB function that fetches data from the workspace (although you > can't generate code with RTW in that case). > > -- > > Mike > > > > "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message > news:hkd71g$5d4$1(a)fred.mathworks.com... > >I am building a nonlinear 6DoF aircraft equation of motion using MATLAB and > >Simulink. > > > > So far, I have a function (in M-file) running that would calculate the > > first derivative of the motion variables (airspeed, AoA and Sideslip, > > rotation rates, euler angles, and position). I would like to put this > > function into Simulink for control design (Stability Augmentation System, > > Autopilot, etc). > > I found the embedded MATLAB function that I may be able to use to put a > > user-defined function that takes some input and spits out the derivatives > > as the output. However, I encountered some problems here. > > > > 1. I have also created a script file that generates all the aircraft > > parameters (geometry, force and moment coefficients) in a structure. I > > found out that I could not pass this structure into embedded MATLAB > > function. I have tried using the model explorer and change the input type > > into "parameters" but I always get an error saying that the data type is > > not supported. Is there any workaround for this issue without my changing > > all the variables name? > > > > I browsed through MATLAB and Simulink's help and found out that the > > embedded function works with structure local to the function. However I > > could not find any reference that tells me how to have structure coming > > into the function. > > > > 2. For my ultimate purpose that is to "embed" my user-defined function > > into simulink, I wonder is Embedded MATLAB function something that is > > suitable for this or do you have any better recommendation for this > > purpose? > > > > Thanks a lot! >
From: Michael Hosea on 4 Feb 2010 04:20 I think support for structure parameters was added in 2008a. -- Mike "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message news:hkdk12$bsk$1(a)fred.mathworks.com... > Hi Michael, > > I use MATLAB R2007a and the Simulink that came with it. > I have done exactly like you did but it did not work out for me. > I definte the structure the way you did, from both the MATLAB command line > and from Model Workspace -> Model Workspace -> From M file and then I type > the command to generate the structure. > > But when I run the simulink, I always get the error message: > Parameter s (#126) has a value of an unsupported type > > > Adhika > > "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message > <hkdinp$lc9$1(a)fred.mathworks.com>... >> Seems to work fine for me, although I didn't check it in an official >> release version. This worked fine >> >> function y = fcn(u,s) >> >> %#eml >> >> >> y = u + s.a + s.b; >> >> Here s is a Parameter (either tunable or not). I defined s in my >> workspace via >> >> >> s = struct('a',13,'b',17) >> s = >> a: 13 >> b: 17 >> >> Is it possible that your structure isn't defined properly when you're >> building the model or isn't really just a structure? What version are >> you using (because I think support for tunable structure parameters might >> have been added more recently than non-tunable)? Note that you can >> always use an extrinsic MATLAB function that fetches data from the >> workspace (although you can't generate code with RTW in that case). >> >> -- >> >> Mike >> >> >> >> "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message >> news:hkd71g$5d4$1(a)fred.mathworks.com... >> >I am building a nonlinear 6DoF aircraft equation of motion using MATLAB >> >and Simulink. >> > >> > So far, I have a function (in M-file) running that would calculate the >> > first derivative of the motion variables (airspeed, AoA and Sideslip, >> > rotation rates, euler angles, and position). I would like to put this >> > function into Simulink for control design (Stability Augmentation >> > System, Autopilot, etc). >> > I found the embedded MATLAB function that I may be able to use to put a >> > user-defined function that takes some input and spits out the >> > derivatives as the output. However, I encountered some problems here. >> > >> > 1. I have also created a script file that generates all the aircraft >> > parameters (geometry, force and moment coefficients) in a structure. I >> > found out that I could not pass this structure into embedded MATLAB >> > function. I have tried using the model explorer and change the input >> > type into "parameters" but I always get an error saying that the data >> > type is not supported. Is there any workaround for this issue without >> > my changing all the variables name? >> > >> > I browsed through MATLAB and Simulink's help and found out that the >> > embedded function works with structure local to the function. However I >> > could not find any reference that tells me how to have structure coming >> > into the function. >> > >> > 2. For my ultimate purpose that is to "embed" my user-defined function >> > into simulink, I wonder is Embedded MATLAB function something that is >> > suitable for this or do you have any better recommendation for this >> > purpose? >> > >> > Thanks a lot! >>
From: Adhika Lie on 4 Feb 2010 06:29
Mike, Thank you so much. Do you know any possible work around for this other than changing the whole variable name? Adhika "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message <hke3hh$okp$1(a)fred.mathworks.com>... > I think support for structure parameters was added in 2008a. > -- > Mike > > "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message > news:hkdk12$bsk$1(a)fred.mathworks.com... > > Hi Michael, > > > > I use MATLAB R2007a and the Simulink that came with it. > > I have done exactly like you did but it did not work out for me. > > I definte the structure the way you did, from both the MATLAB command line > > and from Model Workspace -> Model Workspace -> From M file and then I type > > the command to generate the structure. > > > > But when I run the simulink, I always get the error message: > > Parameter s (#126) has a value of an unsupported type > > > > > > Adhika > > > > "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message > > <hkdinp$lc9$1(a)fred.mathworks.com>... > >> Seems to work fine for me, although I didn't check it in an official > >> release version. This worked fine > >> > >> function y = fcn(u,s) > >> > >> %#eml > >> > >> > >> y = u + s.a + s.b; > >> > >> Here s is a Parameter (either tunable or not). I defined s in my > >> workspace via > >> > >> >> s = struct('a',13,'b',17) > >> s = > >> a: 13 > >> b: 17 > >> > >> Is it possible that your structure isn't defined properly when you're > >> building the model or isn't really just a structure? What version are > >> you using (because I think support for tunable structure parameters might > >> have been added more recently than non-tunable)? Note that you can > >> always use an extrinsic MATLAB function that fetches data from the > >> workspace (although you can't generate code with RTW in that case). > >> > >> -- > >> > >> Mike > >> > >> > >> > >> "Adhika Lie" <adhika.lee(a)gmail.com> wrote in message > >> news:hkd71g$5d4$1(a)fred.mathworks.com... > >> >I am building a nonlinear 6DoF aircraft equation of motion using MATLAB > >> >and Simulink. > >> > > >> > So far, I have a function (in M-file) running that would calculate the > >> > first derivative of the motion variables (airspeed, AoA and Sideslip, > >> > rotation rates, euler angles, and position). I would like to put this > >> > function into Simulink for control design (Stability Augmentation > >> > System, Autopilot, etc). > >> > I found the embedded MATLAB function that I may be able to use to put a > >> > user-defined function that takes some input and spits out the > >> > derivatives as the output. However, I encountered some problems here. > >> > > >> > 1. I have also created a script file that generates all the aircraft > >> > parameters (geometry, force and moment coefficients) in a structure. I > >> > found out that I could not pass this structure into embedded MATLAB > >> > function. I have tried using the model explorer and change the input > >> > type into "parameters" but I always get an error saying that the data > >> > type is not supported. Is there any workaround for this issue without > >> > my changing all the variables name? > >> > > >> > I browsed through MATLAB and Simulink's help and found out that the > >> > embedded function works with structure local to the function. However I > >> > could not find any reference that tells me how to have structure coming > >> > into the function. > >> > > >> > 2. For my ultimate purpose that is to "embed" my user-defined function > >> > into simulink, I wonder is Embedded MATLAB function something that is > >> > suitable for this or do you have any better recommendation for this > >> > purpose? > >> > > >> > Thanks a lot! > >> > |