```python
from sympy import *
init_printing()
```


```python
th1, th2, th3 = symbols('theta_1, theta_2, theta_3')
dcm_321 = Matrix([[cos(th1)*cos(th2),
         cos(th1)*sin(th2)*sin(th3) - sin(th1)*cos(th3),
         cos(th1)*sin(th2)*cos(th3) + sin(th1)*sin(th3)],
        [sin(th1)*cos(th2),
         sin(th1)*sin(th2)*sin(th3) + cos(th1)*cos(th3),
         sin(th1)*sin(th2)*cos(th3) - cos(th1)*sin(th3)],
        [-sin(th2),
        cos(th2)*sin(th3),
        cos(th2)*cos(th3)]
    ])
dcm_321
```


```python
phi, theta, psi = symbols('phi, theta, psi')
sub_eulers = {
    th1: psi, th2: theta, th3: phi
}
dcm_321_euler = dcm_321.subs(sub_eulers)
dcm_321_euler
```


```python
dcm_pitch_up = dcm_321_euler.subs({theta:pi/2, phi:0})
dcm_pitch_up
```


```python
atan2(dcm_pitch_up[1,2], dcm_pitch_up[0,2])
```


```python
dcm_pitch_down = dcm_321_euler.subs({theta:pi/2, phi:0})
dcm_pitch_down
```


```python
dcm_pitch_down = dcm_321_euler.subs({theta:-pi/2, phi:0})
atan2(-dcm_pitch_down[1,2], -dcm_pitch_down[0,2])
```

9131c84848cd10b807ac36506962c8aa7b650a6b
ipynb
Jupyter Notebook
src/lib/matrix/doc/euler_gimbal_lock.ipynb
shening/PX4-1.34-Vision-Fix
1e696bc1c2dae71ba7b277d40106a5b6c0a1a050
BSD-3-Clause
2016-08-13T11:26:51.000Z
2022-02-17T08:45:40.000Z
src/lib/matrix/doc/euler_gimbal_lock.ipynb
shening/PX4-1.34-Vision-Fix
1e696bc1c2dae71ba7b277d40106a5b6c0a1a050
BSD-3-Clause
2020-11-03T14:09:51.000Z
2021-10-07T09:09:53.000Z
src/lib/matrix/doc/euler_gimbal_lock.ipynb
shening/PX4-1.34-Vision-Fix
1e696bc1c2dae71ba7b277d40106a5b6c0a1a050
BSD-3-Clause
2016-08-15T14:00:44.000Z
2022-02-17T08:45:41.000Z
Qwen/Qwen-72B
1. YES
2. YES