This package contains LCM generated Python bindings for ROS message types.
pip install -e .To use these message types in your Python code, import them with the lcm_msgs prefix:
# Instead of
# from sensor_msgs import JointState
# Use
from lcm_msgs.sensor_msgs import JointState
from lcm_msgs.geometry_msgs import Pose, Twist
from lcm_msgs.std_msgs import Header
# Create and use the message instances
joint_state = JointState()
joint_state.name = ["joint1", "joint2"]
joint_state.position = [0.0, 1.0]
joint_state.name_length = len(joint_state.name)
joint_state.position_length = len(joint_state.position)
# Create a Twist message
twist = Twist()
twist.linear.x = 1.0
twist.linear.y = 2.0
twist.angular.z = 0.5
# Encode for LCM publishing
encoded_msg = joint_state.encode()- Generate Python bindings for your LCM message types
- Place them in the appropriate package directory
- Update the imports to use the
lcm_msgsprefix when importing from other message packages - Run the provided fix script to correct internal imports:
./fix_imports.pyIf you encounter import errors like:
AttributeError: module 'geometry_msgs' has no attribute 'Vector3'
It's likely due to the internal import structure of the generated LCM files. Run the fix_imports.py script:
./fix_imports.pyTo update imports in your existing code to use the lcm_msgs namespace, run:
./update_imports.py /path/to/your/codeThe package structure supports intellisense in most IDEs. You'll get autocompletion and type hints for all message types and their attributes.