A 2D slider-crank animation of the one-cylinder engine
(Modelica.Mechanics.MultiBody.Examples.Loops.Engine1a) simulated with OM.jl.
The blue arm is the crank, the orange segment is the connecting rod, and the red block is the piston sliding in the cylinder. The dotted circle is the crank-pin path. The flywheel starts at 10 rad/s and the stored angular momentum drives the motion (there is no combustion in this model).
Engine1a is the mechanical part of one engine cylinder, built solely from
revolute and prismatic joints. This forms a planar kinematic loop, which
OM.jl solves numerically each step. The single state that matters for the
animation is the crankshaft angle Inertia.phi.
- Simulate.
OM.simulateruns the model with the stiffRodas5solver and the crankshaft angle is read back asInertia.phi. - Slider-crank geometry. The mechanism has one degree of freedom: given the
crank angle
theta, the crank pin is at(R*sin theta, R*cos theta)and the piston aty = R*cos theta + sqrt(L^2 - (R*sin theta)^2). The crank radiusR = 0.1and rod lengthL = 0.2are taken directly from the model (Crank2.randRod.r). - Render. Each frame draws the crank, rod, piston, and cylinder; the GIF is
assembled with
Plots.
The example needs OM (this repository) and Plots:
using Pkg
Pkg.add("Plots")
include("examples/Animation/Engine/engine_animation.jl")This regenerates engine.gif in this directory.
The sibling model Engine1b adds a gas-force model but starts from rest
(w = 0); with no cranking torque it does not turn over, so it is not useful for
an animation. Engine1a is driven by the flywheel's initial speed and spins
through several revolutions, which is why it is used here.
