Input equations into Matlab for Simulink Function











up vote
0
down vote

favorite












I am currently working on an assignment where I need to create two different controllers in Matlab/Simulink for a robotic exoskeleton leg. The idea behind this is to compare both of them and see which controller is better at assisting a human wearing it. I am having a lot of trouble putting specific equations into a Matlab function block to then run in Simulink to get results for an AFO (adaptive frequency oscillator). The link has the equations I'm trying to put in and the following is the code I have so far:



    function [pos_AFO, vel_AFO, acc_AFO, offset, omega, phi, ampl, phi1] = LHip(theta, eps, nu, dt, AFO_on)
t = 0;
% syms j
% M = 6;
% j = sym('j', [1 M]);

if t == 0
omega = 3*pi/2;
theta = 0;
phi = pi/2;
ampl = 0;
else
omega = omega*(t-1) + dt*(eps*offset*cos(phi1));
theta = theta*(t-1) + dt*(nu*offset);
phi = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
phi1 = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
ampl = ampl*(t-1) + dt*(nu*offset*sin(phi));
offset = theta - theta*(t-1) - sym(ampl*sin(phi), [1 M]);
end

pos_AFO = (theta*(t-1) + symsum(ampl*(t-1)*sin(phi* (t-1))))*AFO_on; %symsum needs input arguement for index M and range
vel_AFO = diff(pos_AFO)*AFO_on;
acc_AFO = diff(vel_AFO)*AFO_on;
end


https://www.pastepic.xyz/image/pg4mP



Essentially, I don't know how to do the subscripts, sigma, or the (t+1) function. Any help is appreciated as this is due next week










share|improve this question
























  • Welcome to StackOverflow. Unfortunately, the posted link does not work
    – Michael C.
    Nov 22 at 0:08












  • My bad I thought it would work. It should hopefully work now
    – Sam A
    Nov 22 at 2:42










  • You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
    – SRhm
    Nov 22 at 2:54










  • How would I use the previous values? What line of code or function would let that happen?
    – Sam A
    Nov 22 at 3:41















up vote
0
down vote

favorite












I am currently working on an assignment where I need to create two different controllers in Matlab/Simulink for a robotic exoskeleton leg. The idea behind this is to compare both of them and see which controller is better at assisting a human wearing it. I am having a lot of trouble putting specific equations into a Matlab function block to then run in Simulink to get results for an AFO (adaptive frequency oscillator). The link has the equations I'm trying to put in and the following is the code I have so far:



    function [pos_AFO, vel_AFO, acc_AFO, offset, omega, phi, ampl, phi1] = LHip(theta, eps, nu, dt, AFO_on)
t = 0;
% syms j
% M = 6;
% j = sym('j', [1 M]);

if t == 0
omega = 3*pi/2;
theta = 0;
phi = pi/2;
ampl = 0;
else
omega = omega*(t-1) + dt*(eps*offset*cos(phi1));
theta = theta*(t-1) + dt*(nu*offset);
phi = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
phi1 = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
ampl = ampl*(t-1) + dt*(nu*offset*sin(phi));
offset = theta - theta*(t-1) - sym(ampl*sin(phi), [1 M]);
end

pos_AFO = (theta*(t-1) + symsum(ampl*(t-1)*sin(phi* (t-1))))*AFO_on; %symsum needs input arguement for index M and range
vel_AFO = diff(pos_AFO)*AFO_on;
acc_AFO = diff(vel_AFO)*AFO_on;
end


https://www.pastepic.xyz/image/pg4mP



Essentially, I don't know how to do the subscripts, sigma, or the (t+1) function. Any help is appreciated as this is due next week










share|improve this question
























  • Welcome to StackOverflow. Unfortunately, the posted link does not work
    – Michael C.
    Nov 22 at 0:08












  • My bad I thought it would work. It should hopefully work now
    – Sam A
    Nov 22 at 2:42










  • You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
    – SRhm
    Nov 22 at 2:54










  • How would I use the previous values? What line of code or function would let that happen?
    – Sam A
    Nov 22 at 3:41













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am currently working on an assignment where I need to create two different controllers in Matlab/Simulink for a robotic exoskeleton leg. The idea behind this is to compare both of them and see which controller is better at assisting a human wearing it. I am having a lot of trouble putting specific equations into a Matlab function block to then run in Simulink to get results for an AFO (adaptive frequency oscillator). The link has the equations I'm trying to put in and the following is the code I have so far:



    function [pos_AFO, vel_AFO, acc_AFO, offset, omega, phi, ampl, phi1] = LHip(theta, eps, nu, dt, AFO_on)
t = 0;
% syms j
% M = 6;
% j = sym('j', [1 M]);

if t == 0
omega = 3*pi/2;
theta = 0;
phi = pi/2;
ampl = 0;
else
omega = omega*(t-1) + dt*(eps*offset*cos(phi1));
theta = theta*(t-1) + dt*(nu*offset);
phi = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
phi1 = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
ampl = ampl*(t-1) + dt*(nu*offset*sin(phi));
offset = theta - theta*(t-1) - sym(ampl*sin(phi), [1 M]);
end

pos_AFO = (theta*(t-1) + symsum(ampl*(t-1)*sin(phi* (t-1))))*AFO_on; %symsum needs input arguement for index M and range
vel_AFO = diff(pos_AFO)*AFO_on;
acc_AFO = diff(vel_AFO)*AFO_on;
end


https://www.pastepic.xyz/image/pg4mP



Essentially, I don't know how to do the subscripts, sigma, or the (t+1) function. Any help is appreciated as this is due next week










share|improve this question















I am currently working on an assignment where I need to create two different controllers in Matlab/Simulink for a robotic exoskeleton leg. The idea behind this is to compare both of them and see which controller is better at assisting a human wearing it. I am having a lot of trouble putting specific equations into a Matlab function block to then run in Simulink to get results for an AFO (adaptive frequency oscillator). The link has the equations I'm trying to put in and the following is the code I have so far:



    function [pos_AFO, vel_AFO, acc_AFO, offset, omega, phi, ampl, phi1] = LHip(theta, eps, nu, dt, AFO_on)
t = 0;
% syms j
% M = 6;
% j = sym('j', [1 M]);

if t == 0
omega = 3*pi/2;
theta = 0;
phi = pi/2;
ampl = 0;
else
omega = omega*(t-1) + dt*(eps*offset*cos(phi1));
theta = theta*(t-1) + dt*(nu*offset);
phi = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
phi1 = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
ampl = ampl*(t-1) + dt*(nu*offset*sin(phi));
offset = theta - theta*(t-1) - sym(ampl*sin(phi), [1 M]);
end

pos_AFO = (theta*(t-1) + symsum(ampl*(t-1)*sin(phi* (t-1))))*AFO_on; %symsum needs input arguement for index M and range
vel_AFO = diff(pos_AFO)*AFO_on;
acc_AFO = diff(vel_AFO)*AFO_on;
end


https://www.pastepic.xyz/image/pg4mP



Essentially, I don't know how to do the subscripts, sigma, or the (t+1) function. Any help is appreciated as this is due next week







matlab simulink






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 2:41

























asked Nov 21 at 22:47









Sam A

12




12












  • Welcome to StackOverflow. Unfortunately, the posted link does not work
    – Michael C.
    Nov 22 at 0:08












  • My bad I thought it would work. It should hopefully work now
    – Sam A
    Nov 22 at 2:42










  • You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
    – SRhm
    Nov 22 at 2:54










  • How would I use the previous values? What line of code or function would let that happen?
    – Sam A
    Nov 22 at 3:41


















  • Welcome to StackOverflow. Unfortunately, the posted link does not work
    – Michael C.
    Nov 22 at 0:08












  • My bad I thought it would work. It should hopefully work now
    – Sam A
    Nov 22 at 2:42










  • You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
    – SRhm
    Nov 22 at 2:54










  • How would I use the previous values? What line of code or function would let that happen?
    – Sam A
    Nov 22 at 3:41
















Welcome to StackOverflow. Unfortunately, the posted link does not work
– Michael C.
Nov 22 at 0:08






Welcome to StackOverflow. Unfortunately, the posted link does not work
– Michael C.
Nov 22 at 0:08














My bad I thought it would work. It should hopefully work now
– Sam A
Nov 22 at 2:42




My bad I thought it would work. It should hopefully work now
– Sam A
Nov 22 at 2:42












You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
– SRhm
Nov 22 at 2:54




You should use the previous value of theta, ampl, and phi, not multiply them by (t-1)
– SRhm
Nov 22 at 2:54












How would I use the previous values? What line of code or function would let that happen?
– Sam A
Nov 22 at 3:41




How would I use the previous values? What line of code or function would let that happen?
– Sam A
Nov 22 at 3:41












1 Answer
1






active

oldest

votes

















up vote
1
down vote













You are looking to find the result of an adaptive process therefore your algorithm needs to consider time as it progresses. There is no (t-1) operator as such. It is just a mathematical notation telling you that you need to reuse an old value to calculate a new value.



omega_old=0;
theta_old=0;
% initialize the rest of your variables

for [t=1:N]
omega[t] = omega_old + % here is the rest of your omega calculation
theta[t] = theta_old + % ...

% more code .....

% remember your old values for next iteration
omega_old = omega[t];
theta_old = theta[t];
end


I think you forgot to apply the modulo operation to phi judging by the original formula you linked. As a general rule, design your code in small pieces, make sure the output of each piece makes sense and then combine all pieces and make sure the overall result is correct.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421499%2finput-equations-into-matlab-for-simulink-function%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    You are looking to find the result of an adaptive process therefore your algorithm needs to consider time as it progresses. There is no (t-1) operator as such. It is just a mathematical notation telling you that you need to reuse an old value to calculate a new value.



    omega_old=0;
    theta_old=0;
    % initialize the rest of your variables

    for [t=1:N]
    omega[t] = omega_old + % here is the rest of your omega calculation
    theta[t] = theta_old + % ...

    % more code .....

    % remember your old values for next iteration
    omega_old = omega[t];
    theta_old = theta[t];
    end


    I think you forgot to apply the modulo operation to phi judging by the original formula you linked. As a general rule, design your code in small pieces, make sure the output of each piece makes sense and then combine all pieces and make sure the overall result is correct.






    share|improve this answer



























      up vote
      1
      down vote













      You are looking to find the result of an adaptive process therefore your algorithm needs to consider time as it progresses. There is no (t-1) operator as such. It is just a mathematical notation telling you that you need to reuse an old value to calculate a new value.



      omega_old=0;
      theta_old=0;
      % initialize the rest of your variables

      for [t=1:N]
      omega[t] = omega_old + % here is the rest of your omega calculation
      theta[t] = theta_old + % ...

      % more code .....

      % remember your old values for next iteration
      omega_old = omega[t];
      theta_old = theta[t];
      end


      I think you forgot to apply the modulo operation to phi judging by the original formula you linked. As a general rule, design your code in small pieces, make sure the output of each piece makes sense and then combine all pieces and make sure the overall result is correct.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        You are looking to find the result of an adaptive process therefore your algorithm needs to consider time as it progresses. There is no (t-1) operator as such. It is just a mathematical notation telling you that you need to reuse an old value to calculate a new value.



        omega_old=0;
        theta_old=0;
        % initialize the rest of your variables

        for [t=1:N]
        omega[t] = omega_old + % here is the rest of your omega calculation
        theta[t] = theta_old + % ...

        % more code .....

        % remember your old values for next iteration
        omega_old = omega[t];
        theta_old = theta[t];
        end


        I think you forgot to apply the modulo operation to phi judging by the original formula you linked. As a general rule, design your code in small pieces, make sure the output of each piece makes sense and then combine all pieces and make sure the overall result is correct.






        share|improve this answer














        You are looking to find the result of an adaptive process therefore your algorithm needs to consider time as it progresses. There is no (t-1) operator as such. It is just a mathematical notation telling you that you need to reuse an old value to calculate a new value.



        omega_old=0;
        theta_old=0;
        % initialize the rest of your variables

        for [t=1:N]
        omega[t] = omega_old + % here is the rest of your omega calculation
        theta[t] = theta_old + % ...

        % more code .....

        % remember your old values for next iteration
        omega_old = omega[t];
        theta_old = theta[t];
        end


        I think you forgot to apply the modulo operation to phi judging by the original formula you linked. As a general rule, design your code in small pieces, make sure the output of each piece makes sense and then combine all pieces and make sure the overall result is correct.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 at 23:16

























        answered Nov 23 at 18:42









        Michael C.

        10210




        10210






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421499%2finput-equations-into-matlab-for-simulink-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks