Foxglove Schemas Protobuf
This library provides precompiled Protocol Buffer (protobuf) schemas for Foxglove, a web-based visualization and debugging tool for robotics. It allows Python applications to serialize and deserialize data according to Foxglove's standardized message definitions, facilitating interoperability within the Foxglove ecosystem. The current version is 0.3.0, and updates typically align with new schema definitions released by the broader Foxglove SDK.
Common errors
-
ModuleNotFoundError: No module named 'foxglove_schemas_protobuf.SomeSchema_pb2'
cause The specific schema's `_pb2` file does not exist, or the schema name is misspelled.fixVerify the exact schema name from the Foxglove schemas repository. The Python module structure is `foxglove_schemas_protobuf.<SchemaName>_pb2` (e.g., `ImageAnnotation_pb2`). Ensure the package is correctly installed. -
google.protobuf.message.DecodeError: Truncated message
cause Attempting to deserialize an incomplete, corrupted, or incompatible (e.g., non-protobuf or wrong schema type) byte string.fixEnsure the input byte string is a complete and valid serialized Protobuf message for the target schema. Check the source of the data for corruption or mismatch. Verify that both sender and receiver are using compatible schema versions. -
AttributeError: 'FrameTransform' object has no attribute 'old_field_name'
cause You are attempting to access a field that no longer exists or has been renamed in the version of `foxglove-schemas-protobuf` you are using, or you are trying to parse data from a newer schema version with an older client.fixUpdate your code to reflect the current schema definition by consulting the Foxglove schema documentation or upgrading your `foxglove-schemas-protobuf` package and re-evaluating the available fields. Alternatively, ensure the data being deserialized matches the expected schema version.
Warnings
- gotcha The `foxglove-schemas-protobuf` Python package may lag behind schema updates in other Foxglove SDK languages (TypeScript, C++, Rust). If you're working with the latest schema definitions in other environments, ensure your Python package version is compatible or sufficiently recent.
- gotcha Incompatibility with the `protobuf` library version. Protobuf generated code is sensitive to the version of the `protobuf` runtime library installed. Mismatched versions can lead to serialization/deserialization errors or unexpected behavior.
- gotcha Schema definition changes between `foxglove-schemas-protobuf` versions. While Protobuf is designed for backward compatibility, changes like renaming fields, altering field types, or modifying enum values can lead to `AttributeError` during access or `DecodeError` during deserialization if an older client tries to parse data from a newer schema (or vice-versa).
Install
-
pip install foxglove-schemas-protobuf
Imports
- FrameTransform
import foxglove_schemas_protobuf.FrameTransform
from foxglove_schemas_protobuf.FrameTransform_pb2 import FrameTransform
- Timestamp
from protobuf.timestamp_pb2 import Timestamp
from google.protobuf.timestamp_pb2 import Timestamp
Quickstart
from foxglove_schemas_protobuf.FrameTransform_pb2 import FrameTransform
from google.protobuf.timestamp_pb2 import Timestamp
# Create a Timestamp
ts = Timestamp()
ts.seconds = 1678886400 # Example: March 15, 2023 12:00:00 PM UTC
ts.nanos = 123456789
# Create a FrameTransform message
transform = FrameTransform(
timestamp=ts,
parent_frame_id="base_link",
child_frame_id="tool0",
translation_x=1.0,
translation_y=0.5,
translation_z=0.2,
rotation_x=0.0,
rotation_y=0.0,
rotation_z=0.0,
rotation_w=1.0
)
# Serialize to bytes
serialized_data = transform.SerializeToString()
print(f"Serialized FrameTransform data length: {len(serialized_data)} bytes")
# Deserialize from bytes
deserialized_transform = FrameTransform()
deserialized_transform.ParseFromString(serialized_data)
print(f"\nDeserialized Parent frame: {deserialized_transform.parent_frame_id}")
print(f"Deserialized Child frame: {deserialized_transform.child_frame_id}")
print(f"Deserialized Timestamp: {deserialized_transform.timestamp.seconds}.{deserialized_transform.timestamp.nanos}")
assert deserialized_transform.parent_frame_id == "base_link"
assert deserialized_transform.translation_x == 1.0