Skip to content

Commit

Permalink
implement @mgg's codegroup and include approach
Browse files Browse the repository at this point in the history
  • Loading branch information
rennis250 committed Aug 21, 2024
1 parent 2e39a75 commit 156298f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
36 changes: 7 additions & 29 deletions alpha-lab/imu-transformations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,17 @@ readings, we can do some useful transformations.

An alternate representation of IMU data is a heading vector that points outwards from the center of the IMU. Neutral orientation of the IMU would correspond to a heading vector that points at magnetic North and that is oriented perpendicular to the line of gravity:

- **Rob Variant 1:** Write out scipy module reference in full:
::: code-group

```python
imu_neutral_heading = np.array([0.0, 1.0, 0.0])
world_rotation_matrices = scipy.spatial.transform.Rotation.from_quat(imu_quaternions).as_matrix()
headings_in_world = world_rotation_matrices @ imu_neutral_heading
```python:line-numbers {16,23,27} [imu_heading_in_world()]
<!--@include: ./pl_imu_transformations_no_comments.py{2,8}-->
```

- **Rob Variant 2:** Show conventional way to import Rotation sub-module of scipy:

```python
from scipy.spatial.transform import Rotation as R

imu_neutral_heading = np.array([0.0, 1.0, 0.0])
world_rotation_matrices = R.from_quat(imu_quaternions).as_matrix()
headings_in_world = world_rotation_matrices @ imu_neutral_heading
```

- **Rob Variant 3:** Just write the conventional way without showing the import:

```python
imu_neutral_heading = np.array([0.0, 1.0, 0.0])
world_rotation_matrices = R.from_quat(imu_quaternions).as_matrix()
headings_in_world = world_rotation_matrices @ imu_neutral_heading
```

- **Rob Variant 4:** Do it as Python-esque pseudo-code:

```python
imu_neutral_heading = np.array([0.0, 1.0, 0.0])
world_rotation_matrices = rotation_matrices_from_quaternions(imu_quaternions)
headings_in_world = world_rotation_matrices @ imu_neutral_heading
```python:line-numbers {18,25,29} [(with comments)]
<!--@include: ./pl_imu_transformations.py{2,32}-->
```
:::


## Transform IMU Acceleration Data to World Coordinates

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np
from scipy.spatial.transform import Rotation as R

def imu_heading_in_world(imu_quaternions):
imu_neutral_heading = np.array([0.0, 1.0, 0.0])
world_rotation_matrices = R.from_quat(imu_quaternions).as_matrix()
headings_in_world = world_rotation_matrices @ imu_neutral_heading
return headings_in_world

0 comments on commit 156298f

Please sign in to comment.