> restart: libname := libname, "C:/libs/MBSymba.mla": with(MBSymba_r6):
Vector loop
definition of the vectors
> AC := make_VECTOR(ground,c,0,0): show(AC);
> AB := make_VECTOR(Rotate('Z',q),r,0,0): show(AB);
> BC := make_VECTOR(Rotate('Z',-theta),l,0,0): show(BC);
##NOTE: theta is clockwise, so it requires the minus (-) sign.
closing the vector loop: definition of a closure vector
> closure := AC - BC - AB: show(closure);
this expression must be null
> {comp_X(closure) , comp_Y(closure)};
we find the solution with respect to the variables cand theta which depend on the generalized coordinate q(rotation of the crank)
> solution := solve(%,{theta,c});
we extract the solutions
> eval([theta, c], solution):
> theta := %[1];
> c := %%[2];
anothe trick for univocally identify variables from solution set
> c := subs(solution,c);
> theta := subs(solution,theta);
Numerical Solution
numerical solution for specified crank and rod lengths:
crank length r = 0.1 m
rod length l = 0.4 m
> dataset := [r=0.1, l=0.4];
> theta := subs(dataset, theta);
> c := subs(dataset,c);
> r := subs(dataset,r);
> l := subs(dataset,l);
Plot of the mechanism
> A := origin(ground): #show(A);
> B := A + AB: show(B): show(B);
> C := A + AC: show(C): show(C);
> vertex := [ [comp_X(A),comp_Y(A)] , [comp_X(B),comp_Y(B)] , [comp_X(C),comp_Y(C)] ];
> plot(theta, q=0..2*Pi, labels=[q, "theta"], title="theta vs. q");
> plot(c, q=0..2*Pi, labels=[q, "c"], title="location of the slider vs. q");
Animation of the Mechanism
##Substitute in values for problem
> with(plots):with(plottools):
##Generate frames for the animation
> N:=15; ##number of steps
for n from 0 to N-1 do
q := evalf(2*Pi*n/N);
##crank
> crank || n := plot({[ [comp_X(A)+0.01*cos(q),comp_Y(A)+0.01*sin(q)], [comp_X(B)-0.01*cos(q),comp_Y(B)-0.01*sin(q)] ] }, color=black, thickness=3 );
##connecting rod
> rod || n := plot( {[ [comp_X(B)+0.01*cos(theta),comp_Y(B)-0.01*sin(theta)], [comp_X(C)-0.01*cos(theta),comp_Y(C)+0.01*sin(theta)] ]}, color=black, thickness=3 );
## slider
> slider || n := rectangle([comp_X(C)-0.08/2, comp_Y(C)+0.02], [comp_X(C)+0.08/2, comp_Y(C)-0.02], color=grey );
##revolute joint A
> revj_A || n := disk( [comp_X(A),comp_Y(A)], 0.01, color=yellow );
##revolute joint B
> revj_B || n := disk( [comp_X(B),comp_Y(B)], 0.01, color=yellow );
##revolute joint C
> revj_C || n := disk( [comp_X(C),comp_Y(C)], 0.01, color=yellow );
##assembly the mechanis
> four_bar || n := display ( {crank||n, rod||n, slider||n, revj_A||n, revj_B||n, revj_C||n} ):
> end:
Display the animation
> display([four_bar||(0..N-1)], insequence=true, scaling=constrained);