diff --git a/setup.py b/setup.py index 47647ec..52ce31c 100644 --- a/setup.py +++ b/setup.py @@ -13,9 +13,9 @@ package_dir={"": "src"}, package_data={ "isar_turtlebot": [ - "settings/maps/turtleworld.json", - "settings/maps/klab_turtlebot_old.json", - "settings/maps/klab_turtlebot.json", + "config/maps/turtleworld.json", + "config/maps/klab_turtlebot_old.json", + "config/maps/klab_turtlebot.json", "config/settings.env", ] }, diff --git a/src/isar_turtlebot/config/__init__.py b/src/isar_turtlebot/config/__init__.py index e69de29..45c4086 100644 --- a/src/isar_turtlebot/config/__init__.py +++ b/src/isar_turtlebot/config/__init__.py @@ -0,0 +1 @@ +from isar_turtlebot.config.settings import settings diff --git a/src/isar_turtlebot/settings/maps/klab_turtlebot.json b/src/isar_turtlebot/config/maps/klab_turtlebot.json similarity index 100% rename from src/isar_turtlebot/settings/maps/klab_turtlebot.json rename to src/isar_turtlebot/config/maps/klab_turtlebot.json diff --git a/src/isar_turtlebot/settings/maps/klab_turtlebot_old.json b/src/isar_turtlebot/config/maps/klab_turtlebot_old.json similarity index 100% rename from src/isar_turtlebot/settings/maps/klab_turtlebot_old.json rename to src/isar_turtlebot/config/maps/klab_turtlebot_old.json diff --git a/src/isar_turtlebot/settings/maps/turtleworld.json b/src/isar_turtlebot/config/maps/turtleworld.json similarity index 100% rename from src/isar_turtlebot/settings/maps/turtleworld.json rename to src/isar_turtlebot/config/maps/turtleworld.json diff --git a/src/isar_turtlebot/config/settings.env b/src/isar_turtlebot/config/settings.env index ff32d65..9d50883 100644 --- a/src/isar_turtlebot/config/settings.env +++ b/src/isar_turtlebot/config/settings.env @@ -1,2 +1,4 @@ CAPABILITIES = '["take_thermal_image","take_image","drive_to_pose"]' ROBOT_MODEL = Turtlebot + +TURTLEBOT_MAP = klab_turtlebot diff --git a/src/isar_turtlebot/settings/settings.py b/src/isar_turtlebot/config/settings.py similarity index 50% rename from src/isar_turtlebot/settings/settings.py rename to src/isar_turtlebot/config/settings.py index 2e79073..e113a04 100644 --- a/src/isar_turtlebot/settings/settings.py +++ b/src/isar_turtlebot/config/settings.py @@ -1,7 +1,18 @@ -from pydantic import BaseSettings, Field +import importlib.resources as pkg_resources + +from pydantic import Field +from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): + def __init__(self) -> None: + try: + with pkg_resources.path(f"isar_turtlebot.config", "settings.env") as path: + env_file_path = path + except ModuleNotFoundError: + env_file_path = None + super().__init__(_env_file=env_file_path) + IMAGE_FILETYPE: str = Field(default="jpg") THERMAL_IMAGE_FILETYPE: str = Field(default="png") @@ -17,8 +28,11 @@ class Settings(BaseSettings): LOGGER_NAME: str = Field(default="isar_turtlebot") - class Config: - env_prefix = "ISAR_TURTLEBOT_" + model_config = SettingsConfigDict( + env_prefix="ISAR_TURTLEBOT_", + env_file_encoding="utf-8", + case_sensitive=True, + ) settings = Settings() diff --git a/src/isar_turtlebot/robotinterface.py b/src/isar_turtlebot/robotinterface.py index ae1cc72..2810b2a 100644 --- a/src/isar_turtlebot/robotinterface.py +++ b/src/isar_turtlebot/robotinterface.py @@ -15,8 +15,8 @@ from robot_interface.robot_interface import RobotInterface from robot_interface.telemetry.mqtt_client import MqttTelemetryPublisher +from isar_turtlebot.config import settings from isar_turtlebot.ros_bridge.ros_bridge import RosBridge, RosBridgeInterface -from isar_turtlebot.settings import settings from isar_turtlebot.turtlebot import Turtlebot @@ -25,7 +25,7 @@ def __init__(self, bridge: RosBridgeInterface = RosBridge): map_alignment: MapAlignment = MapAlignment.from_config( Path( os.path.dirname(os.path.realpath(__file__)), - f"settings/maps/{settings.TURTLEBOT_MAP}.json", + f"config/maps/{settings.TURTLEBOT_MAP}.json", ) ) transform: Transform = align_maps( diff --git a/src/isar_turtlebot/ros_bridge/ros_bridge.py b/src/isar_turtlebot/ros_bridge/ros_bridge.py index 9bf2f4a..d95159d 100644 --- a/src/isar_turtlebot/ros_bridge/ros_bridge.py +++ b/src/isar_turtlebot/ros_bridge/ros_bridge.py @@ -7,8 +7,8 @@ ) from roslibpy import Ros +from isar_turtlebot.config import settings from isar_turtlebot.ros_bridge.topic import ImageTopic, Topic -from isar_turtlebot.settings import settings class RosBridgeInterface(ABC): diff --git a/src/isar_turtlebot/ros_bridge/topic.py b/src/isar_turtlebot/ros_bridge/topic.py index 27c243c..b12c55b 100644 --- a/src/isar_turtlebot/ros_bridge/topic.py +++ b/src/isar_turtlebot/ros_bridge/topic.py @@ -10,7 +10,7 @@ from roslibpy import Message, Ros from roslibpy import Topic as RosTopic -from isar_turtlebot.settings import settings +from isar_turtlebot.config import settings class TopicInterface(ABC): diff --git a/src/isar_turtlebot/settings/__init__.py b/src/isar_turtlebot/settings/__init__.py deleted file mode 100644 index f9c5a7c..0000000 --- a/src/isar_turtlebot/settings/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from isar_turtlebot.settings.settings import settings diff --git a/src/isar_turtlebot/settings/settings.env b/src/isar_turtlebot/settings/settings.env deleted file mode 100644 index b80e46c..0000000 --- a/src/isar_turtlebot/settings/settings.env +++ /dev/null @@ -1 +0,0 @@ -TURTLEBOT_MAP = klab_turtlebot diff --git a/src/isar_turtlebot/turtlebot/step_handlers/driveto.py b/src/isar_turtlebot/turtlebot/step_handlers/driveto.py index 8041378..a801003 100644 --- a/src/isar_turtlebot/turtlebot/step_handlers/driveto.py +++ b/src/isar_turtlebot/turtlebot/step_handlers/driveto.py @@ -9,9 +9,9 @@ ) from robot_interface.models.mission.step import DriveToPose +from isar_turtlebot.config import settings from isar_turtlebot.models.turtlebot_status import Status from isar_turtlebot.ros_bridge.ros_bridge import RosBridge -from isar_turtlebot.settings import settings from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler from isar_turtlebot.utilities.pose_message import encode_pose_message diff --git a/src/isar_turtlebot/turtlebot/step_handlers/stephandler.py b/src/isar_turtlebot/turtlebot/step_handlers/stephandler.py index a10d45e..188a1d2 100644 --- a/src/isar_turtlebot/turtlebot/step_handlers/stephandler.py +++ b/src/isar_turtlebot/turtlebot/step_handlers/stephandler.py @@ -5,8 +5,8 @@ from robot_interface.models.exceptions.robot_exceptions import RobotAPIException from robot_interface.models.mission.step import Step +from isar_turtlebot.config import settings from isar_turtlebot.models.turtlebot_status import Status -from isar_turtlebot.settings import settings class StepHandler(ABC): diff --git a/src/isar_turtlebot/turtlebot/step_handlers/takeimage.py b/src/isar_turtlebot/turtlebot/step_handlers/takeimage.py index ab3776d..c40d362 100644 --- a/src/isar_turtlebot/turtlebot/step_handlers/takeimage.py +++ b/src/isar_turtlebot/turtlebot/step_handlers/takeimage.py @@ -12,15 +12,12 @@ RobotCommunicationException, RobotInfeasibleStepException, ) -from robot_interface.models.inspection.inspection import ( - Image, - ImageMetadata, -) +from robot_interface.models.inspection.inspection import Image, ImageMetadata from robot_interface.models.mission.step import TakeImage +from isar_turtlebot.config import settings from isar_turtlebot.models.turtlebot_status import Status from isar_turtlebot.ros_bridge.ros_bridge import RosBridge -from isar_turtlebot.settings import settings from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler from isar_turtlebot.utilities.inspection_pose import get_inspection_pose from isar_turtlebot.utilities.pose_message import ( diff --git a/src/isar_turtlebot/turtlebot/step_handlers/takethermalimage.py b/src/isar_turtlebot/turtlebot/step_handlers/takethermalimage.py index 581d129..7f1b99f 100644 --- a/src/isar_turtlebot/turtlebot/step_handlers/takethermalimage.py +++ b/src/isar_turtlebot/turtlebot/step_handlers/takethermalimage.py @@ -8,8 +8,8 @@ from typing import Optional from uuid import uuid4 -import PIL.Image as PILImage import numpy as np +import PIL.Image as PILImage from alitra import Pose, Position, Transform from robot_interface.models.exceptions.robot_exceptions import ( RobotCommunicationException, @@ -21,9 +21,9 @@ ) from robot_interface.models.mission.step import TakeThermalImage +from isar_turtlebot.config import settings from isar_turtlebot.models.turtlebot_status import Status from isar_turtlebot.ros_bridge.ros_bridge import RosBridge -from isar_turtlebot.settings import settings from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler from isar_turtlebot.utilities.inspection_pose import get_inspection_pose from isar_turtlebot.utilities.pose_message import ( diff --git a/src/isar_turtlebot/turtlebot/turtlebot.py b/src/isar_turtlebot/turtlebot/turtlebot.py index 0a4e626..072560f 100644 --- a/src/isar_turtlebot/turtlebot/turtlebot.py +++ b/src/isar_turtlebot/turtlebot/turtlebot.py @@ -11,7 +11,6 @@ RobotRetrieveInspectionException, RobotTelemetryException, ) - from robot_interface.models.inspection.inspection import Inspection from robot_interface.models.mission.status import StepStatus from robot_interface.models.mission.step import InspectionStep, Step @@ -21,9 +20,9 @@ ) from robot_interface.utilities.json_service import EnhancedJSONEncoder +from isar_turtlebot.config import settings from isar_turtlebot.models.turtlebot_status import Status from isar_turtlebot.ros_bridge import RosBridge -from isar_turtlebot.settings import settings from isar_turtlebot.turtlebot.step_handlers import ( DriveToHandler, TakeImageHandler,