Expand description
C FFI bindings for the PhyTrace SDK.
This module exposes the PhyTrace SDK’s core functionality through a C-compatible ABI, enabling integration with C++ ROS2 nodes and other non-Rust consumers.
§Architecture
The FFI layer manages an internal tokio::Runtime per agent handle so that
C callers never deal with async. All functions are synchronous from the caller’s
perspective.
§Memory Model
- Opaque handles (
*mut PhyTraceAgent,*mut PhyTraceBuilder,*mut PhyTraceEvent) are heap-allocated and must be freed by the corresponding_destroyfunction. - Strings returned by the library (e.g.,
phytrace_last_error,phytrace_event_to_json) must be freed withphytrace_string_free. - Null pointers are handled gracefully — functions return
PHYTRACE_ERR_NULL_PTR.
§Domains Covered
This FFI layer covers the domains required for ROS2 topic integration:
- Identity, Location, Motion, Power, Perception (Lidar + IMU), Safety, Navigation, Actuators (Joints), Operational, Communication, Context
§Domains NOT Yet Covered (tracked in issue)
AI, Audio, Compliance, Compute, Coordination, EnvironmentInteraction, HRI, Maintenance, Manipulation, Payload, Simulation, Thermal
Structs§
- PhyTrace
Agent Handle - Opaque handle to a PhyTrace agent with an embedded tokio runtime.
- PhyTrace
Builder Handle - Opaque handle to an event builder.
- PhyTrace
Event Handle - Opaque handle to a built UDM event.
Constants§
- PHYTRACE_
ERR_ AGENT - Agent lifecycle error (start, stop, flush).
- PHYTRACE_
ERR_ BUILDER - Event builder error (build validation failed).
- PHYTRACE_
ERR_ CONFIG - Configuration error (invalid YAML, missing fields, validation failure).
- PHYTRACE_
ERR_ INVALID_ ENUM - Invalid enum value passed.
- PHYTRACE_
ERR_ INVALID_ UTF8 - A string argument contained invalid UTF-8.
- PHYTRACE_
ERR_ NULL_ PTR - A null pointer was passed where a valid pointer was required.
- PHYTRACE_
ERR_ RUNTIME - Tokio runtime creation failed.
- PHYTRACE_
ERR_ SERIALIZATION - Serialization error (JSON encode/decode).
- PHYTRACE_
ERR_ TRANSPORT - Transport error (send failed).
- PHYTRACE_
ESTOP_ TYPE_ AUTOMATIC EStopType::Automatic- PHYTRACE_
ESTOP_ TYPE_ HARDWARE EStopType::Hardware- PHYTRACE_
ESTOP_ TYPE_ REMOTE EStopType::Remote- PHYTRACE_
ESTOP_ TYPE_ SOFTWARE EStopType::Software- PHYTRACE_
EVENT_ TYPE_ CUSTOM EventType::Custom- PHYTRACE_
EVENT_ TYPE_ EMERGENCY_ STOP EventType::EmergencyStop- PHYTRACE_
EVENT_ TYPE_ ERROR EventType::Error- PHYTRACE_
EVENT_ TYPE_ GOAL_ REACHED EventType::GoalReached- PHYTRACE_
EVENT_ TYPE_ MODE_ CHANGE EventType::ModeChange- PHYTRACE_
EVENT_ TYPE_ PATH_ BLOCKED EventType::PathBlocked- PHYTRACE_
EVENT_ TYPE_ REROUTING EventType::Rerouting- PHYTRACE_
EVENT_ TYPE_ SAFETY_ VIOLATION EventType::SafetyViolation- PHYTRACE_
EVENT_ TYPE_ STATE_ TRANSITION EventType::StateTransition- PHYTRACE_
EVENT_ TYPE_ SYSTEM_ SHUTDOWN EventType::SystemShutdown- PHYTRACE_
EVENT_ TYPE_ SYSTEM_ STARTUP EventType::SystemStartup- PHYTRACE_
EVENT_ TYPE_ TASK_ CANCELLED EventType::TaskCancelled- PHYTRACE_
EVENT_ TYPE_ TASK_ COMPLETED EventType::TaskCompleted- PHYTRACE_
EVENT_ TYPE_ TASK_ FAILED EventType::TaskFailed- PHYTRACE_
EVENT_ TYPE_ TASK_ STARTED EventType::TaskStarted- PHYTRACE_
EVENT_ TYPE_ TELEMETRY_ ON_ CHANGE EventType::TelemetryOnChange- PHYTRACE_
EVENT_ TYPE_ TELEMETRY_ PERIODIC EventType::TelemetryPeriodic- PHYTRACE_
EVENT_ TYPE_ TELEMETRY_ SNAPSHOT EventType::TelemetrySnapshot- PHYTRACE_
LOCALIZATION_ QUALITY_ EXCELLENT LocalizationQuality::Excellent- PHYTRACE_
LOCALIZATION_ QUALITY_ FAIR LocalizationQuality::Fair- PHYTRACE_
LOCALIZATION_ QUALITY_ GOOD LocalizationQuality::Good- PHYTRACE_
LOCALIZATION_ QUALITY_ LOST LocalizationQuality::Lost- PHYTRACE_
LOCALIZATION_ QUALITY_ POOR LocalizationQuality::Poor- PHYTRACE_
OK - Operation succeeded.
- PHYTRACE_
OPERATIONAL_ MODE_ AUTONOMOUS OperationalMode::Autonomous- PHYTRACE_
OPERATIONAL_ MODE_ EMERGENCY OperationalMode::Emergency- PHYTRACE_
OPERATIONAL_ MODE_ IDLE OperationalMode::Idle- PHYTRACE_
OPERATIONAL_ MODE_ LEARNING OperationalMode::Learning- PHYTRACE_
OPERATIONAL_ MODE_ MAINTENANCE OperationalMode::Maintenance- PHYTRACE_
OPERATIONAL_ MODE_ MANUAL OperationalMode::Manual- PHYTRACE_
OPERATIONAL_ MODE_ SEMI_ AUTONOMOUS OperationalMode::SemiAutonomous- PHYTRACE_
OPERATIONAL_ MODE_ TELEOPERATED OperationalMode::Teleoperated- PHYTRACE_
OPERATIONAL_ STATE_ BOOTING OperationalState::Booting- PHYTRACE_
OPERATIONAL_ STATE_ CHARGING OperationalState::Charging- PHYTRACE_
OPERATIONAL_ STATE_ EMERGENCY_ STOPPED OperationalState::EmergencyStopped- PHYTRACE_
OPERATIONAL_ STATE_ ERROR OperationalState::Error- PHYTRACE_
OPERATIONAL_ STATE_ EXECUTING_ TASK OperationalState::ExecutingTask- PHYTRACE_
OPERATIONAL_ STATE_ MANIPULATING OperationalState::Manipulating- PHYTRACE_
OPERATIONAL_ STATE_ NAVIGATING OperationalState::Navigating- PHYTRACE_
OPERATIONAL_ STATE_ OFF OperationalState::Off- PHYTRACE_
OPERATIONAL_ STATE_ PAUSED OperationalState::Paused- PHYTRACE_
OPERATIONAL_ STATE_ READY OperationalState::Ready- PHYTRACE_
OPERATIONAL_ STATE_ RECOVERING OperationalState::Recovering- PHYTRACE_
OPERATIONAL_ STATE_ SHUTTING_ DOWN OperationalState::ShuttingDown- PHYTRACE_
PATH_ STATE_ BLOCKED PathState::Blocked- PHYTRACE_
PATH_ STATE_ COMPLETED PathState::Completed- PHYTRACE_
PATH_ STATE_ EXECUTING PathState::Executing- PHYTRACE_
PATH_ STATE_ FAILED PathState::Failed- PHYTRACE_
PATH_ STATE_ NONE PathState::None- PHYTRACE_
PATH_ STATE_ PLANNING PathState::Planning- PHYTRACE_
PATH_ STATE_ VALID PathState::Valid- PHYTRACE_
SAFETY_ STATE_ EMERGENCY_ STOP SafetyState::EmergencyStop- PHYTRACE_
SAFETY_ STATE_ NORMAL SafetyState::Normal- PHYTRACE_
SAFETY_ STATE_ PROTECTIVE_ STOP SafetyState::ProtectiveStop- PHYTRACE_
SAFETY_ STATE_ REDUCED_ SPEED SafetyState::ReducedSpeed- PHYTRACE_
SAFETY_ STATE_ SAFETY_ INTERLOCK SafetyState::SafetyInterlock- PHYTRACE_
SAFETY_ STATE_ WARNING SafetyState::Warning- PHYTRACE_
SOURCE_ TYPE_ AGV SourceType::Agv- PHYTRACE_
SOURCE_ TYPE_ AMR SourceType::Amr- PHYTRACE_
SOURCE_ TYPE_ AUTONOMOUS_ FORKLIFT SourceType::AutonomousForklift- PHYTRACE_
SOURCE_ TYPE_ AUTONOMOUS_ VEHICLE SourceType::AutonomousVehicle- PHYTRACE_
SOURCE_ TYPE_ CLEANING_ ROBOT SourceType::CleaningRobot- PHYTRACE_
SOURCE_ TYPE_ COBOT SourceType::Cobot- PHYTRACE_
SOURCE_ TYPE_ CUSTOM SourceType::Custom- PHYTRACE_
SOURCE_ TYPE_ DELIVERY_ ROBOT SourceType::DeliveryRobot- PHYTRACE_
SOURCE_ TYPE_ DRONE SourceType::Drone- PHYTRACE_
SOURCE_ TYPE_ ELECTRIC_ VEHICLE SourceType::ElectricVehicle- PHYTRACE_
SOURCE_ TYPE_ HUMAN SourceType::Human- PHYTRACE_
SOURCE_ TYPE_ HUMANOID SourceType::Humanoid- PHYTRACE_
SOURCE_ TYPE_ INDUSTRIAL_ ARM SourceType::IndustrialArm- PHYTRACE_
SOURCE_ TYPE_ INSPECTION_ ROBOT SourceType::InspectionRobot- PHYTRACE_
SOURCE_ TYPE_ MOBILE_ MANIPULATOR SourceType::MobileManipulator- PHYTRACE_
SOURCE_ TYPE_ QUADRUPED SourceType::Quadruped- PHYTRACE_
SOURCE_ TYPE_ SECURITY_ ROBOT SourceType::SecurityRobot- PHYTRACE_
SOURCE_ TYPE_ SIMULATION SourceType::Simulation
Functions§
- phytrace_
agent_ ⚠create_ from_ file - Create a PhyTrace agent from a YAML configuration file path.
- phytrace_
agent_ ⚠create_ from_ yaml - Create a PhyTrace agent from a YAML configuration string.
- phytrace_
agent_ ⚠create_ mock - Create a PhyTrace agent with a mock transport for testing.
- phytrace_
agent_ ⚠destroy - Destroy and free an agent handle.
- phytrace_
agent_ ⚠flush - Flush any buffered events to the transport.
- phytrace_
agent_ ⚠is_ running - Check if the agent is currently running.
- phytrace_
agent_ ⚠send - Send a built event through the agent’s transport.
- phytrace_
agent_ ⚠start - Start the agent (connects transport, begins background workers).
- phytrace_
agent_ ⚠stop - Stop the agent gracefully (flushes buffer, disconnects transport).
- phytrace_
builder_ ⚠build - Build the event, consuming the builder.
- phytrace_
builder_ ⚠build_ unchecked - Build the event without validation, consuming the builder.
- phytrace_
builder_ ⚠destroy - Destroy a builder without building an event.
- phytrace_
builder_ ⚠new - Create a new event builder from an agent’s configuration.
- phytrace_
builder_ ⚠set_ actuators_ joints - Set the actuators domain with joint state data.
- phytrace_
builder_ ⚠set_ communication - Set the communication domain on the builder.
- phytrace_
builder_ ⚠set_ context - Set the context domain on the builder.
- phytrace_
builder_ ⚠set_ event_ type - Set the event type on the builder.
- phytrace_
builder_ ⚠set_ extensions_ json - Set arbitrary extensions on the builder as a JSON string.
- phytrace_
builder_ ⚠set_ identity - Set the identity domain on the builder.
- phytrace_
builder_ ⚠set_ location - Set the location domain on the builder.
- phytrace_
builder_ ⚠set_ motion - Set the motion domain on the builder.
- phytrace_
builder_ ⚠set_ navigation - Set the navigation domain on the builder.
- phytrace_
builder_ ⚠set_ operational - Set the operational domain on the builder.
- phytrace_
builder_ ⚠set_ perception_ imu - Set the IMU sensor in the perception domain.
- phytrace_
builder_ ⚠set_ perception_ lidar - Set a lidar sensor in the perception domain.
- phytrace_
builder_ ⚠set_ power - Set the power domain on the builder.
- phytrace_
builder_ ⚠set_ safety - Set the safety domain on the builder.
- phytrace_
builder_ ⚠set_ source_ type - Set the source type on the builder.
- phytrace_
event_ ⚠destroy - Destroy a built event without sending it.
- phytrace_
event_ ⚠to_ json - Serialize a built event to JSON.
- phytrace_
last_ error - Retrieve the last error message from the FFI layer.
- phytrace_
sdk_ version - Get the PhyTrace SDK version string.
- phytrace_
string_ ⚠free - Free a string allocated by the PhyTrace FFI layer.
- phytrace_
udm_ version - Get the UDM version string supported by this SDK.