Skip to content

Commit f8d901f

Browse files
committed
Added constants, states and dataclasses for movement. Added control mechanisms (both manual and programmable). Added part of the streaming saver.
Updated ruff with more linting and fewer exceptions. Updated Requirements to match the used packages.
1 parent 8f603f3 commit f8d901f

File tree

12 files changed

+1003
-15
lines changed

12 files changed

+1003
-15
lines changed

.gitignore

Lines changed: 249 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,250 @@
1-
.ruff_cache
1+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
2+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3+
4+
# User-specific stuff
5+
.idea/**/workspace.xml
6+
.idea/**/tasks.xml
7+
.idea/**/usage.statistics.xml
8+
.idea/**/dictionaries
9+
.idea/**/shelf
10+
11+
# AWS User-specific
12+
.idea/**/aws.xml
13+
14+
# Generated files
15+
.idea/**/contentModel.xml
16+
17+
# Sensitive or high-churn files
18+
.idea/**/dataSources/
19+
.idea/**/dataSources.ids
20+
.idea/**/dataSources.local.xml
21+
.idea/**/sqlDataSources.xml
22+
.idea/**/dynamic.xml
23+
.idea/**/uiDesigner.xml
24+
.idea/**/dbnavigator.xml
25+
26+
# Gradle
27+
.idea/**/gradle.xml
28+
.idea/**/libraries
29+
30+
# Gradle and Maven with auto-import
31+
# When using Gradle or Maven with auto-import, you should exclude module files,
32+
# since they will be recreated, and may cause churn. Uncomment if using
33+
# auto-import.
34+
.idea/artifacts
35+
.idea/compiler.xml
36+
.idea/jarRepositories.xml
37+
.idea/modules.xml
38+
.idea/*.iml
39+
.idea/modules
40+
*.iml
41+
*.ipr
42+
43+
# CMake
44+
cmake-build-*/
45+
46+
# Mongo Explorer plugin
47+
.idea/**/mongoSettings.xml
48+
49+
# File-based project format
50+
*.iws
51+
52+
# IntelliJ
53+
out/
54+
55+
# mpeltonen/sbt-idea plugin
56+
.idea_modules/
57+
58+
# JIRA plugin
59+
atlassian-ide-plugin.xml
60+
61+
# Cursive Clojure plugin
62+
.idea/replstate.xml
63+
64+
# SonarLint plugin
65+
.idea/sonarlint/
66+
67+
# Crashlytics plugin (for Android Studio and IntelliJ)
68+
com_crashlytics_export_strings.xml
69+
crashlytics.properties
70+
crashlytics-build.properties
71+
fabric.properties
72+
73+
# Editor-based Rest Client
74+
.idea/httpRequests
75+
76+
# Android studio 3.1+ serialized cache file
77+
.idea/caches/build_file_checksums.ser
78+
79+
# Byte-compiled / optimized / DLL files
80+
__pycache__/
81+
*.py[cod]
82+
*$py.class
83+
84+
# C extensions
85+
*.so
86+
87+
# Distribution / packaging
88+
.Python
89+
build/
90+
develop-eggs/
91+
dist/
92+
downloads/
93+
eggs/
94+
.eggs/
95+
lib/
96+
lib64/
97+
parts/
98+
sdist/
99+
var/
100+
wheels/
101+
share/python-wheels/
102+
*.egg-info/
103+
.installed.cfg
104+
*.egg
105+
MANIFEST
106+
107+
.DS_Store
108+
.idea
109+
110+
# PyInstaller
111+
# Usually these files are written by a python script from a template
112+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
113+
*.manifest
114+
*.spec
115+
116+
# Installer model-logs
117+
pip-log.txt
118+
pip-delete-this-directory.txt
119+
120+
# Unit test / coverage reports
121+
htmlcov/
122+
.tox/
123+
.nox/
124+
.coverage
125+
.coverage.*
126+
.cache
127+
nosetests.xml
128+
coverage.xml
129+
*.cover
130+
*.py,cover
131+
.hypothesis/
132+
.pytest_cache/
133+
cover/
134+
135+
# Translations
136+
*.mo
137+
*.pot
138+
139+
# Django stuff:
140+
*.log
141+
local_settings.py
142+
db.sqlite3
143+
db.sqlite3-journal
144+
145+
# Flask stuff:
146+
instance/
147+
.webassets-cache
148+
149+
# Scrapy stuff:
150+
.scrapy
151+
152+
# Sphinx documentation
153+
docs/_build/
154+
155+
# PyBuilder
156+
.pybuilder/
157+
target/
158+
159+
# Jupyter Notebook
160+
.ipynb_checkpoints
161+
162+
# IPython
163+
profile_default/
164+
ipython_config.py
165+
166+
# pyenv
167+
# For a library or package, you might want to ignore these files since the code is
168+
# intended to run in multiple environments; otherwise, check them in:
169+
# .python-version
170+
171+
# pipenv
172+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
173+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
174+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
175+
# install all needed dependencies.
176+
#Pipfile.lock
177+
178+
# poetry
179+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
180+
# This is especially recommended for binary packages to ensure reproducibility, and is more
181+
# commonly ignored for libraries.
182+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
183+
#poetry.lock
184+
185+
# pdm
186+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
187+
#pdm.lock
188+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
189+
# in version control.
190+
# https://pdm.fming.dev/#use-with-ide
191+
.pdm.toml
192+
193+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
194+
__pypackages__/
195+
196+
# Celery stuff
197+
celerybeat-schedule
198+
celerybeat.pid
199+
200+
# SageMath parsed files
201+
*.sage.py
202+
203+
# Environments
204+
.env
2205
.venv
3-
__pycache__
206+
env/
207+
venv/
208+
ENV/
209+
env.bak/
210+
venv.bak/
211+
gpu-env/
212+
213+
# Spyder project settings
214+
.spyderproject
215+
.spyproject
216+
217+
# Rope project settings
218+
.ropeproject
219+
220+
# mkdocs documentation
221+
/site
222+
223+
# mypy
224+
.mypy_cache/
225+
.dmypy.json
226+
dmypy.json
227+
228+
# Pyre type checker
229+
.pyre/
230+
231+
# pytype static type analyzer
232+
.pytype/
233+
234+
# Cython debug symbols
235+
cython_debug/
236+
237+
# Git Files
238+
*.patch
239+
240+
# Python generated files and user files
241+
*.h5
242+
*.MP4
243+
*.mp4
244+
*.ckpt
245+
*.pt
246+
*.pth
247+
*.stats
248+
logs/
249+
results/
250+
.ruff_cache

main/config/drone.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from dataclasses import dataclass, field
2+
from enum import Enum
3+
4+
5+
class DroneIp(str, Enum):
6+
SIMULATED = "10.202.0.1"
7+
CABLE = "192.168.53.1"
8+
WIRELESS = "192.168.42.1"
9+
10+
def __str__(self) -> str:
11+
return self.value
12+
13+
14+
class GimbalType(str, Enum):
15+
REF_ABSOLUTE = "absolute"
16+
REF_RELATIVE = "relative"
17+
MODE_POSITION = "position"
18+
MODE_VELOCITY = "velocity"
19+
20+
def __str__(self) -> str:
21+
return self.value
22+
23+
24+
@dataclass(frozen=True)
25+
class DroneSpeed:
26+
"""
27+
Configuration class for drone piloting commands.
28+
29+
All values for x, y, z and z_rot must be positive and less than or equal to 100, where:
30+
- x (roll): represents translation left (negative) and right (positive) on X axis .
31+
- y (pitch): represents translation forwards (positive) and backwards (negative) on Y axis.
32+
- z (yaw): represents translation upwards (positive) and backwards (negative) on Z axis.
33+
- z_rot (gaz): represents rotation around Z axis (rotation on Yaw), left (negative) and right (positive).
34+
35+
The sign of the values for x, y, and z and z_rot are the responsibility of the user of this class.
36+
37+
Time step dt (piloting_time) is in seconds and must be a positive float.
38+
"""
39+
x: int = field(default=20, metadata={"range": (0, 100)})
40+
y: int = field(default=20, metadata={"range": (0, 100)})
41+
z: int = field(default=20, metadata={"range": (0, 100)})
42+
z_rot: int = field(default=20, metadata={"range": (0, 100)})
43+
dt: float = field(default=0.1)
44+
45+
def __post_init__(self):
46+
dt_value = getattr(self, "dt")
47+
if dt_value < 0:
48+
raise ValueError(f"Time step must be positive, got \"{dt_value}\" instead")
49+
for attr in ("x", "y", "z", "z_rot"):
50+
value = getattr(self, attr)
51+
if not (0 <= value <= 100): # noqa: PLR2004
52+
raise ValueError(f"{attr} must be between [0, 100], got \"{value}\" instead")

main/config/logger.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import logging
2+
import sys
3+
from logging.handlers import RotatingFileHandler
4+
from pathlib import Path
5+
from typing import Final
6+
7+
8+
class LoggerSetup:
9+
LEVEL_WIDTH: Final[int] = 8
10+
11+
@staticmethod
12+
def setup_logger(
13+
logger_name: str,
14+
log_file: str | Path | None = None,
15+
level: int = logging.DEBUG,
16+
console_level: int = logging.INFO,
17+
file_level: int = logging.DEBUG
18+
) -> logging.Logger:
19+
"""
20+
Set up a logger with both console and file handlers.
21+
22+
@param logger_name: Name of the logger.
23+
@param log_file: Optional path to log file. If None, only console logging is set.
24+
@param level: Overall logging level.
25+
@param console_level: Logging level for console output.
26+
@param file_level: Logging level for file output.
27+
@return: Configured logger instance.
28+
"""
29+
logger = logging.getLogger(logger_name)
30+
logger.setLevel(level)
31+
logger.handlers.clear()
32+
33+
console_formatter = logging.Formatter(
34+
f'%(asctime)s - [%(levelname)-{LoggerSetup.LEVEL_WIDTH:d}s] - %(name)s - '
35+
f'[%(filename)s:%(lineno)d] - %(message)s'
36+
)
37+
file_formatter = logging.Formatter(
38+
f'%(asctime)s - [%(levelname)-{LoggerSetup.LEVEL_WIDTH:d}s] - %(name)s - [%(filename)s:%(lineno)d] - '
39+
f'[Thread: %(threadName)s | PID: %(process)d] - %(message)s'
40+
)
41+
42+
console_handler = logging.StreamHandler(sys.stdout)
43+
console_handler.setLevel(console_level)
44+
console_handler.setFormatter(console_formatter)
45+
logger.addHandler(console_handler)
46+
47+
if log_file:
48+
log_path = Path(log_file)
49+
log_path.parent.mkdir(parents=True, exist_ok=True)
50+
51+
file_handler = RotatingFileHandler(log_file, maxBytes=5 * 1024 * 1024, backupCount=5)
52+
file_handler.setLevel(file_level)
53+
file_handler.setFormatter(file_formatter)
54+
logger.addHandler(file_handler)
55+
56+
return logger

0 commit comments

Comments
 (0)