# myersjm/mecademic-ros2 architecture

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

- Interactive diagram: https://gitdiagram.com/myersjm/mecademic-ros2
- Repository: https://github.com/myersjm/mecademic-ros2

## Overview

#### Purpose and execution model
This ROS 2 Humble workspace controls two Mecademic Meca500 R3 arms, plans collision-aware joint trajectories for their shared workcell, and visualizes plans before execution. Primary executables are the per-robot driver, central planner, and application/control client:
- `meca_ws/src/meca_controller/meca_controller/meca_driver.py`
- `meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py`
- `meca_ws/src/meca_controller/meca_controller/meca_control.py`

#### ROS package boundary and contract
`custom_interfaces` is the wire contract between controller clients, robot drivers, and the planner. It defines motion-plan/status messages and services for pose/joint motion, gripper control, planner requests, and visualization:
- `meca_ws/src/custom_interfaces/msg/MotionPlan.msg`
- `meca_ws/src/custom_interfaces/srv/GetMotionPlan.srv`
- `meca_ws/src/custom_interfaces/srv/GoToPose.srv`

The system runs two instances of the driver under separate ROS namespaces (normally `/robot1` and `/robot2`), isolating each arm’s services and state topics while the planner reasons about both arms jointly.

#### Physical robot driver
The driver is the hardware-facing ROS node. It connects to an arm through MecademicPy, publishes robot/gripper state, and exposes services for movement and runtime settings such as joint velocity, acceleration, blending, gripper force, and gripper velocity:
- `meca_ws/src/meca_controller/meca_controller/meca_driver.py`
- `meca_ws/src/meca_controller/meca_controller/meca_settings.py`
- `meca_ws/src/custom_interfaces/msg/RobotStatus.msg`

Robot IP addresses, namespaces, and fallback/rest configurations are centralized in `meca_settings.py`. This is the safety-critical boundary where planned commands ultimately become physical motion; physical robot joint commands use degrees.

#### Application/control client
`meca_control` is the intended user-program entry point. It coordinates ROS service calls: obtain and optionally visualize a motion plan, then invoke namespaced driver services to execute robot and gripper commands:
- `meca_ws/src/meca_controller/meca_controller/meca_control.py`
- `meca_ws/src/custom_interfaces/srv/MoveJoints.srv`
- `meca_ws/src/custom_interfaces/srv/VisualizeMotionPlan.srv`

It separates task-level sequencing from hardware communications and planning implementation.

#### Joint planning pipeline
The planner node accepts planning/visualization service requests, builds a collision-free path through joint space, and returns a `MotionPlan`. Bidirectional RRT generates feasible paths; shortcutting reduces unnecessary waypoints:
- `meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py`
- `meca_ws/src/meca_motion_planner/meca_motion_planner/bidirectional_rrt.py`
- `meca_ws/src/meca_motion_planner/meca_motion_planner/shortcutting.py`

Planner and visualization inputs use radians, unlike the driver’s physical-robot command convention. The plan should be previewed and executed at low velocity due to known model-vs-real-world clearance limitations.

#### Combined collision and visualization model
`RobotModel` constructs the shared kinematic/collision world: two instances of the arm model plus the fixed environment, including their extrinsic transforms. Pinocchio supplies kinematics/collision checking and Meshcat provides visualization:
- `meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py`
- `meca_ws/src/resources/meca/meca.urdf`
- `meca_ws/src/resources/environment/environment.urdf`

The model is the key planning boundary: calibration changes alter robot-to-robot placement; environment URDF changes alter obstacles. Mesh/STL assets back these URDF collision and visual geometries.

#### Runtime and infrastructure
The workspace is built with `colcon` and contains Python ROS packages plus a CMake-built interface package. Runtime requires ROS 2 Humble/Ubuntu 22.04, Python 3.10 virtualenv setup, Pinocchio (`pin`), Meshcat, and MecademicPy. Environment initialization is captured in:
- `meca_ws/meca_setup.sh`
- `meca_ws/src/meca_controller/setup.py`
- `meca_ws/src/meca_motion_planner/setup.py`

Main entry points: [`meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py`](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py) (motion_planner), [`meca_ws/src/meca_controller/meca_controller/meca_driver.py`](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_driver.py) (meca_driver ×2), [`meca_ws/src/meca_controller/meca_controller/meca_control.py`](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_control.py) (meca_control), [`meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py`](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py) (RobotModel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control &amp; Hardware"]
  node_control_client["meca_control<br/>ROS control client<br/>[meca_control.py]"]
  node_driver["meca_driver ×2<br/>namespaced ROS driver<br/>[meca_driver.py]"]
  node_settings["Robot settings<br/>configuration boundary<br/>[meca_settings.py]"]
  node_physical_arms{{"Meca500 R3 arms<br/>physical hardware"}}
end

subgraph group_planning["Joint Planning"]
  node_planner["motion_planner<br/>ROS planner node<br/>[motion_planner.py]"]
  node_rrt["Bidirectional RRT<br/>joint-space search"]
  node_shortcutting["Path shortcutting<br/>trajectory optimization<br/>[shortcutting.py]"]
end

subgraph group_model["Shared Cell Model"]
  node_robot_model["RobotModel<br/>kinematic collision world<br/>[robot_model.py]"]
  node_arm_urdf["Arm URDF<br/>robot geometry<br/>[meca.urdf]"]
  node_environment_urdf["Environment URDF<br/>obstacle geometry<br/>[environment.urdf]"]
  node_meshcat["Meshcat<br/>plan visualization"]
end

subgraph group_interfaces["ROS Contract"]
  node_interfaces["custom_interfaces<br/>ROS messages &amp; services"]
  node_motion_plan_msg["MotionPlan<br/>ROS message<br/>[MotionPlan.msg]"]
  node_planner_service["GetMotionPlan<br/>ROS planning service<br/>[GetMotionPlan.srv]"]
  node_pose_service["GoToPose<br/>ROS driver service<br/>[GoToPose.srv]"]
  node_robot_status["RobotStatus<br/>ROS state message<br/>[RobotStatus.msg]"]
  node_execution_services["MoveJoints &amp; visualization<br/>ROS services<br/>[MoveJoints.srv]"]
end

node_control_client -->|"requests plan / preview"| node_planner
node_control_client -->|"calls namespaced motion and gripper services"| node_driver
node_planner -->|"generates feasible path"| node_rrt
node_rrt -->|"raw waypoint path"| node_shortcutting
node_shortcutting -->|"reduced trajectory"| node_planner
node_planner -->|"collision queries"| node_robot_model
node_planner -->|"visualizes plan"| node_meshcat
node_robot_model -->|"two arm instances"| node_arm_urdf
node_robot_model -->|"fixed obstacles"| node_environment_urdf
node_driver -->|"loads connection and safety defaults"| node_settings
node_driver -->|"MecademicPy commands"| node_physical_arms
node_physical_arms -->|"robot and gripper state"| node_driver
node_interfaces -->|"defines"| node_motion_plan_msg
node_interfaces -->|"defines"| node_planner_service
node_interfaces -->|"defines"| node_pose_service
node_interfaces -->|"defines"| node_robot_status
node_interfaces -->|"defines"| node_execution_services
node_control_client -.->|"uses contract"| node_interfaces
node_planner -.->|"uses contract"| node_interfaces
node_driver -.->|"uses contract"| node_interfaces

click node_control_client "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_control.py"
click node_driver "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_driver.py"
click node_settings "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_settings.py"
click node_planner "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py"
click node_rrt "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/bidirectional_rrt.py"
click node_shortcutting "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/shortcutting.py"
click node_robot_model "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py"
click node_arm_urdf "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/resources/meca/meca.urdf"
click node_environment_urdf "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/resources/environment/environment.urdf"
click node_motion_plan_msg "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/msg/MotionPlan.msg"
click node_planner_service "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/GetMotionPlan.srv"
click node_pose_service "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/GoToPose.srv"
click node_robot_status "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/msg/RobotStatus.msg"
click node_execution_services "https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/MoveJoints.srv"

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_control_client,node_driver,node_settings,node_physical_arms toneBlue
class node_planner,node_rrt,node_shortcutting toneAmber
class node_robot_model,node_arm_urdf,node_environment_urdf,node_meshcat toneMint
class node_interfaces,node_motion_plan_msg,node_planner_service,node_pose_service,node_robot_status,node_execution_services toneRose
```

## Components

### Control & Hardware

- [meca_control](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_control.py): ROS control client · Sequences planning, preview, and execution. · `meca_ws/src/meca_controller/meca_controller/meca_control.py`
- [meca_driver ×2](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_driver.py): namespaced ROS driver · One hardware-facing instance runs per arm namespace. · `meca_ws/src/meca_controller/meca_controller/meca_driver.py`
- [Robot settings](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_controller/meca_controller/meca_settings.py): configuration boundary · Centralizes IPs, namespaces, and fallback configurations. · `meca_ws/src/meca_controller/meca_controller/meca_settings.py`
- **Meca500 R3 arms**: physical hardware · Driver commands use joint degrees.

### Joint Planning

- [motion_planner](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py): ROS planner node · Serves plan and visualization requests in radians. · `meca_ws/src/meca_motion_planner/meca_motion_planner/motion_planner.py`
- [Bidirectional RRT](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/bidirectional_rrt.py): joint-space search · `meca_ws/src/meca_motion_planner/meca_motion_planner/bidirectional_rrt.py`
- [Path shortcutting](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/shortcutting.py): trajectory optimization · `meca_ws/src/meca_motion_planner/meca_motion_planner/shortcutting.py`

### Shared Cell Model

- [RobotModel](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py): kinematic collision world · Combines both arms, extrinsics, and fixed environment. · `meca_ws/src/meca_motion_planner/meca_motion_planner/robot_model.py`
- [Arm URDF](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/resources/meca/meca.urdf): robot geometry · `meca_ws/src/resources/meca/meca.urdf`
- [Environment URDF](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/resources/environment/environment.urdf): obstacle geometry · `meca_ws/src/resources/environment/environment.urdf`
- **Meshcat**: plan visualization

### ROS Contract

- **custom_interfaces**: ROS messages & services · Wire contract shared by clients, planner, and drivers.
- [MotionPlan](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/msg/MotionPlan.msg): ROS message · `meca_ws/src/custom_interfaces/msg/MotionPlan.msg`
- [GetMotionPlan](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/GetMotionPlan.srv): ROS planning service · `meca_ws/src/custom_interfaces/srv/GetMotionPlan.srv`
- [GoToPose](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/GoToPose.srv): ROS driver service · `meca_ws/src/custom_interfaces/srv/GoToPose.srv`
- [RobotStatus](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/msg/RobotStatus.msg): ROS state message · `meca_ws/src/custom_interfaces/msg/RobotStatus.msg`
- [MoveJoints & visualization](https://github.com/myersjm/mecademic-ros2/blob/main/meca_ws/src/custom_interfaces/srv/MoveJoints.srv): ROS services · Control-client execution and preview service contracts. · `meca_ws/src/custom_interfaces/srv/MoveJoints.srv`

## Connections

- meca_control → motion_planner: requests plan / preview
- meca_control → meca_driver ×2: calls namespaced motion and gripper services
- motion_planner → Bidirectional RRT: generates feasible path
- Bidirectional RRT → Path shortcutting: raw waypoint path
- Path shortcutting → motion_planner: reduced trajectory
- motion_planner → RobotModel: collision queries
- motion_planner → Meshcat: visualizes plan
- RobotModel → Arm URDF: two arm instances
- RobotModel → Environment URDF: fixed obstacles
- meca_driver ×2 → Robot settings: loads connection and safety defaults
- meca_driver ×2 → Meca500 R3 arms: MecademicPy commands
- Meca500 R3 arms → meca_driver ×2: robot and gripper state
- custom_interfaces → MotionPlan: defines
- custom_interfaces → GetMotionPlan: defines
- custom_interfaces → GoToPose: defines
- custom_interfaces → RobotStatus: defines
- custom_interfaces → MoveJoints & visualization: defines
- meca_control → custom_interfaces: uses contract
- motion_planner → custom_interfaces: uses contract
- meca_driver ×2 → custom_interfaces: uses contract
