How to subscribe to a static_transform_publisher node?
Hi,
I have a bunch of frames that I created using the static_transform_publisher
option from tf2
in ros2
. I created them as follows:
Node( package='tf2_ros', executable='static_transform_publisher', arguments = ['0', '0', '0.5', '0', '0', '0', 'robot-base', 'robot-base_CoM'] ),
So now I want to create a listener
package that access the new frames positions and publishes a new frame, but I can't make that work. Right now this is what I have following the tf2 tutorials:
class CoM_listener(Node):
def __init__(self):
super().__init__('CoM_listener')
# Declare and acquire `target_frame` parameter
self.declare_parameter('target_frame', 'right_hand_CoM')
self.target_frame = self.get_parameter('target_frame').get_parameter_value().string_value
self.tf_buffer = Buffer()
self.tf_listener = TransformListener(self.tf_buffer, self)
# Call on_timer function every second
self.timer = self.create_timer(1.0, self.on_timer)
def on_timer(self):
# Store frame names in variables that will be used to
# compute transformations
from_frame_rel = self.target_frame
to_frame_rel = 'robot-base'
# Look up for the transformation between target_frame and CoM frames
try:
now = rclpy.time.Time()
trans = self.tf_buffer.lookup_transform(to_frame_rel, from_frame_rel, now)
except TransformException as ex:
self.get_logger().info(
f'Could not transform {to_frame_rel} to {from_frame_rel}: {ex}')
return
msg = Pose()
msg.position.x = trans.transform.translation.x * 2
msg.position.y = trans.transform.translation.y * 2
msg.position.z = trans.transform.translation.z * 2
self.publisher.publish(msg)
def main(): rclpy.init() node = CoM_listener() try: rclpy.spin(node) except KeyboardInterrupt: pass rclpy.shutdown()
But I keep getting errors like:
AttributeError: 'CoM_listener' object has no attribute 'publisher'
Or:
[listener]: Could not transform CoM to robot-base_CoM: "CoM" passed to lookupTransform argument target_frame does not exist.
Any guidance would be appreciated please.