# y2d2/upf_rpe architecture

> Architecture diagram of the GitHub repository y2d2/upf_rpe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/y2d2/upf_rpe
- Repository: https://github.com/y2d2/upf_rpe

## Overview

#### Purpose and entry points
This is a Python research codebase for relative-pose estimation between two mobile agents using shared VIO motion and a single inter-agent UWB range. Its principal estimator is an Unscented Particle Filter (UPF) designed to preserve multi-modal hypotheses during unobservable relative motion. Start with `Quick_start.ipynb`; reusable estimator entry point is `Code/ParticleFilter/ConnectedAgentClass.py`. Reproducible experiment drivers are under `test_cases/RPE_2_agents_LOS/Experiments/Experiment_run.py` and simulation generation under `test_cases/RPE_2_agents_LOS/simulations/Simulation_runs/`.

#### UPF estimation core
`Code/ParticleFilter/ConnectedAgentClass.py` defines the connected-agent/UPF state and public lifecycle: initialize a relative-pose distribution, update the host agent’s local motion, then process the connected agent’s communicated motion plus UWB range. It owns particle hypotheses, relative-pose propagation, likelihood/weight updates, and logging integration. `Code/ParticleFilter/ModifiedUKF.py` supplies the UKF machinery used per hypothesis; `Code/ParticleFilter/TargetTrackingUKF.py` provides a related target-tracking UKF formulation.

#### Motion and measurement boundary
The estimator consumes pose increments and covariance from VIO/odometry, and scalar distance measurements from UWB. Sensor-facing abstractions are separated in `Code/UtilityCode/IMU.py`, `Code/UtilityCode/UWB.py`, and `Code/UtilityCode/Measurement.py`; frame/pose transformations are centralized in `Code/UtilityCode/Transformation_Matrix_Fucntions.py`. This boundary lets the same filter operate on synthetic trajectories, sampled experiment data, or robot/ROS-derived data rather than requiring a web or service runtime.

#### Simulation pipeline
`Code/Simulation/MultiRobotClass.py` coordinates multi-agent scenarios; `Code/Simulation/RobotClass.py` represents individual simulated robots, while `Code/Simulation/UWBMeasurmentClass.py` produces range observations. `Code/Simulation/BiRobotMovement.py` defines two-robot motion cases and `Code/Simulation/NLOS_Manager.py` models non-line-of-sight handling. Simulations generate corrupted VIO/UWB inputs, persisted as trajectory pickles in `Data/Simulations/*/trajectories.pkl`, for controlled, common-input algorithm comparisons.

#### Benchmark solvers
The UPF is evaluated against distinct batch/optimization-style baselines: nonlinear least squares in `Code/BaseLines/NLS.py`, quadratically constrained quadratic programming in `Code/BaseLines/QCQP.py`, and a 4-DoF algebraic estimator in `Code/BaseLines/AlgebraicMethod4DoF.py`. These are parallel consumers of comparable motion/range data, not dependencies of the UPF.

#### Data, logging, and analysis
Recorded LOS experiment inputs are stored as sampled pickles in `Data/Measurements/` and as ROS 2 bag SQLite datasets in `Data/Measurements/rosbags/`. ROS message schemas identify integration contracts for Vicon positions and UWB ranges: `Data/Custom_ros_messages/vicon_receiver/msg/Position.msg` and `Data/Custom_ros_messages/yd_uwb_msgs/msg/UWBRange.msg`. Estimator-specific result capture is separated through `Code/DataLoggers/ConnectedAgent_DataLogger.py`, `Code/DataLoggers/NLS_DataLogger.py`, and `Code/DataLoggers/QCQP_DataLogger.py`; comparative post-processing centers on `Code/Analysis/TwoAgentAnalysis.py` and notebooks.

#### Runtime and deployment context
The material runtime is Python, packaged by `setup.py` with dependencies declared in `requirements.txt`. Hardware-oriented adapters include `Code/UtilityCode/RealRobot.py` and `Code/UtilityCode/turtlebot4.py`, indicating TurtleBot 4, UWB, VIO, and ROS 2 interoperability. `tmux_script/start_simulation.sh` and `tmux_script/simulation.yaml` support multi-process simulation execution. No hosted infrastructure, database service, or network API is indicated; persisted artifacts are local pickle files and ROS bag databases.

Main entry points: [`Code/UtilityCode/Measurement.py`](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/Measurement.py) (Sensor abstractions), [`Code/ParticleFilter/ConnectedAgentClass.py`](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/ParticleFilter/ConnectedAgentClass.py) (Connected-agent UPF), [`Code/Simulation/MultiRobotClass.py`](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/MultiRobotClass.py) (Multi-robot simulator), [`Code/DataLoggers/ConnectedAgent_DataLogger.py`](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/DataLoggers/ConnectedAgent_DataLogger.py) (Estimator result loggers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Motion &amp; measurement inputs"]
  node_sensor_boundary["Sensor abstractions<br/>Python modules<br/>[Measurement.py]"]
  node_transforms["Pose transforms<br/>Python module"]
  node_recorded_data[("Recorded LOS inputs<br/>pickle datasets")]
  node_rosbags[("ROS 2 bag datasets<br/>SQLite bags")]
  node_ros_messages["ROS message schemas<br/>ROS messages<br/>[Position.msg]"]
  node_hardware_adapters["Robot and TurtleBot adapters<br/>Python adapters<br/>[RealRobot.py]"]
end

subgraph group_simulation["Simulation pipeline"]
  node_scenario_motion["Two-robot motion cases<br/>Python module<br/>[BiRobotMovement.py]"]
  node_multi_robot_sim["Multi-robot simulator<br/>Python module<br/>[MultiRobotClass.py]"]
  node_robot_sim["Simulated robots<br/>Python module<br/>[RobotClass.py]"]
  node_range_sim["UWB range simulator<br/>Python module"]
  node_nlos["NLOS model<br/>Python module<br/>[NLOS_Manager.py]"]
  node_sim_trajectories[("Simulated trajectories<br/>pickle artifacts")]
end

subgraph group_estimators["Estimators"]
  node_upf{{"Connected-agent UPF<br/>Python estimator"}}
  node_ukf["Per-hypothesis UKF<br/>Python filter<br/>[ModifiedUKF.py]"]
  node_baselines["Batch baselines<br/>Python solvers<br/>[NLS.py]"]
end

subgraph group_evaluation["Experiments &amp; analysis"]
  node_quickstart["Quick start notebook<br/>[Quick_start.ipynb]"]
  node_experiment_driver["Experiment driver<br/>Python runner<br/>[Experiment_run.py]"]
  node_result_loggers["Estimator result loggers<br/>Python loggers"]
  node_analysis["Two-agent analysis<br/>Python analysis"]
end

node_ros_messages -.->|"define message payloads"| node_rosbags
node_recorded_data -->|"provide sampled inputs"| node_sensor_boundary
node_rosbags -->|"provide ROS-derived inputs"| node_sensor_boundary
node_hardware_adapters -->|"adapt hardware streams"| node_sensor_boundary
node_scenario_motion -->|"defines scenarios"| node_multi_robot_sim
node_robot_sim -->|"agents"| node_multi_robot_sim
node_range_sim -->|"range observations"| node_multi_robot_sim
node_nlos -->|"models degraded ranging"| node_multi_robot_sim
node_multi_robot_sim -->|"persists corrupted inputs"| node_sim_trajectories
node_sim_trajectories -->|"replays synthetic inputs"| node_sensor_boundary
node_sensor_boundary -->|"pose increments and ranges"| node_transforms
node_transforms -->|"normalized relative motion"| node_upf
node_sensor_boundary -->|"VIO covariance and UWB range"| node_upf
node_ukf -->|"updates each hypothesis"| node_upf
node_experiment_driver -->|"runs"| node_upf
node_experiment_driver -->|"runs comparisons"| node_baselines
node_upf -->|"logs estimates"| node_result_loggers
node_baselines -->|"logs baseline results"| node_result_loggers
node_result_loggers -->|"comparison results"| node_analysis
node_quickstart -.->|"demonstrates"| node_upf

click node_quickstart "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Quick_start.ipynb"
click node_sensor_boundary "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/Measurement.py"
click node_transforms "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/Transformation_Matrix_Fucntions.py"
click node_ros_messages "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Data/Custom_ros_messages/vicon_receiver/msg/Position.msg"
click node_scenario_motion "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/BiRobotMovement.py"
click node_multi_robot_sim "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/MultiRobotClass.py"
click node_robot_sim "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/RobotClass.py"
click node_range_sim "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/UWBMeasurmentClass.py"
click node_nlos "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/NLOS_Manager.py"
click node_upf "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/ParticleFilter/ConnectedAgentClass.py"
click node_ukf "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/ParticleFilter/ModifiedUKF.py"
click node_baselines "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/BaseLines/NLS.py"
click node_experiment_driver "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/test_cases/RPE_2_agents_LOS/Experiments/Experiment_run.py"
click node_result_loggers "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/DataLoggers/ConnectedAgent_DataLogger.py"
click node_analysis "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Analysis/TwoAgentAnalysis.py"
click node_hardware_adapters "https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/RealRobot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sensor_boundary,node_transforms,node_recorded_data,node_rosbags,node_ros_messages,node_hardware_adapters toneBlue
class node_scenario_motion,node_multi_robot_sim,node_robot_sim,node_range_sim,node_nlos,node_sim_trajectories toneAmber
class node_upf,node_ukf,node_baselines toneMint
class node_quickstart,node_experiment_driver,node_result_loggers,node_analysis toneRose
```

## Components

### Motion & measurement inputs

- [Sensor abstractions](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/Measurement.py): Python modules · VIO/IMU, UWB, and measurement contracts. · `Code/UtilityCode/Measurement.py`
- [Pose transforms](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/Transformation_Matrix_Fucntions.py): Python module · `Code/UtilityCode/Transformation_Matrix_Fucntions.py`
- **Recorded LOS inputs**: pickle datasets
- **ROS 2 bag datasets**: SQLite bags
- [ROS message schemas](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Data/Custom_ros_messages/vicon_receiver/msg/Position.msg): ROS messages · Vicon position and UWB range contracts. · `Data/Custom_ros_messages/vicon_receiver/msg/Position.msg`
- [Robot and TurtleBot adapters](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/UtilityCode/RealRobot.py): Python adapters · ROS 2, VIO, UWB, and TurtleBot 4 interoperability. · `Code/UtilityCode/RealRobot.py`

### Simulation pipeline

- [Two-robot motion cases](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/BiRobotMovement.py): Python module · `Code/Simulation/BiRobotMovement.py`
- [Multi-robot simulator](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/MultiRobotClass.py): Python module · Coordinates simulated robot scenarios. · `Code/Simulation/MultiRobotClass.py`
- [Simulated robots](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/RobotClass.py): Python module · `Code/Simulation/RobotClass.py`
- [UWB range simulator](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/UWBMeasurmentClass.py): Python module · `Code/Simulation/UWBMeasurmentClass.py`
- [NLOS model](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Simulation/NLOS_Manager.py): Python module · `Code/Simulation/NLOS_Manager.py`
- **Simulated trajectories**: pickle artifacts · Common corrupted VIO/UWB inputs for comparisons.

### Estimators

- [Connected-agent UPF](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/ParticleFilter/ConnectedAgentClass.py): Python estimator · Maintains multimodal relative-pose particle hypotheses. · `Code/ParticleFilter/ConnectedAgentClass.py`
- [Per-hypothesis UKF](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/ParticleFilter/ModifiedUKF.py): Python filter · `Code/ParticleFilter/ModifiedUKF.py`
- [Batch baselines](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/BaseLines/NLS.py): Python solvers · NLS, QCQP, and 4-DoF algebraic estimators. · `Code/BaseLines/NLS.py`

### Experiments & analysis

- [Quick start notebook](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Quick_start.ipynb): notebook · Interactive entry point. · `Quick_start.ipynb`
- [Experiment driver](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/test_cases/RPE_2_agents_LOS/Experiments/Experiment_run.py): Python runner · Runs reproducible LOS comparisons. · `test_cases/RPE_2_agents_LOS/Experiments/Experiment_run.py`
- [Estimator result loggers](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/DataLoggers/ConnectedAgent_DataLogger.py): Python loggers · Separate UPF, NLS, and QCQP result capture. · `Code/DataLoggers/ConnectedAgent_DataLogger.py`
- [Two-agent analysis](https://github.com/y2d2/upf_rpe/blob/v1.0_dev/Code/Analysis/TwoAgentAnalysis.py): Python analysis · Comparative post-processing and visualization. · `Code/Analysis/TwoAgentAnalysis.py`

## Connections

- ROS message schemas → ROS 2 bag datasets: define message payloads
- Recorded LOS inputs → Sensor abstractions: provide sampled inputs
- ROS 2 bag datasets → Sensor abstractions: provide ROS-derived inputs
- Robot and TurtleBot adapters → Sensor abstractions: adapt hardware streams
- Two-robot motion cases → Multi-robot simulator: defines scenarios
- Simulated robots → Multi-robot simulator: agents
- UWB range simulator → Multi-robot simulator: range observations
- NLOS model → Multi-robot simulator: models degraded ranging
- Multi-robot simulator → Simulated trajectories: persists corrupted inputs
- Simulated trajectories → Sensor abstractions: replays synthetic inputs
- Sensor abstractions → Pose transforms: pose increments and ranges
- Pose transforms → Connected-agent UPF: normalized relative motion
- Sensor abstractions → Connected-agent UPF: VIO covariance and UWB range
- Per-hypothesis UKF → Connected-agent UPF: updates each hypothesis
- Experiment driver → Connected-agent UPF: runs
- Experiment driver → Batch baselines: runs comparisons
- Connected-agent UPF → Estimator result loggers: logs estimates
- Batch baselines → Estimator result loggers: logs baseline results
- Estimator result loggers → Two-agent analysis: comparison results
- Quick start notebook → Connected-agent UPF: demonstrates
