mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
Current state of the simulation
This commit is contained in:
parent
828af75fe3
commit
dedd445470
2
setup.py
2
setup.py
@ -8,7 +8,7 @@ with open('README.md', 'r') as f:
|
|||||||
setup(
|
setup(
|
||||||
name='spatz',
|
name='spatz',
|
||||||
version='0.0.10',
|
version='0.0.10',
|
||||||
packages=find_packages(exclude=["_tests"]),
|
packages=['spatz'],
|
||||||
long_description=longdescription,
|
long_description=longdescription,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
)
|
)
|
@ -1,10 +1,12 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
from typing import List, AnyStr
|
from typing import List, AnyStr
|
||||||
|
|
||||||
from numpy.typing import ArrayLike
|
from numpy.typing import ArrayLike
|
||||||
from spatz.dataset import ArrayLike, Dataset
|
from spatz.dataset import ArrayLike, Dataset
|
||||||
from spatz.logger import ArrayLike, Logger
|
from spatz.logger import ArrayLike, Logger
|
||||||
from spatz.sensors import IMU, Accelerometer, Gyroscope
|
from spatz.sensors import IMU, Accelerometer, Gyroscope
|
||||||
from spatz.transforms import Transform
|
from spatz.transforms import Transform, GaussianNoise
|
||||||
|
|
||||||
|
|
||||||
class BHI160Gyro(Gyroscope):
|
class BHI160Gyro(Gyroscope):
|
||||||
@ -27,8 +29,10 @@ class BHI160Acc(Accelerometer):
|
|||||||
def __init__(self, dataset: Dataset, logger: Logger, offset: float = 0, transforms: List[Transform] = []):
|
def __init__(self, dataset: Dataset, logger: Logger, offset: float = 0, transforms: List[Transform] = []):
|
||||||
super().__init__(dataset, logger, offset, transforms)
|
super().__init__(dataset, logger, offset, transforms)
|
||||||
|
|
||||||
|
self.__noise = GaussianNoise(0, 0.05)
|
||||||
|
|
||||||
def _get_name(self) -> AnyStr:
|
def _get_name(self) -> AnyStr:
|
||||||
return 'BHI160'
|
return 'BHI160'
|
||||||
|
|
||||||
def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike:
|
def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike:
|
||||||
return x
|
return self.__noise(0, x)
|
@ -13,15 +13,25 @@ class GaussianNoise(Transform):
|
|||||||
self.__mu = mu
|
self.__mu = mu
|
||||||
self.__sigma = sigma
|
self.__sigma = sigma
|
||||||
|
|
||||||
def __call__(self, t: float, x: ArrayLike) -> ArrayLike:
|
def __call__(self, _: float, x: ArrayLike) -> ArrayLike:
|
||||||
assert np.shape(self.__mu) == np.shape(x), "Mu and x have to match in shape."
|
|
||||||
|
|
||||||
if np.isscalar(x):
|
if np.isscalar(x):
|
||||||
noise = np.random.normal(0, 1)
|
noise = np.random.normal(0, 1)
|
||||||
x += self.__sigma * noise + self.__mu
|
x += self.__sigma * noise + self.__mu
|
||||||
else:
|
else:
|
||||||
|
dim = len(x)
|
||||||
|
|
||||||
|
if np.isscalar(self.__sigma):
|
||||||
|
sigma = np.identity(dim) * self.__sigma
|
||||||
|
else:
|
||||||
|
sigma = self.__sigma
|
||||||
|
|
||||||
|
if np.isscalar(self.__mu):
|
||||||
|
mu = np.ones(dim)
|
||||||
|
else:
|
||||||
|
mu = self.__mu
|
||||||
|
|
||||||
noise = np.random.normal(0, 1, np.shape(x))
|
noise = np.random.normal(0, 1, np.shape(x))
|
||||||
x += self.__sigma @ noise + self.__mu
|
x += sigma @ noise + mu
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
36
tests.ipynb
36
tests.ipynb
@ -631,7 +631,7 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"[<matplotlib.lines.Line2D at 0x24cf15adfa0>]"
|
"[<matplotlib.lines.Line2D at 0x28b3b18fc20>]"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 13,
|
"execution_count": 13,
|
||||||
@ -819,7 +819,27 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 16,
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"7.767031884916352"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"max(np.array(acc_total) / g)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -839,7 +859,7 @@
|
|||||||
"Name: altitude, Length: 1721, dtype: float64"
|
"Name: altitude, Length: 1721, dtype: float64"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 16,
|
"execution_count": 17,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -850,7 +870,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 17,
|
"execution_count": 18,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -859,7 +879,7 @@
|
|||||||
"19335.3982925117"
|
"19335.3982925117"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 17,
|
"execution_count": 18,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -870,7 +890,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 18,
|
"execution_count": 19,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -890,7 +910,7 @@
|
|||||||
"Name: Time, Length: 1721, dtype: float64"
|
"Name: Time, Length: 1721, dtype: float64"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 18,
|
"execution_count": 19,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -901,7 +921,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 19,
|
"execution_count": 20,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user