Rigid Body Pendulum on a Flywheel

Manipulate[
Quiet[process[L,m,massOfFlyWheel,θ0,ϕ0,derθ0,derϕ0,viewPoint,currentTime],InterpolatingFunction::dmval],
{{L,7.5,"rod length (m)"},2,7.5,.1,Appearance->"Labeled",ImageSize->Tiny},
{{m,3.5,"mass of rod (kg)"},1,100,.1,Appearance->"Labeled",ImageSize->Tiny},
{{massOfFlyWheel,3.5,"mass of flywheel (kg)"},1,500,.1,Appearance->"Labeled",ImageSize->Tiny},
Delimiter,
{{θ0,45,"θ(0) (deg)"},-90,90,1,Appearance->"Labeled",ImageSize->Tiny},
{{ϕ0,90,"ϕ(0) (deg)"},0,360,1,Appearance->"Labeled",ImageSize->Tiny},
{{derθ0,24,"θ'(0) (deg/sec)"},0,90,1,Appearance->"Labeled",ImageSize->Tiny},
{{derϕ0,50,"ϕ'(0) (deg/sec)"},0,90,1,Appearance->"Labeled",ImageSize->Tiny},
{{animRate,1,"animate rate"},.1,2,.1,Appearance->"Labeled",ImageSize->Tiny},
Delimiter,
{{currentTime,0,"start simulation"},0,100,.001,ControlType->Trigger,AnimationRate->Dynamic[animRate],ImageSize->Tiny},
Delimiter,
{{viewPoint,{Pi,Pi/2,2},"select viewpoint"},{{1.3,-2.4,2}->1,{1,-2,1}->2,{0,-2,2}->3,{0,-2,-2}->4,{-2,-2,0}->5,{2,-2,0}->6,{Pi,Pi/2,2}->7},ControlType->SetterBar,ImageSize->Small},

SynchronousUpdating->True,
SynchronousInitialization->True,
AutorunSequencing->{9},

Initialization:> 
(
g=9.8;
h1=.4;
r1=6*h1;
h0=3*h1; r0=r1/3;
h2=4*h1;
r2=h2/2;
r3=r2/4;

process[L_,m_,massOfFlyWheel_,θ0_,ϕ0_,derθ0_,derϕ0_,viewPoint_,currentTime_]:=Module[{eq1,eq2,Id,sol,solθ,solϕ,θ,ϕ,t,lines,i,title},
Id=massOfFlyWheel*r1^2/2;

(*The equations of motions of for the 2 generalized coordinates have beeen*)
(*derived using Lagrangian energy method and will now be numerically solved*)
eq1= Id ϕ''[t]+(1/3 m L^2)(ϕ''[t] Sin[θ[t]]^2+2 ϕ'[t] Sin[θ[t]] Cos[θ[t]]θ'[t]);
eq2=(1/3) m (L^2) θ''[t]-(1/3)m L^2 ϕ'[t]^2 Sin[θ[t]]Cos[θ[t]]+m g L/2 Sin[θ[t]];

sol=First@Quiet@NDSolve[{eq1==0,eq2==0,θ[0]==θ0 Degree,θ'[0]==derθ0 Degree,ϕ[0]==ϕ0 Degree,ϕ'[0]==derϕ0 Degree},{θ,ϕ},{t,0,100}];

solθ=θ/.sol;
solϕ=ϕ/.sol;

With[{currentθ=solθ[currentTime],currentϕ=solϕ[currentTime]},

(*make few lines to draw around the pendulum rod in order to make it *)
(*more clear that it is spining on its axes*)
lines=Table[Line[{
{r3 Cos[currentϕ+i*2Pi/5],r3 Sin[currentϕ+i*2Pi/5] ,-(h1/2+h2-r2/2)+ r3 Sin[currentθ]Cos[currentϕ+i*2Pi/5]  },
{r3 Cos[currentϕ+i*2Pi/5]+ L Sin[currentθ],r3 Sin[currentϕ+i*2Pi/5],- L Cos[currentθ]-(h1/2+h2-r2/2)+ r3 Sin[currentθ]Cos[currentϕ+i*2Pi/5] }
}],{i,1,5}];

title =Text@Style[Grid[{
{"time (sec)","θ (deg)","ϕ (deg)"},

{Row[{
Text@PaddedForm[currentTime,{4,2},NumberSigns->{"-",""},NumberPadding->{"0","0"},SignPadding->True]
}],

Row[{
Text@PaddedForm[currentθ 180./Pi ,{5,2},NumberSigns->{"-","+"},NumberPadding->{"0","0"},SignPadding->True]
}],

Row[{
Text@PaddedForm[Mod[currentϕ 180./Pi,360],{5,2},NumberSigns->{"",""},NumberPadding->{"0","0"},SignPadding->True]
}]
}},Frame->All,Spacings->1,ItemSize->8]
,12];

(*build the 3D graphics, one by one from top to bottom *)
Grid[{
{title},
{
Graphics3D[
{
Cylinder[{{0,0,h1/2},{0,0,h1/2+h0}},r0],
Cylinder[{{0,0,h1/2},{0,0,-h1/2}},r1],
 Cuboid[{-r2,-r2/2,-h2},{r2,r2/2,0}] ,
 Cylinder[{{0,r2,-h2},{0,-r2,-h2}},r2] , 

{  EdgeForm[{Thick,Blue}],FaceForm[{Pink,Opacity[1]}],Cylinder[{{0,0,-(h1/2+h2-r2/2)},{L Sin[currentθ],0,-(h1/2+h2-r2/2+L Cos[currentθ])}},r3] },

(*line around cylinder*)
{Thickness[.005],Blue,lines},

{Thickness[.02],Red,Line[{{0,0,h1/2},{r1 Cos[currentϕ],r1 Sin[currentϕ],h1/2}}]},
{Thickness[.02],Red,Line[{{r1 Cos[currentϕ],r1 Sin[currentϕ],h1/2},{r1 Cos[currentϕ],r1 Sin[currentϕ],-h1/2}}]}
},

PlotRange->{{-5,5},{-3,3},{-8,1}},ImageSize->{330,330},Axes->False,Boxed->False,AxesOrigin->{0,0,0},ImageMargins->2,ImagePadding->2,PlotRangePadding->1,
ViewPoint->viewPoint,ViewCenter->{0,0,0}
]}
},Alignment->Center,Spacings->0,Frame->{False,-1->True}]
]
]
)
]

This Demonstration simulates the motion of a rigid pendulum pivoted, with no friction, to a rotating flywheel. The pendulum is forced to spin on its axes by the flywheel's angular motion and at the same it can swing in a fixed 2D plane. The system has two degrees of freedom: θ, which is the pendulum's swing angle, and ϕ, which is the flywheel's rotation angle. The two nonlinear equations of motion are derived using the Lagrangian energy method. The two equations are solved numerically and the motion is simulated. Interesting motion profiles can be observed by changing the system parameters and the initial conditions.

The parameters that you can vary with the sliders are: mass of the flywheel, mass of the pendulum rod, length of the rod, and the four initial conditions needed for the two second-order differential equations. All units are SI.

The pendulum is a rigid body in rotation, assumed to have its center of mass at its midpoint. The equations of motion are (Subscript[I, d]) ϕ''(t)+(1/3) m (L^2)(ϕ''(t) (sin^2) θ(t)+2 ϕ'(t)  θ'(t)sin θ(t) cos θ(t) )=0 and (1/3) m (L^2) θ''(t)-(1/3)m (L^2) ϕ'(((t))^2) sin θ(t)cos θ(t)+m g ((L )/2) sin θ(t)=0, where (Subscript[I, d]) is the moment of inertia of the flywheel, given by M (R^2)/2, where M is the mass of the flywheel and R is its radius; m is the mass of the pendulum rod and L is its length. The nonlinear equations are solved numerically using the built-in Mathematica function NDSolve. Notice that the pivot point where the pendulum is attached to the flywheel remains fixed in space.

Contributed by: Nasser M. Abbasi