Engee documentation
Notebook

A pendulum in polar coordinates: a physical component in Engee

The implementation of a pendulum in polar coordinates demonstrates an approach to modeling mechanical systems through physical components.

Description of the model

The 2D model of a pendulum (in the plane of motion) consists of a point mass fixed on a weightless rod with a length of , which can freely rotate around the suspension point. The system is affected by:

  • Gravity ;

  • Damping force proportional to the angular velocity by a factor of ;

  • Rod reaction (tension), which is automatically taken into account when using polar coordinates (significantly complicating the model when modeling in Cartesian coordinates).

image.png

The settings for mass, rod length, and initial displacement are transmitted to the component via the block mask. Маятник в полярных координатах:

image.png

In polar coordinates, the state of the system is described by the angle of deflection and angular velocity . The equations of motion have the form:

where:

  • — the angle of deviation from the vertical (rad);

  • — angular velocity (rad/s);

  • — the mass of the pendulum (kg);

  • — rod length (m);

  • — damping coefficient (kg/s);

  • — acceleration of gravity (m/s2).

In the file pendulum_planar_polar_coord.ngpc The code of this system is given in the Engee physical modeling language. In contrast to the algorithmic type of solution, or from specifying the system in a finite-difference form for numerical integration, the language of physical modeling allows you to expand the physical description and include effects that will act on the system "from the output variables" - for example, add a changing inertia of the mass or the movement of the suspension.

In the block @equations this code shows how the equations of motion of the system are given in terms of differential equations:

der(theta) ~ omega
m * l * der(omega) ~ -m * g * sin(theta) - l * d * omega

To successfully compile the code of the pendulum model, the file pendulum_planar_polar_coord.ngpc It must be located in a folder located among the search paths in the system (i.e. in one of the home folders). The icon of the folder containing the component should look like this: <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg "class="folder-icon">.

Launching the model

Let's imagine the dependence of the angle of deviation of the pendulum on time. The initial angle is 90° (π/2 rad).

In [ ]:
engee.open("pendulum_in_polar_coordinates.engee")
data = engee.run()

angle_array = data["Маятник в полярных координатах.Угол"]

gr()
plot( angle_array.time, angle_array.value, xlabel="Time, from", ylabel="Angle, degree",
      label = "The pendulum in Cartesian coordinates", title="Simulation of the movement of a pendulum")
Out[0]:
No description has been provided for this image

Conclusion

This training example is intended to illustrate a physical modeling approach that allows mechanical systems with equations of motion and constraints to be placed inside Engee blocks.