# eth-pbl/map-controller architecture

> Architecture diagram of the GitHub repository eth-pbl/map-controller, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eth-pbl/map-controller
- Repository: https://github.com/eth-pbl/map-controller

## Overview

The project at hand is an autonomous racing controller package that implements both Model- and Acceleration-based Pursuit (MAP) and Pure Pursuit algorithms. It not only provides the controller algorithms and lookup table generation for steering dynamics but also includes a simulator for evaluating controller performance. The project’s purpose is to generate steering commands for a racecar using both geometric (Pure Pursuit) and more dynamic (MAP) strategies, with an emphasis on accurately converting acceleration to steering values via a lookup table derived from vehicle dynamics and tire models.

##### Main Components
- Simulator Environment: Represented by the F110_ROS_Simulator directory. This includes ROS launch files, maps, the car’s kinematic models (e.g., ackermann_kinematics.hpp, st_kinematics.hpp, etc.), and visualization (RViz).
- Controllers: There are at least two controllers included:
- Controller (Model- and Acceleration-based Pursuit) – provided in the “map_controller” package.
- Pure Pursuit Controller – also provided in the “map_controller” package.
- Lookup Table Generation: Located in the “steering_lookup” folder. This is a crucial preprocessing component that creates steering lookup tables based on tire dynamics and vehicle parameters.
- ROS Message Definitions: The “f110_msgs” package defines the messages (e.g., Wpnt.msg, WpntArray.msg) used for communicating the car state and waypoints.
- ROS Nodes: Found in various directories (node in F110_ROS_Simulator and Python nodes in map_controller) that publish or subscribe to essential topics such as vehicle pose, waypoints, and control commands.
- Configuration Files: The YAML files in “map_controller/cfg” and “steering_lookup/cfg” and other parameter-related files which are central for tuning the controllers and lookup table generation.

##### Relationships and Interactions
- Data Flow: Position and waypoint data are published on the ROS topics (e.g., /car_state/pose and /global_waypoints), which are then used by the controllers.
- Controllers: Both controllers receive data, compute steering commands, and output “AckermannDriveStamped” messages on a dedicated topic (/ackermann_cmd_mux/input/teleop).
- Lookup Table Integration: The steering_lookup module generates the lookup tables (via simulate_model.py) that are used by the MAP controller for converting calculated acceleration into refined steering angle commands.
- Simulation Interaction: The simulator launches and visualizes the vehicle’s movement using various launch files (e.g., racecar_model.launch, simulator.rviz) and integrates with the map data provided under “maps”.

##### Architectural Patterns and Design Principles
- ROS Node Architecture: The system is modularly built using ROS nodes for each major function (simulation, control, lookup table generation), allowing for clear separation of concerns.
- Layered Architecture: The system can be seen as layered – from data acquisition (via sensor and state messages), through processing (controllers, lookup table generation), to actuation (control command publication to the vehicle simulator).
- Configuration-driven Setup: Several parameters and behavior adjustments are externalized in YAML and configuration files, supporting tuning and flexibility.

##### Detail and Component Separation
- More details (like specific file names from the include/ or src/ directories) may be added if needed, but focus on the logical separation rather than individual file details.
- Keep inter-component interfaces (ROS topics and message types) explicit, as these are fundamental to understanding the system’s flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Simulation Environment"
    sim["F110_ROS_Simulator – Kinematics & Simulation"]:::simulation
  end

  subgraph "Messaging"
    msg["f110_msgs – Wpnt & WpntArray"]:::messaging
  end

  subgraph "Control Modules"
    mapctrl["MAP Controller (Python)"]:::controller
    ppctrl["Pure Pursuit Controller (Python)"]:::controller
    ttracker["Time Error Tracker Utility (Python)"]:::controller
  end

  subgraph "Lookup Table Generation"
    lookup["Lookup Table Generator (steering_lookup)"]:::lookup
    lookupConfig["Lookup Table Config (CSV/YAML)"]:::lookup
    lutgen["LUT Generation Scripts"]:::lookup
  end

  subgraph "External Systems"
    actuator["Actuator/Output (AckermannDriveStamped)"]:::external
    roscore["ROS Core"]:::external
  end

  %% Data Flow Arrows
  sim -->|"Publishes car state & waypoints (PoseStamped, WpntArray)"| mapctrl
  sim -->|"Publishes car state & waypoints (PoseStamped, WpntArray)"| ppctrl
  msg -->|"Defines custom messages"| mapctrl
  msg -->|"Defines custom messages"| ppctrl
  mapctrl -->|"Publishes command (AckermannDriveStamped)"| actuator
  ppctrl -->|"Publishes command (AckermannDriveStamped)"| actuator
  lookup -->|"Provides steering lookup data"| mapctrl
  lookup -->|"Provides steering lookup data"| ppctrl
  roscore -->|"Orchestrates ROS topics"| sim
  roscore -->|"Orchestrates ROS topics"| mapctrl
  roscore -->|"Orchestrates ROS topics"| lookup

  %% Click Events from component mapping
  click sim "https://github.com/eth-pbl/map-controller/tree/main/F110_ROS_Simulator/"
  click msg "https://github.com/eth-pbl/map-controller/tree/main/f110_msgs/msg"
  click mapctrl "https://github.com/eth-pbl/map-controller/blob/main/map_controller/src/MAP_controller.py"
  click ppctrl "https://github.com/eth-pbl/map-controller/blob/main/map_controller/src/PP_controller.py"
  click ttracker "https://github.com/eth-pbl/map-controller/blob/main/map_controller/src/time_error_tracker.py"
  click lookup "https://github.com/eth-pbl/map-controller/blob/main/steering_lookup/src/steering_lookup/lookup_steer_angle.py"
  click lookupConfig "https://github.com/eth-pbl/map-controller/tree/main/steering_lookup/cfg"
  click lutgen "https://github.com/eth-pbl/map-controller/tree/main/steering_lookup/src/LUT_Generation"

  %% Legend
  subgraph "Legend"
    L1["<b>Color Legend:</b>"]
    L2["Simulation Environment: Light Blue"]
    L3["Messaging: Light Green"]
    L4["Control Modules: Light Yellow"]
    L5["Lookup Table Generation: Light Red"]
    L6["External Systems: Light Purple"]
  end

  class sim simulation
  class msg messaging
  class mapctrl,ppctrl,ttracker controller
  class lookup,lookupConfig,lutgen lookup
  class actuator,roscore external

  classDef simulation fill:#AED6F1,stroke:#2471A3,stroke-width:2px
  classDef messaging fill:#ABEBC6,stroke:#1E8449,stroke-width:2px
  classDef controller fill:#F9E79F,stroke:#B7950B,stroke-width:2px
  classDef lookup fill:#F5B7B1,stroke:#C0392B,stroke-width:2px
  classDef external fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px
  classDef legend fill:#EEEEEE,stroke:#000000,stroke-dasharray: 5 5
```
