Lab 5, simulation of car trailer. EME 121, Spring 2011, UC Davis

By Nasser M. Abbasi. May 22, 2011

Manipulate[process[u,m,L,abRatio,IgGain,Ct,v0,r0,θ0,δ,f,maxt,noslip],
{{u,79.2,"speed U km/hr"},10,200,1,Appearance->"Labeled",ImageSize->Small},
{{m,1800/2.2,"mass kg"},1,1000,1,Appearance->"Labeled",ImageSize->Small},
{{L,7*0.3048,"trailer length m"},1,10,0.1,Appearance->"Labeled",ImageSize->Small},
{{abRatio,0.85,"a/b ratio"},0.1,0.9,0.1,Appearance->"Labeled",ImageSize->Small},
{{IgGain,0.8,"(Subscript[I, g]) gain"},{0.8->0.8,0.9->0.9,1->1,1.1->1.1,1.2->1.2,1.3->1.3},ControlType->SetterBar,ImageSize->Small},
{{Ct,210*4.448*180/Pi,"(Subscript[C, t]) N/rad"},30000,100000,1000,Appearance->"Labeled",ImageSize->Small},
{{f,1,"spring f (Hz)"},0.1,3,0.1,Appearance->"Labeled",ImageSize->Small},
{{maxt,10,"simulation time (sec)"},0.1,40,0.1,Appearance->"Labeled",ImageSize->Small},

Delimiter,

Control[{{noslip,False,"Apply no-slip condition"},{False, True},ControlType->Checkbox,ImageSize->Small}],

Delimiter,

Text["Initial conditions"],
{{v0,0,"V(0) km/hr"},0,10,1,Appearance->"Labeled",ImageSize->Small},
{{r0,0,"r(0) degree/sec"},0,7,1,Appearance->"Labeled",ImageSize->Small},
{{θ0,2,"θ(0) degree"},0,7,.1,Appearance->"Labeled",ImageSize->Small},
{{δ,0,"(Subscript[δ, s])(0) mm"},0,100,1,Appearance->"Labeled",ImageSize->Small},

SynchronousUpdating->False,(*important to have this*)
ContinuousAction->False,

Initialization:> 
(
process[uu0_,m_,L_,abRatio_,IgGain_,c_,vv0_,rr0_,θθ0_,δδ0_,f_,maxt_,noslip_]:=Module[{b=1./(1+abRatio),a,k=m*(2.*Pi*f)^2,u0=uu0*1000/3600.,v0=vv0*1000/3600.,θ0=θθ0*Pi/180.,δ0=δδ0/1000.,r0=rr0*Pi/180.,F,eq1,eq2,eq3,eq4,t,r,v,θ,δ,Ig,sol,data},

a=L-b;
F=c(b r[t]-v[t])/u0;
Ig=IgGain m a b;

If[noslip==False,{
eq1=v'[t]==(F/m)+((k δ[t])/m)-r[t] u0;
eq2=r'[t]==((k δ[t] a )/Ig)-((F b)/Ig);
eq3=θ'[t]==r[t];
eq4=δ'[t]==-(v[t]+u0 θ[t]+a r[t]);
sol=First@DSolve[{eq1,eq2,eq3,eq4,v[0]==v0,r[0]==r0,θ[0]==θ0,δ[0]==δ0},{v[t],r[t],θ[t],δ[t]},t]
},{
eq1=r'[t]==((-r[t](m b u0)+(b+a)k δ[t])/(Ig+m b^2));
eq2=θ'[t]==r[t];
eq3=δ'[t]==-(b r[t]+u0 θ[t]+a r[t]);
sol=First@DSolve[{eq1,eq2,eq3,r[0]==r0,θ[0]==θ0,δ[0]==δ0},{r[t],θ[t],δ[t]},t]
}
];


Grid[
{ 
{Plot[Chop@Evaluate[r[t]/.sol]*180/Pi,{t,0,maxt},PlotRange->All,Frame->True,FrameLabel->{{"r(t) (deg/sec)",None},{"t (sec)","r(t) vs. time"}},ImagePadding->{{40,10},{40,40}},ImageSize->250,AspectRatio->0.8]
},
{
Row[{
Plot[Chop@Evaluate[θ[t]/.sol]*180/Pi,{t,0,maxt},PlotRange->All,Frame->True,FrameLabel->{{None,None},{"t (sec)",Row[{"θ in deg vs. time"}]}},ImagePadding->{{40,10},{50,40}},ImageSize->180]
,
Plot[Chop@Evaluate[δ[t]/.sol],{t,0,maxt},PlotRange->All,Frame->True,FrameLabel->{{None,None},{"t (sec)",Row[{"spring displacement (mm) vs. time"}]}},ImagePadding->{{40,10},{50,40}},ImageSize->180]
}]
}
},Frame->All,Spacings->0
]
]

)
]