Skip to content

Commit

Permalink
Documentation of electronic_sensor and constants modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Furtado committed Feb 1, 2024
1 parent 7a9b438 commit 6e1ea6e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 6 deletions.
32 changes: 31 additions & 1 deletion Phase 2/filter_py_lib_test/constants.py
Original file line number Diff line number Diff line change
@@ -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
'''

Expand Down
68 changes: 63 additions & 5 deletions Phase 2/filter_py_lib_test/electronic_sensors.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -81,6 +134,7 @@ def read(self):

def data_set(self):
'''
Creates a data set of position, velocity, acceleration and noise.
Parameters
Expand All @@ -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])
Expand Down

0 comments on commit 6e1ea6e

Please sign in to comment.