Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. %Given Variables
  2. syms qi qf qddc tf;
  3. %Set Given Values
  4. qi=.1;
  5. qf=1.2;
  6. qddc=6;
  7. tf=1.2;
  8.  
  9. %Check for valid condition
  10. if ((qddc*tf^2)/4<=(qf-qi))
  11. fprintf("The motion cannot be completed with the given parameters")
  12. return
  13. end
  14. %Solved Variables
  15. syms tc qdc;
  16. %Variable Relations
  17. eq1=subs(qdc==qddc*tc);
  18. eq2=subs((qf-qi)==(tf-tc)*qdc);
  19. eq3=subs(tc<=tf/2);
  20. %Solving
  21. S=solve([eq1,eq2,eq3],[tc,qdc]);
  22. tc=S.tc;
  23. qdc=S.qdc;
  24. %Define Piecewise Functions
  25. syms x
  26. 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);
  27. qd=piecewise(0<x<tc, qddc*x, tc<x<(tf-tc), qdc, (tf-tc)<x<tf, -qddc*(x-tf));
  28. qdd=piecewise(0<x<tc, qddc, tc<x<(tf-tc), 0, (tf-tc)<x<tf, -qddc);
  29. %Plotting
  30. hold on
  31. subplot(3,1,1)
  32. fplot(q, [0 tf])
  33. xlabel('time')
  34. ylabel('Position')
  35. subplot(3,1,2)
  36. fplot(qd, [0 tf])
  37. xlabel('time')
  38. ylabel('Velocity')
  39. subplot(3,1,3)
  40. fplot(qdd, [0 tf])
  41. xlabel('time')
  42. ylabel('Acceleration')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement