From 6e1ea6ec1d67af7cc8240007177488ac4cbd8850 Mon Sep 17 00:00:00 2001 From: Gavin Furtado Date: Thu, 1 Feb 2024 12:42:47 +0000 Subject: [PATCH] Documentation of electronic_sensor and constants modules --- Phase 2/filter_py_lib_test/constants.py | 32 ++++++++- .../filter_py_lib_test/electronic_sensors.py | 68 +++++++++++++++++-- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Phase 2/filter_py_lib_test/constants.py b/Phase 2/filter_py_lib_test/constants.py index 28988c3..d45a294 100644 --- a/Phase 2/filter_py_lib_test/constants.py +++ b/Phase 2/filter_py_lib_test/constants.py @@ -1,10 +1,40 @@ ''' -This module constists of constants across all modules +Module name +----------- +constants + +Module Summary +-------------- +This module is a collection of constants that are used across all modules in this project. + +Constants +--------- +1. dt(float): The time interval between two measurements in seconds. + +Usage +----- +This module is the central location to store all the important constant +data. You can change and control all the contants by changing it here +and it will reflect in all the modules you used it. This helps in maintianing +synchronicity across the simulation. + +Example +------- +To use this time interval in other modules, follow the example below +```python +from constants import dt + +# Python code using dt constant +sensor = es.PositionSensor(noise_mean=0.5, noise_std=1.5, dt=dt ,sample_size=50) + +```python Author ------ Gavin Furtado +Role +----- AOCS Engineer ''' diff --git a/Phase 2/filter_py_lib_test/electronic_sensors.py b/Phase 2/filter_py_lib_test/electronic_sensors.py index fe60940..aadcda6 100644 --- a/Phase 2/filter_py_lib_test/electronic_sensors.py +++ b/Phase 2/filter_py_lib_test/electronic_sensors.py @@ -1,15 +1,38 @@ ''' +Modue name +---------- +electronic_sensor + +Module summary +-------------- Module that simulates a real world electronic sensor +Usage +----- +This module is used to generate a functional model the real world sensors +such as accelerometer and gyroscope. +You will be able to obtain a dataset of the measurements of respective sensors. + +Example +------- +Here is an example of how to use this module in projects. +```python +import sensor as sn + +sensor = sn.PositionSensor(noise_mean=0.2, noise_std=1.5, dt=1,sample_size=50) +position, velocity, acceleration, noise = sensor.data_set() +```python + Author ------ Gavin Furtado +Role +---- AOCS Engineer ''' import numpy as np -## A model of real world object: electronic sensor class PositionSensor(object): ''' Represent a real world position sensor/accelerometer that @@ -51,6 +74,8 @@ class PositionSensor(object): Example ------- + Here is an example of how to use this module in projects. + ```python import sensor as sn sensor = sn.PositionSensor(noise_mean=0.2, noise_std=1.5, dt=1,sample_size=50) @@ -60,6 +85,19 @@ class PositionSensor(object): def __init__(self, initial_position=(0.,0.), initial_velocity=(0.,0.), acceleration=(0.2,0.09),dt=0., noise_mean=0., noise_std=0., sample_size=0) -> None: + ''' + Intitalisation function of the class Position Sensor + + Attributes + ---------- + position : array + velocity : array + acceleration : array + dt : array + noise_mean : float + noise_std : float + sample_size : int + ''' self.position = np.array(initial_position) self.velocity = np.array(initial_velocity) self.acceleration = np.array(acceleration) @@ -69,6 +107,21 @@ def __init__(self, initial_position=(0.,0.), initial_velocity=(0.,0.), self.sample_size = sample_size def read(self): + ''' + Summary + ------- + This functions measures the position, velocity and + acceleration of the object. + + Parameters + ----------- + None + + Returns + ------- + position, velocity, acceleration, noise + Single 2-Dimensional arrays + ''' self.velocity += self.acceleration*self.dt self.position += self.velocity*self.dt @@ -81,6 +134,7 @@ def read(self): def data_set(self): ''' + Creates a data set of position, velocity, acceleration and noise. Parameters @@ -89,10 +143,14 @@ def data_set(self): Returns ------- - postion_data : 2-Dim array - velocity_data : 2-Dim array - acceleration_data : 2-Dim array - noise_data : 2-Dim array + postion_data : An array of 2-Dimensional arrays + Array containing X and Y position coordinates. + velocity_data : An array of 2-Dimensional arrays + Array containing X and Y velocities. + acceleration_data : An array of 2-Dimensional arrays + Array containing X and Y accelerations. + noise_data : An array of 2-Dimensional arrays + Array containing Gaussian noise. ''' position_data = np.zeros([self.sample_size,2]) velocity_data = np.zeros([self.sample_size,2])