From e4b242c3ddea5837beaa6bdaa09aab0bc5b68897 Mon Sep 17 00:00:00 2001 From: ratheron Date: Mon, 19 Oct 2026 19:02:44 +0200 Subject: [PATCH] Rename the ros_nodes package to ros The connector, node, and utils modules drop their ros2_ prefix. The package exports ROSConnector, so `from drone_estimators.ros import ROSConnector` works, and the node runs with `python -m drone_estimators.ros.node`. --- README.md | 10 +++++----- docs/get-started/ros2.md | 10 +++++----- docs/reference/index.md | 2 +- drone_estimators/ros/__init__.py | 5 +++++ .../{ros_nodes/ros2_connector.py => ros/connector.py} | 0 drone_estimators/{ros_nodes => ros}/estimators.toml | 0 .../{ros_nodes/ros2_node.py => ros/node.py} | 4 ++-- .../{ros_nodes/ros2_utils.py => ros/utils.py} | 0 drone_estimators/ros_nodes/__init__.py | 1 - pyproject.toml | 2 +- .../{test_ros2_connector.py => test_connector.py} | 6 +++--- tests/integration/test_save_data.py | 2 +- tests/unit/test_import.py | 2 +- 13 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 drone_estimators/ros/__init__.py rename drone_estimators/{ros_nodes/ros2_connector.py => ros/connector.py} (100%) rename drone_estimators/{ros_nodes => ros}/estimators.toml (100%) rename drone_estimators/{ros_nodes/ros2_node.py => ros/node.py} (99%) rename drone_estimators/{ros_nodes/ros2_utils.py => ros/utils.py} (100%) delete mode 100644 drone_estimators/ros_nodes/__init__.py rename tests/integration/{test_ros2_connector.py => test_connector.py} (96%) diff --git a/README.md b/README.md index 60e051b..8829a36 100644 --- a/README.md +++ b/README.md @@ -99,12 +99,12 @@ The differentiation-based filter is `DiffFilter` in `drone_estimators.estimator_ ### ROS 2 node ```bash -python -m drone_estimators.ros_nodes.ros2_node --drone_name cf1 --estimator_type ukf -python -m drone_estimators.ros_nodes.ros2_node --drone_name cf1 --estimator_type diff -python -m drone_estimators.ros_nodes.ros2_node --settings path/to/estimators.toml +python -m drone_estimators.ros.node --drone_name cf1 --estimator_type ukf +python -m drone_estimators.ros.node --drone_name cf1 --estimator_type diff +python -m drone_estimators.ros.node --settings path/to/estimators.toml ``` -The settings are read from [`estimators.toml`](drone_estimators/ros_nodes/estimators.toml). To estimate several drones, add one `[estimatorX]` section per drone and pass your file with `--settings`. Drones with identical settings are batched into one estimator. +The settings are read from [`estimators.toml`](drone_estimators/ros/estimators.toml). To estimate several drones, add one `[estimatorX]` section per drone and pass your file with `--settings`. Drones with identical settings are batched into one estimator. The node subscribes to `/tf` (e.g., from [motion_capture_tracking](https://github.com/learnsyslab/motion_capture_tracking)) and to `/drones//command` (roll, pitch, yaw in deg and thrust in PWM, needed by the UKF). It publishes the estimates to `/drones//estimate/{pose,twist,wrench,rotor_vel}`. The node only communicates with nodes on the same machine (`ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST`). @@ -113,7 +113,7 @@ To read the estimates in Python without blocking, use the `ROSConnector`: ```python import rclpy -from drone_estimators.ros_nodes.ros2_connector import ROSConnector +from drone_estimators.ros import ROSConnector rclpy.init() conn = ROSConnector(estimator_names=["cf1"], timeout=10.0) diff --git a/docs/get-started/ros2.md b/docs/get-started/ros2.md index 95ec194..048163a 100644 --- a/docs/get-started/ros2.md +++ b/docs/get-started/ros2.md @@ -17,21 +17,21 @@ The type and IP address of the motion capture system are set in the [configurati Start the estimator for a single drone with ```bash -python -m drone_estimators.ros_nodes.ros2_node --drone_name cf1 +python -m drone_estimators.ros.node --drone_name cf1 ``` The node waits until it has received a first pose of every drone, initializes the estimators with it, and then runs at a fixed frequency. Add `--estimator_type diff` to use the differentiation-based filter instead of the UKF, `--estimator_type ekf` to use the EKF, or `--estimator_type ukf` to force the UKF. -The settings of the estimators are read from a TOML file. By default, the node uses the [estimators.toml](https://github.com/learnsyslab/drone-estimators/blob/main/drone_estimators/ros_nodes/estimators.toml) that ships with the package: +The settings of the estimators are read from a TOML file. By default, the node uses the [estimators.toml](https://github.com/learnsyslab/drone-estimators/blob/main/drone_estimators/ros/estimators.toml) that ships with the package: ```toml ---8<-- "drone_estimators/ros_nodes/estimators.toml" +--8<-- "drone_estimators/ros/estimators.toml" ``` To estimate several drones, add one `[estimatorN]` section per drone to your own copy of the file and pass it to the node. `--drone_name` and `--estimator_type` overwrite the settings of `estimator1`. ```bash -python -m drone_estimators.ros_nodes.ros2_node --settings path/to/estimators.toml +python -m drone_estimators.ros.node --settings path/to/estimators.toml ``` Estimators with identical settings (except for the drone name) run as one batched estimator. @@ -75,7 +75,7 @@ The `ROSConnector` gives non-blocking access to the latest estimates from your o ```python import rclpy -from drone_estimators.ros_nodes.ros2_connector import ROSConnector +from drone_estimators.ros import ROSConnector if __name__ == "__main__": # The connector spawns processes, so guard the entry point rclpy.init() diff --git a/docs/reference/index.md b/docs/reference/index.md index 373b294..31ef6a6 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -10,6 +10,6 @@ This section is generated from the docstrings of the source code with [mkdocstri | `drone_estimators.filterpy` | Functional EKF and UKF predict and correct steps, adapted from [FilterPy](https://github.com/rlabbe/filterpy) | | `drone_estimators.structs` | `EstimatorData` and the EKF and UKF settings | | `drone_estimators.utils` | Batching, dynamics, and integration helpers | -| `drone_estimators.ros_nodes` | The ROS 2 estimator node, the `ROSConnector`, and message utilities | +| `drone_estimators.ros` | The ROS 2 estimator node, the `ROSConnector`, and message utilities | Navigate the full reference using the sidebar. diff --git a/drone_estimators/ros/__init__.py b/drone_estimators/ros/__init__.py new file mode 100644 index 0000000..dfc2b05 --- /dev/null +++ b/drone_estimators/ros/__init__.py @@ -0,0 +1,5 @@ +"""ROS 2 node and connector for the estimators.""" + +from drone_estimators.ros.connector import ROSConnector + +__all__ = ["ROSConnector"] diff --git a/drone_estimators/ros_nodes/ros2_connector.py b/drone_estimators/ros/connector.py similarity index 100% rename from drone_estimators/ros_nodes/ros2_connector.py rename to drone_estimators/ros/connector.py diff --git a/drone_estimators/ros_nodes/estimators.toml b/drone_estimators/ros/estimators.toml similarity index 100% rename from drone_estimators/ros_nodes/estimators.toml rename to drone_estimators/ros/estimators.toml diff --git a/drone_estimators/ros_nodes/ros2_node.py b/drone_estimators/ros/node.py similarity index 99% rename from drone_estimators/ros_nodes/ros2_node.py rename to drone_estimators/ros/node.py index bf96242..97ed1f2 100644 --- a/drone_estimators/ros_nodes/ros2_node.py +++ b/drone_estimators/ros/node.py @@ -50,7 +50,7 @@ from drone_estimators.estimator_diff import DiffFilter from drone_estimators.estimator_kalman import KalmanFilter -from drone_estimators.ros_nodes.ros2_utils import ( +from drone_estimators.ros.utils import ( append_measurement, append_state, create_array, @@ -696,7 +696,7 @@ def launch_node(settings: Munch, stop_event: Event): args = parser.parse_args() if args.settings is None: - path = Path(__file__).parents[1] / "ros_nodes/estimators.toml" + path = Path(__file__).parent / "estimators.toml" else: path = args.settings with open(path, "r") as f: diff --git a/drone_estimators/ros_nodes/ros2_utils.py b/drone_estimators/ros/utils.py similarity index 100% rename from drone_estimators/ros_nodes/ros2_utils.py rename to drone_estimators/ros/utils.py diff --git a/drone_estimators/ros_nodes/__init__.py b/drone_estimators/ros_nodes/__init__.py deleted file mode 100644 index 873785e..0000000 --- a/drone_estimators/ros_nodes/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""ROS 2 node and connector for the estimators.""" diff --git a/pyproject.toml b/pyproject.toml index 71bb954..2130bf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ find = {} [tool.setuptools.package-data] -drone_estimators = ["ros_nodes/*.toml"] +drone_estimators = ["ros/*.toml"] [tool.pytest.ini_options] markers = ["unit", "integration", "render"] diff --git a/tests/integration/test_ros2_connector.py b/tests/integration/test_connector.py similarity index 96% rename from tests/integration/test_ros2_connector.py rename to tests/integration/test_connector.py index d39e27d..fb9e852 100644 --- a/tests/integration/test_ros2_connector.py +++ b/tests/integration/test_connector.py @@ -12,7 +12,7 @@ import numpy as np import pytest -# Keep the test traffic on this machine, see ros2_node.py +# Keep the test traffic on this machine, see node.py os.environ["ROS_AUTOMATIC_DISCOVERY_RANGE"] = "LOCALHOST" import rclpy @@ -21,7 +21,7 @@ from std_msgs.msg import Float64MultiArray from tf2_msgs.msg import TFMessage -from drone_estimators.ros_nodes.ros2_connector import ROSConnector +from drone_estimators.ros import ROSConnector if TYPE_CHECKING: from collections.abc import Callable, Iterator @@ -48,7 +48,7 @@ def fake() -> Iterator[SimpleNamespace]: fake = SimpleNamespace(gate=f"gate_{uuid4().hex[:8]}", drone=f"cf_{uuid4().hex[:8]}") fake.drone_tracked = True rclpy.init() - node = rclpy.create_node("test_ros2_connector_" + uuid4().hex) + node = rclpy.create_node("test_connector_" + uuid4().hex) tf_pub = node.create_publisher(TFMessage, "/tf", 10) topic = f"/drones/{fake.drone}/estimate" pose_pub = node.create_publisher(PoseStamped, f"{topic}/pose", 10) diff --git a/tests/integration/test_save_data.py b/tests/integration/test_save_data.py index 4b84f19..ecb64f1 100644 --- a/tests/integration/test_save_data.py +++ b/tests/integration/test_save_data.py @@ -10,7 +10,7 @@ from drone_estimators.estimator_diff import DiffFilter from drone_estimators.estimator_kalman import KalmanFilter -from drone_estimators.ros_nodes.ros2_utils import append_state +from drone_estimators.ros.utils import append_state DIFF_PARAMS = (0.0001, 0.007, 0.09, 0.005, 0.07) # As in the ROS node diff --git a/tests/unit/test_import.py b/tests/unit/test_import.py index b96e212..532f634 100644 --- a/tests/unit/test_import.py +++ b/tests/unit/test_import.py @@ -10,7 +10,7 @@ [ "drone_estimators.estimator_kalman", "drone_estimators.estimator_diff", - "drone_estimators.ros_nodes.ros2_node", + "drone_estimators.ros.node", ], ) def test_import_first(module: str):