Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Given Variables
- syms qi qf qddc tf;
- %Set Given Values
- qi=.1;
- qf=1.2;
- qddc=6;
- tf=1.2;
- %Check for valid condition
- if ((qddc*tf^2)/4<=(qf-qi))
- fprintf("The motion cannot be completed with the given parameters")
- return
- end
- %Solved Variables
- syms tc qdc;
- %Variable Relations
- eq1=subs(qdc==qddc*tc);
- eq2=subs((qf-qi)==(tf-tc)*qdc);
- eq3=subs(tc<=tf/2);
- %Solving
- S=solve([eq1,eq2,eq3],[tc,qdc]);
- tc=S.tc;
- qdc=S.qdc;
- %Define Piecewise Functions
- syms x
- q=piecewise(0<x<tc, qi+qddc*x^2/2, tc<x<(tf-tc), qi+qddc*tc^2/2+(x-tc)*qdc, (tf-tc)<x<tf, qf-(tf-x)^2*qddc/2);
- qd=piecewise(0<x<tc, qddc*x, tc<x<(tf-tc), qdc, (tf-tc)<x<tf, -qddc*(x-tf));
- qdd=piecewise(0<x<tc, qddc, tc<x<(tf-tc), 0, (tf-tc)<x<tf, -qddc);
- %Plotting
- hold on
- subplot(3,1,1)
- fplot(q, [0 tf])
- xlabel('time')
- ylabel('Position')
- subplot(3,1,2)
- fplot(qd, [0 tf])
- xlabel('time')
- ylabel('Velocity')
- subplot(3,1,3)
- fplot(qdd, [0 tf])
- xlabel('time')
- ylabel('Acceleration')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement