2026-03-10 21:22:09 +07:00
# blockly_interfaces — ROS2 Interfaces
2026-03-09 23:35:48 +07:00
2026-03-10 21:22:09 +07:00
Provides custom ROS2 action and message definitions for the Blockly Robot Controller.
2026-03-09 23:35:48 +07:00
## BlocklyAction.action
Defined in [`action/BlocklyAction.action` ](action/BlocklyAction.action ):
```
# GOAL — one instruction to execute
2026-03-10 21:22:09 +07:00
string command # e.g. "digital_out", "delay", "digital_in"
string[] param_keys # e.g. ["gpio", "state"]
string[] param_values # e.g. ["17", "true"]
2026-03-09 23:35:48 +07:00
---
# RESULT — sent after action completes or fails
bool success
string message # success message or informative error description
---
# FEEDBACK — sent during execution
string status # "executing" | "done" | "error"
```
This interface is **generic by design** — adding new commands never requires modifying the `.action` file. The `command` + `param_keys` /`param_values` pattern supports any instruction with any parameters.
2026-03-10 21:22:09 +07:00
## GpioWrite.msg & GpioRead.msg
Defined in [`msg/GpioWrite.msg` ](msg/GpioWrite.msg ) and [`msg/GpioRead.msg` ](msg/GpioRead.msg ):
```
# GpioWrite — digital output command (executor → gpio_node)
uint8 pin
bool state
# GpioRead — digital input state (gpio_node → executor)
uint8 pin
bool state
```
Used for communication between the executor's GPIO handlers and the `gpio_node` running on Raspberry Pi.
2026-03-16 20:08:19 +07:00
## PwmWrite.msg
Defined in [`msg/PwmWrite.msg` ](msg/PwmWrite.msg ):
```
# PwmWrite — PWM duty cycle command (executor → pca9685_node)
uint8 address # I2C device address (e.g. 0x40)
uint8 channel # PWM channel (0-15)
uint16 value # Duty cycle (0-4095, 12-bit)
```
Used for communication between the executor's PWM handler and the `pca9685_node` running on Raspberry Pi.
## EncoderRead.msg
Defined in [`msg/EncoderRead.msg` ](msg/EncoderRead.msg ):
```
# EncoderRead — rotary encoder angle (as5600_node → executor)
uint8 encoder_id # Encoder index (0, 1, 2, ...)
float32 angle # Angle in degrees (0.0-360.0)
uint16 raw_angle # Raw 12-bit value (0-4095)
```
Used for communication between the `as5600_node` running on Raspberry Pi and the executor's encoder handler.
2026-03-09 23:35:48 +07:00
## Building
```bash
pixi run build-interfaces
```
2026-03-10 21:22:09 +07:00
This must be run before building any other package. The generated Python modules are then importable as:
2026-03-09 23:35:48 +07:00
```python
from blockly_interfaces.action import BlocklyAction
2026-03-16 20:08:19 +07:00
from blockly_interfaces.msg import GpioWrite, GpioRead, PwmWrite, EncoderRead
2026-03-09 23:35:48 +07:00
```
## Usage
See [`src/blockly_executor/README.md` ](../blockly_executor/README.md ) for how the executor uses this interface, and [`src/blockly_app/BLOCKS.md` ](../blockly_app/BLOCKS.md#79-data-flow-js-block--python-handler--hardware ) for the full data flow from JS block to hardware.