-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb17602
commit 0687045
Showing
2 changed files
with
23 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
| File: imu.py | ||
| Author: Marcelo Jacinto ([email protected]) | ||
| License: BSD-3-Clause. Copyright (c) 2023, Marcelo Jacinto. All rights reserved. | ||
| Description: Simulates an imu. Based on the implementation provided in PX4 stil_gazebo (https://github.com/PX4/PX4-SITL_gazebo) | ||
| Description: Simulates an imu. Based on the implementation provided in PX4 stil_gazebo | ||
(https://github.com/PX4/PX4-SITL_gazebo) | ||
""" | ||
__all__ = ["IMU"] | ||
|
||
|
@@ -18,11 +19,12 @@ | |
class IMU(Sensor): | ||
"""The class that implements the IMU sensor. This class inherits the base class Sensor. | ||
""" | ||
def __init__(self, config={}): | ||
def __init__(self, config=None): | ||
"""Initialize the IMU class | ||
Args: | ||
config (dict): A Dictionary that contains all teh parameters for configuring the IMU - it can be empty or only have some of the parameters used by the IMU. | ||
config (dict): A Dictionary that contains all teh parameters for configuring the IMU - it can be empty or | ||
only have some of the parameters used by the IMU. | ||
Examples: | ||
The dictionary default parameters are | ||
|
@@ -82,12 +84,13 @@ def state(self): | |
|
||
@Sensor.update_at_rate | ||
def update(self, state: State, dt: float): | ||
"""Method that implements the logic of an IMU. In this method we start by generating the random walk of the | ||
gyroscope. This value is then added to the real angular velocity of the vehicle (FLU relative to ENU inertial frame | ||
expressed in FLU body frame). The same logic is followed for the accelerometer and the accelerations. After this step, | ||
the angular velocity is rotated such that it expressed a FRD body frame, relative to a NED inertial frame, expressed | ||
in the FRD body frame. Additionally, the acceleration is also rotated, such that it becomes expressed in the body | ||
FRD frame of the vehicle. This sensor outputs data that follows the PX4 adopted standard. | ||
"""Method that implements the logic of an IMU. In this method we start by generating the random walk of the | ||
gyroscope. This value is then added to the real angular velocity of the vehicle (FLU relative to ENU inertial | ||
frame expressed in FLU body frame). The same logic is followed for the accelerometer and the accelerations. | ||
After this step, the angular velocity is rotated such that it expressed a FRD body frame, relative to a NED | ||
inertial frame, expressed in the FRD body frame. Additionally, the acceleration is also rotated, such that it | ||
becomes expressed in the body FRD frame of the vehicle. This sensor outputs data that follows the PX4 adopted | ||
standard. | ||
Args: | ||
state (State): The current state of the vehicle. | ||
|
@@ -117,10 +120,10 @@ def update(self, state: State, dt: float): | |
self._gyroscope_bias[i] = phi_g_d * self._gyroscope_bias[i] + sigma_b_g_d * np.random.randn() | ||
angular_velocity[i] = state.angular_velocity[i] + sigma_g_d * np.random.randn() + self._gyroscope_bias[i] | ||
|
||
# Accelerometer terms | ||
# Accelerometer terms. | ||
tau_a: float = self._accelerometer_bias_correlation_time | ||
|
||
# Discrete-time standard deviation equivalent to an "integrating" sampler with integration time dt | ||
# Discrete-time standard deviation equivalent to an "integrating" sampler with integration time dt. | ||
sigma_a_d: float = 1.0 / np.sqrt(dt) * self._accelerometer_noise_density | ||
sigma_b_a: float = self._accelerometer_random_walk | ||
|
||
|
@@ -130,14 +133,16 @@ def update(self, state: State, dt: float): | |
# Compute state-transition. | ||
phi_a_d: float = np.exp(-1.0 / tau_a * dt) | ||
|
||
# Compute the linear acceleration from diferentiating the velocity of the vehicle expressed in the inertial frame | ||
# Compute the linear acceleration from diferentiating the velocity of the vehicle expressed in the inertial | ||
# frame. | ||
linear_acceleration_inertial = (state.linear_velocity - self._prev_linear_velocity) / dt | ||
linear_acceleration_inertial = linear_acceleration_inertial - GRAVITY_VECTOR | ||
|
||
# Update the previous linear velocity for the next computation | ||
self._prev_linear_velocity = state.linear_velocity | ||
|
||
# Compute the linear acceleration of the body frame, with respect to the inertial frame, expressed in the body frame | ||
# Compute the linear acceleration of the body frame, with respect to the inertial frame, expressed in the body | ||
# frame. | ||
linear_acceleration = np.array(Rotation.from_quat(state.attitude).inv().apply(linear_acceleration_inertial)) | ||
|
||
# Simulate the accelerometer noise processes and add them to the true linear aceleration values | ||
|