# a605042000/mango_x4_mec_firmware architecture

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

- Interactive diagram: https://gitdiagram.com/a605042000/mango_x4_mec_firmware
- Repository: https://github.com/a605042000/mango_x4_mec_firmware

## Overview

This is RP2350 robot-control firmware for Mango X4, exposing ROS 2 velocity commands and odometry/IMU telemetry over USB CDC or Wi-Fi UDP. The documented runtime routes commands through the micro-ROS interface to the robot controller, which applies watchdog protection, kinematics and wheel PID control to the hardware; encoder and IMU readings feed state estimation and telemetry. Both mecanum and differential kinematics are documented. Relationships for the main control loop and unsampled subsystems rely on README statements; the sampled excerpts do not show all runtime calls.

Main entry points: [`src/robot_system/MecanumRobotSystem.cpp`](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/MecanumRobotSystem.cpp) (Mecanum controller), [`src/main.cpp`](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/main.cpp) (Firmware startup), [`src/ros_interface/MicroRosInterface.cpp`](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/ros_interface/MicroRosInterface.cpp) (micro-ROS interface), [`src/imu/Mpu6050Driver.cpp`](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/imu/Mpu6050Driver.cpp) (MPU6050 driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Motion control"]
  node_system["Mecanum controller"]
  node_robot_system["Robot system<br/>[RobotSystem.cpp]"]
  node_watchdog["Command watchdog<br/>[SafetyWatchdog.cpp]"]
  node_mecanum_kin["Mecanum kinematics"]
  node_diff_kin["Differential kinematics"]
  node_pid["Wheel PID<br/>[PidController.cpp]"]
end

subgraph group_sensing["Sensing and state"]
  node_odometry["Odometry<br/>[Odometry.cpp]"]
  node_encoder["Quadrature decoding"]
  node_imu["MPU6050 driver<br/>[Mpu6050Driver.cpp]"]
  node_imu_filter["IMU filter<br/>[ImuFilter.cpp]"]
end

subgraph group_hardware["Board hardware"]
  node_main["Firmware startup<br/>[main.cpp]"]
  node_config["Robot configuration<br/>[RobotConfig.hpp]"]
  node_encoder_hal["RP2350 encoder HAL"]
  node_i2c["RP2350 I2C bus<br/>[Rp2350I2cBus.hpp]"]
  node_motor["PWM motor control<br/>[PwmMotor.cpp]"]
  node_motor_hal["RP2350 PWM HAL"]
  node_display["SSD1306 display<br/>[Ssd1306Driver.cpp]"]
  node_clock["System clock<br/>[SystemClock.hpp]"]
end

subgraph group_communications["ROS communications"]
  node_ros["micro-ROS interface"]
  node_usb["USB serial transport"]
  node_wifi["Wi-Fi UDP transport"]
  node_microros_lib["micro-ROS support"]
end

node_ros_host(("ROS 2 host"))
node_agent(("micro-ROS Agent"))

node_ros_host -->|"sends commands"| node_agent
node_agent -->|"exchanges ROS data"| node_ros
node_ros -.->|"uses serial"| node_usb
node_ros -->|"uses UDP"| node_wifi
node_ros -.->|"uses middleware"| node_microros_lib
node_main -->|"starts controller"| node_system
node_main -->|"configures board"| node_config
node_main -->|"configures motors"| node_motor_hal
node_main -->|"configures encoders"| node_encoder_hal
node_main -->|"configures sensor"| node_imu
node_main -->|"initializes interface"| node_ros
node_main -.->|"initializes display"| node_display
node_main -.->|"uses timing"| node_clock
node_ros -->|"delivers commands"| node_system
node_system -->|"checks timeout"| node_watchdog
node_system -->|"converts motion"| node_mecanum_kin
node_system -->|"computes wheel output"| node_pid
node_system -->|"sets motor output"| node_motor
node_system -->|"reads wheel feedback"| node_encoder
node_system -->|"updates pose"| node_odometry
node_system -->|"reads orientation"| node_imu
node_system -->|"publishes telemetry"| node_ros
node_encoder_hal -.->|"provides ticks"| node_encoder
node_motor_hal -.->|"drives PWM"| node_motor
node_imu -->|"reads sensor bus"| node_i2c
node_imu -.->|"filters measurements"| node_imu_filter
node_robot_system -->|"supports differential drive"| node_diff_kin
node_ros -->|"publishes telemetry"| node_ros_host

click node_main "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/main.cpp"
click node_config "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/config/RobotConfig.hpp"
click node_system "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/MecanumRobotSystem.cpp"
click node_robot_system "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/RobotSystem.cpp"
click node_watchdog "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/SafetyWatchdog.cpp"
click node_mecanum_kin "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/kinematics/MecanumKinematics.cpp"
click node_diff_kin "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/kinematics/DifferentialKinematics.cpp"
click node_pid "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/pid/PidController.cpp"
click node_odometry "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/odometry/Odometry.cpp"
click node_encoder "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/encoder/QuadratureEncoder.cpp"
click node_encoder_hal "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/encoder/Rp2350EncoderDriver.hpp"
click node_imu "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/imu/Mpu6050Driver.cpp"
click node_imu_filter "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/imu/ImuFilter.cpp"
click node_i2c "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/imu/Rp2350I2cBus.hpp"
click node_motor "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/motor/PwmMotor.cpp"
click node_motor_hal "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/motor/Rp2350PwmMotorDriver.hpp"
click node_ros "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/ros_interface/MicroRosInterface.cpp"
click node_usb "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/micro_ros_pico/pico_uart_transport.c"
click node_wifi "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/micro_ros_pico/pico_wifi_transport.c"
click node_display "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/display/Ssd1306Driver.cpp"
click node_clock "https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/hal/SystemClock.hpp"
click node_microros_lib "https://github.com/a605042000/mango_x4_mec_firmware/tree/main/micro_ros_pico/libmicroros/include"

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_system,node_robot_system,node_watchdog,node_mecanum_kin,node_diff_kin,node_pid toneBlue
class node_odometry,node_encoder,node_imu,node_imu_filter toneAmber
class node_main,node_config,node_encoder_hal,node_i2c,node_motor,node_motor_hal,node_display,node_clock toneMint
class node_ros,node_usb,node_wifi,node_microros_lib toneRose
class node_ros_host,node_agent toneIndigo
```

## Components

### Motion control

- [Mecanum controller](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/MecanumRobotSystem.cpp): `src/robot_system/MecanumRobotSystem.cpp`
- [Robot system](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/RobotSystem.cpp): `src/robot_system/RobotSystem.cpp`
- [Command watchdog](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/robot_system/SafetyWatchdog.cpp): `src/robot_system/SafetyWatchdog.cpp`
- [Mecanum kinematics](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/kinematics/MecanumKinematics.cpp): `src/kinematics/MecanumKinematics.cpp`
- [Differential kinematics](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/kinematics/DifferentialKinematics.cpp): `src/kinematics/DifferentialKinematics.cpp`
- [Wheel PID](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/pid/PidController.cpp): `src/pid/PidController.cpp`

### Sensing and state

- [Odometry](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/odometry/Odometry.cpp): `src/odometry/Odometry.cpp`
- [Quadrature decoding](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/encoder/QuadratureEncoder.cpp): `src/encoder/QuadratureEncoder.cpp`
- [MPU6050 driver](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/imu/Mpu6050Driver.cpp): `src/imu/Mpu6050Driver.cpp`
- [IMU filter](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/imu/ImuFilter.cpp): `src/imu/ImuFilter.cpp`

### Board hardware

- [Firmware startup](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/main.cpp): `src/main.cpp`
- [Robot configuration](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/config/RobotConfig.hpp): `include/config/RobotConfig.hpp`
- [RP2350 encoder HAL](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/encoder/Rp2350EncoderDriver.hpp): `include/encoder/Rp2350EncoderDriver.hpp`
- [RP2350 I2C bus](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/imu/Rp2350I2cBus.hpp): `include/imu/Rp2350I2cBus.hpp`
- [PWM motor control](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/motor/PwmMotor.cpp): `src/motor/PwmMotor.cpp`
- [RP2350 PWM HAL](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/motor/Rp2350PwmMotorDriver.hpp): `include/motor/Rp2350PwmMotorDriver.hpp`
- [SSD1306 display](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/display/Ssd1306Driver.cpp): `src/display/Ssd1306Driver.cpp`
- [System clock](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/include/hal/SystemClock.hpp): `include/hal/SystemClock.hpp`

### ROS communications

- [micro-ROS interface](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/src/ros_interface/MicroRosInterface.cpp): `src/ros_interface/MicroRosInterface.cpp`
- [USB serial transport](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/micro_ros_pico/pico_uart_transport.c): `micro_ros_pico/pico_uart_transport.c`
- [Wi-Fi UDP transport](https://github.com/a605042000/mango_x4_mec_firmware/blob/main/micro_ros_pico/pico_wifi_transport.c): `micro_ros_pico/pico_wifi_transport.c`
- [micro-ROS support](https://github.com/a605042000/mango_x4_mec_firmware/tree/main/micro_ros_pico/libmicroros/include): `micro_ros_pico/libmicroros/include`

### Other components

- **ROS 2 host**
- **micro-ROS Agent**

## Connections

- ROS 2 host → micro-ROS Agent: sends commands (evidence: `README.md`)
- micro-ROS Agent → micro-ROS interface: exchanges ROS data (evidence: `README.md`)
- micro-ROS interface → USB serial transport: uses serial
- micro-ROS interface → Wi-Fi UDP transport: uses UDP (evidence: `src/ros_interface/MicroRosInterface.cpp`)
- micro-ROS interface → micro-ROS support: uses middleware
- Firmware startup → Mecanum controller: starts controller (evidence: `README.md`)
- Firmware startup → Robot configuration: configures board (evidence: `src/main.cpp`)
- Firmware startup → RP2350 PWM HAL: configures motors (evidence: `src/main.cpp`)
- Firmware startup → RP2350 encoder HAL: configures encoders (evidence: `src/main.cpp`)
- Firmware startup → MPU6050 driver: configures sensor (evidence: `src/main.cpp`)
- Firmware startup → micro-ROS interface: initializes interface (evidence: `src/main.cpp`)
- Firmware startup → SSD1306 display: initializes display
- Firmware startup → System clock: uses timing (evidence: `src/main.cpp`)
- micro-ROS interface → Mecanum controller: delivers commands (evidence: `README.md`)
- Mecanum controller → Command watchdog: checks timeout (evidence: `README.md`)
- Mecanum controller → Mecanum kinematics: converts motion
- Mecanum controller → Wheel PID: computes wheel output
- Mecanum controller → PWM motor control: sets motor output (evidence: `README.md`)
- Mecanum controller → Quadrature decoding: reads wheel feedback (evidence: `README.md`)
- Mecanum controller → Odometry: updates pose
- Mecanum controller → MPU6050 driver: reads orientation
- Mecanum controller → micro-ROS interface: publishes telemetry
- RP2350 encoder HAL → Quadrature decoding: provides ticks
- RP2350 PWM HAL → PWM motor control: drives PWM
- MPU6050 driver → RP2350 I2C bus: reads sensor bus
- MPU6050 driver → IMU filter: filters measurements
- Robot system → Differential kinematics: supports differential drive (evidence: `README.md`)
- micro-ROS interface → ROS 2 host: publishes telemetry (evidence: `README.md`)
