Gyroscope in a gimbal
A gyroscope in a gimbal.
- Class:
GimballedGyroscopeSystem - Import:
from skcomplex.systems.physics.mechanics import GimballedGyroscopeSystem - Field:
physics/mechanics - Topics:
mechanics,ode,second order,rotation,gyroscope,lagrangian - References:
- Ryzhov et al. 2021
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.mechanics import GimballedGyroscopeSystem
trajectory = GimballedGyroscopeSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
spin |
50.0 |
beta |
0.3 |
A |
1.0 |
C |
2.0 |
A1 |
0.5 |
B1 |
0.5 |
C1 |
0.5 |
A2 |
1.0 |
torque |
1.0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class GimballedGyroscopeSystem(BaseSystem):
"""A gyroscope in a gimbal.
A rotor in an inner ring turns in an outer ring about a fixed axis.
The outer ring turns by `alpha` about the fixed axis, the inner ring by `beta` in the outer ring, and the rotor
spins by `gamma` in the inner ring. The equations are the Lagrange equations of the kinetic energy `[A2 + (A + A1)
cos² beta + (C + C1) sin² beta] alpha'² / 2 + (A + B1) beta'² / 2 + C alpha' gamma' sin beta + C gamma'² / 2`, with
a torque on the axis of the inner ring, which makes the fast rotor precess about the fixed axis. The momenta
conjugate to `alpha` and `gamma` are conserved. The system has the angles `gyroscope.alpha`, `gyroscope.beta`, and
`gyroscope.gamma`, and their angular velocities, such as `gyroscope.gamma'`.
Args:
spin:
The initial angular velocity of the rotor in the inner ring.
beta:
The initial angle of the inner ring.
A:
The equatorial moment of inertia of the rotor.
C:
The polar moment of inertia of the rotor.
A1:
The first principal moment of inertia of the inner ring.
B1:
The second principal moment of inertia of the inner ring.
C1:
The third principal moment of inertia of the inner ring.
A2:
The moment of inertia of the outer ring about its axis.
torque:
The torque on the axis of the inner ring.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.mechanics import GimballedGyroscopeSystem
>>> trajectory = GimballedGyroscopeSystem(spin=10.0).prepare().simulate(until=0.1)
>>> float(trajectory.get_values("gyroscope.gamma'")[0])
10.0
"""
field = 'physics/mechanics'
topics = ('mechanics', 'ode', 'second order', 'rotation', 'gyroscope', 'lagrangian')
references = ('Ryzhov et al. 2021',)
until = 10.0
dt = 0.01
def __init__(
self,
spin: float = 50.0,
beta: float = 0.3,
*,
A: float = 1.0,
C: float = 2.0,
A1: float = 0.5,
B1: float = 0.5,
C1: float = 0.5,
A2: float = 1.0,
torque: float = 1.0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.spin = spin
self.beta = beta
self.A = A
self.C = C
self.A1 = A1
self.B1 = B1
self.C1 = C1
self.A2 = A2
self.torque = torque
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a gyroscope in a gimbal, its rotor spinning.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
gyroscope = GyroscopeElement(
'gyroscope',
beta=self.beta,
A=self.A,
C=self.C,
A1=self.A1,
B1=self.B1,
C1=self.C1,
A2=self.A2,
values={"gamma'": self.spin},
)
motion = GyroscopeInteraction('motion', target='gyroscope', torque=self.torque)
self.system_ = System(self.label, elements=[gyroscope], interactions=[motion])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
GyroscopeElement, fromElement
Interactions:
GyroscopeInteraction, fromInteraction
class GyroscopeElement(Element):
"""Gyroscope in a gimbal.
A rotor in an inner ring turns in an outer ring about a fixed axis.
The angle `alpha` of the outer ring, `beta` of the inner ring, and `gamma` of the rotor are the coordinates of
`GyroscopeInteraction`, and their angular velocities are `alpha'`, `beta'`, and `gamma'`.
Args:
label:
The label of the gyroscope.
alpha:
The initial angle of the outer ring.
beta:
The initial angle of the inner ring.
gamma:
The initial angle of the rotor.
A:
The equatorial moment of inertia of the rotor.
C:
The polar moment of inertia of the rotor.
A1:
The first principal moment of inertia of the inner ring.
B1:
The second principal moment of inertia of the inner ring.
C1:
The third principal moment of inertia of the inner ring.
A2:
The moment of inertia of the outer ring about its axis.
values:
Further values by name, such as an initial velocity named with a prime, or `None`.
Examples:
>>> from skcomplex.systems.physics.mechanics import GyroscopeElement
>>> GyroscopeElement('gyroscope', C=3.0).C
3.0
"""
def __init__(
self,
label: str,
*,
alpha: Annotated[float, Period(2 * math.pi)] = 0.0,
beta: float = 0.3,
gamma: Annotated[float, Period(2 * math.pi)] = 0.0,
A: Annotated[float, RealSet.open(0, oo)] = 1.0,
C: Annotated[float, RealSet.open(0, oo)] = 2.0,
A1: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
B1: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
C1: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
A2: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
values: Mapping[str, object] | None = None,
) -> None:
super().__init__(label, values=values)
self.alpha = alpha
self.beta = beta
self.gamma = gamma
self.A = A
self.C = C
self.A1 = A1
self.B1 = B1
self.C1 = C1
self.A2 = A2
class GyroscopeInteraction(LagrangianInteraction):
"""Motion of a gimballed gyroscope.
The motion is the Euler-Lagrange equations of its kinetic energy with a torque on `beta`.
The Lagrangian is the kinetic energy `[A2 + (A + A1) cos² β + (C + C1) sin² β] alpha'² / 2 + (A + B1) β'² / 2
+ C alpha' gamma' sin β + C gamma'² / 2`, and the torque acts on the axis of the inner ring.
Args:
label:
The label of the interaction.
target:
The path of the gyroscope.
torque:
The torque on the axis of the inner ring.
Examples:
>>> from skcomplex.systems.physics.mechanics import GyroscopeInteraction
>>> GyroscopeInteraction('motion', target='gyroscope', torque=2.0).torque
2.0
"""
def __init__(self, label: str, *, target: Role, torque: float = 1.0) -> None:
super().__init__(label)
self.target = target
self.torque = torque
def _get_coordinates(self, context: SimpleNamespace) -> list[Expression]:
"""Return the angles of the outer ring, the inner ring, and the rotor."""
return [context.target.alpha, context.target.beta, context.target.gamma]
def _get_forces(
self,
context: SimpleNamespace,
positions: list[Expression],
velocities: list[Expression],
) -> list[Expression]:
"""Return the generalized forces.
The torque acts on the inner ring and none on the outer ring and the rotor.
"""
return [0, context.torque, 0]
def _get_lagrangian(
self,
context: SimpleNamespace,
positions: list[Expression],
velocities: list[Expression],
) -> Expression:
"""Return the kinetic energy of the rings and the rotor.
Args:
context:
The namespace of the gyroscope, the time `t`, and the parameters.
positions:
The symbols of the angles.
velocities:
The symbols of the angular velocities.
Returns:
lagrangian:
The Lagrangian.
"""
p = context.target
beta = positions[1]
da, db, dc = velocities
outer = p.A2 + (p.A + p.A1) * cos(beta) ** 2 + (p.C + p.C1) * sin(beta) ** 2
return outer * da**2 / 2 + (p.A + p.B1) * db**2 / 2 + p.C * da * dc * sin(beta) + p.C * dc**2 / 2
Equations
The equations are those that symbolic returns for the system with its default parameters.
gyroscope.alpha: diff(alpha_gyroscope(t), t, t) == -(C_gyroscope*cos(beta_gyroscope(t))*diff(alpha_gyroscope(t), t)*diff(beta_gyroscope(t), t) - (C_gyroscope*cos(beta_gyroscope(t))*diff(gamma_gyroscope(t), t) - 2*((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)) - (C1_gyroscope + C_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)))*diff(alpha_gyroscope(t), t))*C_gyroscope*sin(beta_gyroscope(t))*diff(beta_gyroscope(t), t)/((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope))*C_gyroscope*sin(beta_gyroscope(t))/(((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope)*(C_gyroscope^2*sin(beta_gyroscope(t))^2/((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope) - C_gyroscope)) - (C_gyroscope*cos(beta_gyroscope(t))*diff(gamma_gyroscope(t), t) - 2*((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)) - (C1_gyroscope + C_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)))*diff(alpha_gyroscope(t), t))*diff(beta_gyroscope(t), t)/((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope)
gyroscope.beta: diff(beta_gyroscope(t), t, t) == (C_gyroscope*cos(beta_gyroscope(t))*diff(alpha_gyroscope(t), t)*diff(gamma_gyroscope(t), t) - ((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)) - (C1_gyroscope + C_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)))*diff(alpha_gyroscope(t), t)^2 + torque_motion)/(A_gyroscope + B1_gyroscope)
gyroscope.gamma: diff(gamma_gyroscope(t), t, t) == (C_gyroscope*cos(beta_gyroscope(t))*diff(alpha_gyroscope(t), t)*diff(beta_gyroscope(t), t) - (C_gyroscope*cos(beta_gyroscope(t))*diff(gamma_gyroscope(t), t) - 2*((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)) - (C1_gyroscope + C_gyroscope)*cos(beta_gyroscope(t))*sin(beta_gyroscope(t)))*diff(alpha_gyroscope(t), t))*C_gyroscope*sin(beta_gyroscope(t))*diff(beta_gyroscope(t), t)/((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope))/(C_gyroscope^2*sin(beta_gyroscope(t))^2/((A1_gyroscope + A_gyroscope)*cos(beta_gyroscope(t))^2 + (C1_gyroscope + C_gyroscope)*sin(beta_gyroscope(t))^2 + A2_gyroscope) - C_gyroscope)