Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Can you create a spring in MAtlab?

  • 05-10-2010 02:56PM
    #1
    Registered Users, Registered Users 2 Posts: 61 ✭✭


    Ok I'll try this again, sorry if I get it wrong again but can you help me out again Phil if so, thanks!


    I am just trying to make the suspension of a bus, so I want to create a spring that I can connect between the wheel and the bus and change its stiffness, do any body know is this possible and if so how I could go about doing it?

    I have a road profile that is basically a curved line in which two wheels and a bus move along. I have posted the code below so you can get an idea to what im trying to do but I cant post the road profile as it is a file, so if you can help me I will send you the road profile too.

    Initially when I tried to make a spring, I did it like you would create a line, I made a few arrays with points in them and created a few lines that looked like a spring, but the problem is I need this to react like a spring and with a few lines connected to each other resembling a spring it would no react while going along the road profile.

    There is a demo within Matlab called "Double Spring Mass System", but with this it uses Simulink and it moves the spring in a horizontal direction. I have tried to understand the model and rotate the spring but I cant and this is why I am asking for your help guys,

    Thanks



    ************ CODE *************



    % user_entry = input('prompt');

    X = input('Press 1 for Sinusoidal or 0 for Road Profile ');


    if X == 1

    % **********************************************************
    % SINE WAVE
    % **********************************************************

    sim('SineWave')

    waitfor(msgbox('X == 1'))
    figure('numbertitle','off','name','Sine Wave Plot')
    simplot(sinewave)

    figure('numbertitle','off','name','Road Profile Plot')

    for i = 1:50

    circlecentrey = sinewave.signals.values(i)+.005;
    circlecentrex = 0.99;

    circlecentrey1 = sinewave.signals.values(i+1)+.005;
    circlecentrex1 = 0.99+3.2; % The 3.2 is the Wheelbase

    wheelrimy = sinewave.signals.values(i)+.01;
    wheelrimx = 0.99;

    wheelrimy1 = sinewave.signals.values(i+1)+.01;
    wheelrimx1 = 0.99+3.2;

    for j = 0:30
    circlex(j+1)=circlecentrex+0.5*sin(j*2*pi/30);
    circley(j+1)=circlecentrey+0.005*cos(j*2*pi/30);
    end

    for k = 0:30
    circlex1(k+1)=circlecentrex1+0.5*sin(k*2*pi/30);
    circley1(k+1)=circlecentrey1+0.005*cos(k*2*pi/30);
    end

    for l = 0:30

    wheelcirclex(l+1)=((wheelrimx+0.5*sin(l*2*pi/30)));
    wheelcircley(l+1)=((wheelrimy+0.005*cos(l*2*pi/30)));
    end

    for m = 0:30

    wheelcirclex1(m+1)=((wheelrimx1+0.5*sin(m*2*pi/30)));
    wheelcircley1(m+1)=((wheelrimy1+0.005*cos(m*2*pi/30)));
    end

    a = circlecentrex;
    b = circlecentrey;

    d = circlecentrex1;
    e = circlecentrey1;

    b1 = b + 0.01;
    e1 = e + 0.01;
    e2 = e1 + 0.02;
    e3 = e1 + 0.01;
    c = b1 + 0.02;
    f = e1 + 0.02;
    a1 = a - 0.4;
    d1 = d + 0.4;


    Spring_X = [a a a-0.06 a+0.06 a-0.06 a+0.06 a a];
    Spring_Y = [b b+0.001 b+0.002 b+0.004 b+0.006 b+0.008 b+0.009 b+0.01];
    Spring_X1 = [d d d-0.06 d+0.06 d-0.06 d+0.06 d d];
    Spring_Y1 = [e e+0.001 e+0.002 e+0.004 e+0.006 e+0.008 e+0.009 e+0.01];
    Bus_X = [a1 a1 d d d1 d1 a1];
    Bus_Y = [b1 c e2 e3 e3 e1 b1];




    plot(sinewave.time,sinewave.signals.values)
    % plot(groundx,roadprofile(2,i:i+200), 'LineWidth', 2);


    hold on
    plot(sinewave.time(i),sinewave.signals.values(i))
    plot(circlex,circley, 'r', 'LineWidth', 3);
    plot(circlex1,circley1, 'r', 'LineWidth', 3);
    plot(Bus_X,Bus_Y,'b','LineWidth',5);
    plot(wheelcirclex,wheelcircley,'g','LineWidth',5);
    plot(wheelcirclex1,wheelcircley1,'g','LineWidth',5);
    plot(Spring_X,Spring_Y,'cyan','LineWidth',2);
    plot(Spring_X1,Spring_Y1,'cyan','LineWidth',2);


    axis([-0.1 10.1 -1.5 1.5]);
    pause(.1);
    hold off
    end
    % **********************************************************
    % ROAD PROFILE
    % **********************************************************

    elseif X == 0

    % waitfor(msgbox('You Must First Upload The Road Profile To The Workspace','Warning','warn'));
    waitfor(msgbox('X == 0'))

    groundx=0:0.03:6;

    figure('numbertitle','off','name','Road Profile Plot')


    for i = 1:800

    circlecentrey = roadprofile(2,i+32)+.005;
    circlecentrex = 0.99;

    circlecentrey1 = roadprofile(2,i+140)+.005;
    circlecentrex1 = 0.99+3.2; % The 3.2 is the Wheelbase

    wheelrimy = roadprofile(2,i+32)+.01;
    wheelrimx = 0.99;

    wheelrimy1 = roadprofile(2,i+140)+.01;
    wheelrimx1 = 0.99+3.2;

    for j = 0:30
    circlex(j+1)=circlecentrex+0.5*sin(j*2*pi/30);
    circley(j+1)=circlecentrey+0.005*cos(j*2*pi/30);
    end

    for k = 0:30
    circlex1(k+1)=circlecentrex1+0.5*sin(k*2*pi/30);
    circley1(k+1)=circlecentrey1+0.005*cos(k*2*pi/30);
    end

    for l = 0:30

    wheelcirclex(l+1)=((wheelrimx+0.5*sin(l*2*pi/30)));
    wheelcircley(l+1)=((wheelrimy+0.005*cos(l*2*pi/30)));
    end

    for m = 0:30

    wheelcirclex1(m+1)=((wheelrimx1+0.5*sin(m*2*pi/30)));
    wheelcircley1(m+1)=((wheelrimy1+0.005*cos(m*2*pi/30)));
    end

    a = circlecentrex;
    b = circlecentrey;

    d = circlecentrex1;
    e = circlecentrey1;

    b1 = b + 0.01;
    e1 = e + 0.01;
    e2 = e1 + 0.02;
    e3 = e1 + 0.01;
    c = b1 + 0.02;
    f = e1 + 0.02;
    a1 = a - 0.4;
    d1 = d + 0.4;


    Spring_X = [a a a-0.06 a+0.06 a-0.06 a+0.06 a a];
    Spring_Y = [b b+0.001 b+0.002 b+0.004 b+0.006 b+0.008 b+0.009 b+0.01];
    Spring_X1 = [d d d-0.06 d+0.06 d-0.06 d+0.06 d d];
    Spring_Y1 = [e e+0.001 e+0.002 e+0.004 e+0.006 e+0.008 e+0.009 e+0.01];
    Bus_X = [a1 a1 d d d1 d1 a1];
    Bus_Y = [b1 c e2 e3 e3 e1 b1];



    plot(groundx,roadprofile(2,i:i+200), 'LineWidth', 2);
    hold on
    plot(circlex,circley, 'r', 'LineWidth', 3);
    plot(circlex1,circley1, 'r', 'LineWidth', 3);
    plot(Bus_X,Bus_Y,'b','LineWidth',5);
    % plot(wheelcirclex,wheelcircley,'g','LineWidth',5);
    % plot(wheelcirclex1,wheelcircley1,'g','LineWidth',5);
    plot(Spring_X,Spring_Y,'cyan','LineWidth',2);
    plot(Spring_X1,Spring_Y1,'cyan','LineWidth',2);


    axis([-0.1 6 -0.02 0.06]);
    pause(.01);
    hold off
    end

    end



    ************ CODE *************


Comments

  • Registered Users, Registered Users 2 Posts: 61 ✭✭[DM]Frink


    So no one can help me then?


  • Registered Users, Registered Users 2 Posts: 61 ✭✭[DM]Frink


    Can not one person give me any idea into this no :(


Advertisement