|
| 1 | +--- |
| 2 | +title: IMU |
| 3 | +description: Reading orientation with NextIMU |
| 4 | +sidebar: |
| 5 | + order: 5 |
| 6 | +--- |
| 7 | + |
| 8 | +import { Tabs, TabItem } from '@astrojs/starlight/components'; |
| 9 | + |
| 10 | +`NextIMU` is a wrapper for the Control Hub or an `IMU` that uses lazy initialization. |
| 11 | + |
| 12 | +## Creating a NextIMU |
| 13 | + |
| 14 | +<Tabs syncKey="language"> |
| 15 | +<TabItem label="Kotlin"> |
| 16 | +```kotlin |
| 17 | +val imu = NextIMU() // Defaults to the configuration name "imu" |
| 18 | + |
| 19 | +val imu = NextIMU("imu") // Using a custom configuration name |
| 20 | +``` |
| 21 | +</TabItem> |
| 22 | +<TabItem label="Java"> |
| 23 | +```java |
| 24 | +NextIMU imu = new NextIMU(); // Defaults to the configuration name "imu" |
| 25 | + |
| 26 | +NextIMU imu = new NextIMU("imu"); // Using a custom configuration name |
| 27 | +``` |
| 28 | +</TabItem> |
| 29 | +</Tabs> |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### `initialize(parameters)` |
| 34 | + |
| 35 | +Initializes the IMU with the given `IMU.Parameters`, such as the hub's mounting orientation. |
| 36 | + |
| 37 | +<Tabs syncKey="language"> |
| 38 | +<TabItem label="Kotlin"> |
| 39 | +```kotlin |
| 40 | +imu.initialize(IMU.Parameters(RevHubOrientationOnRobot(LogoFacingDirection.UP, UsbFacingDirection.FORWARD))) |
| 41 | +``` |
| 42 | +</TabItem> |
| 43 | +<TabItem label="Java"> |
| 44 | +```java |
| 45 | +imu.initialize(new IMU.Parameters(new RevHubOrientationOnRobot(LogoFacingDirection.UP, UsbFacingDirection.FORWARD))); |
| 46 | +``` |
| 47 | +</TabItem> |
| 48 | +</Tabs> |
| 49 | + |
| 50 | +### `resetYaw()` |
| 51 | + |
| 52 | +Resets the yaw angle to zero. |
| 53 | + |
| 54 | +<Tabs syncKey="language"> |
| 55 | +<TabItem label="Kotlin"> |
| 56 | +```kotlin |
| 57 | +imu.resetYaw() |
| 58 | +``` |
| 59 | +</TabItem> |
| 60 | +<TabItem label="Java"> |
| 61 | +```java |
| 62 | +imu.resetYaw(); |
| 63 | +``` |
| 64 | +</TabItem> |
| 65 | +</Tabs> |
| 66 | + |
| 67 | +### `angularVelocity` |
| 68 | + |
| 69 | +`AngularVelocity` the robot's current angular velocity, in radians per second. |
| 70 | + |
| 71 | +<Tabs syncKey="language"> |
| 72 | +<TabItem label="Kotlin"> |
| 73 | +```kotlin |
| 74 | +val turnRate = imu.angularVelocity |
| 75 | +``` |
| 76 | +</TabItem> |
| 77 | +<TabItem label="Java"> |
| 78 | +```java |
| 79 | +AngularVelocity turnRate = imu.getAngularVelocity(); |
| 80 | +``` |
| 81 | +</TabItem> |
| 82 | +</Tabs> |
0 commit comments