Latest updates to data conversion

This commit is contained in:
dario
2024-10-08 14:06:54 +02:00
parent 5479773e32
commit 86cdc18c95
14 changed files with 9803 additions and 6360 deletions

View File

@@ -32,7 +32,7 @@ class Accelerometer(Sensor):
orientation: NDArray = np.identity(3),
offset: float = 0,
transforms: List[Transform] = []):
"""_summary_
"""Accelerometer sensor base class.
Args:
dataset (Dataset): A dataset object to fetch data from.
@@ -50,30 +50,8 @@ class Accelerometer(Sensor):
self._orientation = orientation
def _get_data(self) -> ArrayLike | float:
"""
acc = self._dataset.get_acceleration('global')
self._logger.write('global_ax', acc[0], self._get_name())
self._logger.write('global_ay', acc[1], self._get_name())
self._logger.write('global_az', acc[2], self._get_name())
# Convert FL to body
acc = self._dataset.global_to_local() @ acc
acc += self._dataset.global_to_local() @ np.array([0, 0, g])
self._logger.write('local_x', acc[0], self._get_name())
self._logger.write('local_y', acc[1], self._get_name())
self._logger.write('local_z', acc[2], self._get_name())
# Rotate the acceleration vector to accomodate the accelerometer's orientation on the rocket.
acc = self._orientation @ acc
# Add the effects of the imu's offset.
omega = self._dataset.get_angular_velocity()
acc += (np.cross(omega, self._offset) + np.cross(omega, np.cross(omega, self._offset)))
"""
acc = self._dataset.get_acceleration('local')
acc += self._dataset.global_to_local() @ np.array([g, 0, 0])
return acc

View File

@@ -6,16 +6,26 @@ from numpy.typing import ArrayLike
from spatz.dataset import ArrayLike, Dataset
from spatz.logger import ArrayLike, Logger
from spatz.sensors import IMU, Accelerometer, Gyroscope, CoordSystem
from spatz.transforms import Transform, GaussianNoise
from spatz.transforms import Transform, GaussianNoise, DriftingBias
class IAM_20380HT(Gyroscope):
def __init__(self, dataset: Dataset, logger: Logger, orientation=np.identity(3), transforms: List[Transform] = []):
super().__init__(dataset, logger, orientation, transforms)
self.__bias = DriftingBias(np.zeros(3), np.array([0.00218, 0.00105, 0.00203]), 400)
self.__constant_bias = np.random.normal(0, 2, 3)
self.__normal = GaussianNoise(0, np.array([0.0049272, 0.00557833, 0.00407826]))
def _get_name(self) -> AnyStr:
return 'IAM-20380HT'
def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike:
x = (x / np.pi) * 180
t = self._dataset.get_time()
x = self.__constant_bias + self.__normal(t, self.__bias(t, x))
return x

View File

@@ -13,7 +13,7 @@ class SCA3300(Accelerometer):
def __init__(self, dataset: Dataset, logger: Logger, orientation=np.identity(3), offset=0, transforms: List[Transform] = []):
super().__init__(dataset, logger, orientation, offset, transforms)
self.__noise = GaussianNoise(0, 0.001)
self.__noise = GaussianNoise(0, 0.01)
def _get_name(self) -> AnyStr:
return 'SCA3300'

View File

@@ -34,7 +34,7 @@ class PressureSensor(Sensor):
if self._ts_effects:
# Pre-defined constants.
_p = 3e6
sigma = 40
sigma = 100
# How far away from transsonic speed (mach 1) are we?
vvec = self._dataset.get_velocity('global')

View File

@@ -39,10 +39,10 @@ class ASTOSSource(CSVSource):
super().__init__(path, 'time', interpolation)
def get_position(self) -> NDArray:
return self.fetch_values(['x', 'y', 'z'])
return self.fetch_values(['px_L', 'py_L', 'pz_L'])
def get_velocity(self, frame: Literal['global', 'local']) -> NDArray:
vel = self.fetch_values(['vx', 'vy', 'vz'])
vel = self.fetch_values(['vx_L', 'vy_L', 'vz_L'])
if frame == 'local':
return self.global_to_local() @ vel
@@ -50,10 +50,10 @@ class ASTOSSource(CSVSource):
return vel
def get_acceleration(self, frame: Literal['global', 'local']) -> NDArray:
acc = self.fetch_values(['ax', 'ay', 'az'])
if frame == 'local':
return self.global_to_local() @ acc
if frame == 'global':
acc = self.fetch_values(['ax_L', 'ay_L', 'az_L']) + np.array([-self.fetch_value('gravity'), 0, 0])
else:
acc = self.fetch_values(['ax_B', 'ay_B', 'az_B']) + self.fetch_init_values(['gx_B', 'gy_B', 'gz_B'])
return acc
@@ -69,22 +69,7 @@ class ASTOSSource(CSVSource):
pitch_l, yaw_l, roll_l = rots[0], rots[1], rots[2]
local_to_body = T1(roll_l) @ T2(pitch_l - math.pi/2) @ T1(-yaw_l)
# ASTOS global to launch rail.
init_long = self.fetch_init_value('longitude')
init_lat = self.fetch_init_value('latitude')
global_to_launch_rail = T2(-math.pi/2 - init_lat) @ T3(init_long)
# ASTOS global to local.
decl = self.fetch_value('declination')
long = self.fetch_value('longitude')
t0 = self.get_start_time()
omega_E = (2*math.pi) / (24*60*60)
global_to_local = T2(-decl) @ T3(long + omega_E * t0)
# ASTOS local to launch rail inverted
local_to_launch_rail_inv = global_to_launch_rail @ global_to_local
return local_to_body @ local_to_launch_rail_inv
return local_to_body
def get_angular_velocity(self) -> NDArray:
return self.fetch_values(['OMEGA_X', 'OMEGA_Y', 'OMEGA_Z'])