0
$\begingroup$

Hey I am new to ROS2 and working in a large repository. I have created a node that listens to a topic that is of type PoseStamped. I created this listening node in python. However when I run it, it gives an error which I do not understand. Is there something that I am missing?

import rclpy
from rclpy.node import Node
from geometry_msgs.msg import PoseStamped

class PoseSubscriberNode(Node):

    def __init__(self):
        super().__init__("pose_subscriber")
        self.get_logger().info("Hello I am working")
        self.pose_subscription = self.create_subscription(
            PoseStamped, "/mocap/turtlebot/pose", self.listener_callback,10
            )       
        self.pose_subscription  # prevent unused variable warning

    def listener_callback(self, msg):
        self.get_logger().info("I will get the Pose for you now")
        self.get_logger().info(msg.pose.position)
        

def main(args=None):
        rclpy.init(args=args)
        pose_subscriber = PoseSubscriberNode()
        rclpy.spin(pose_subscriber)
        pose_subscriber.destroy_node()
        rclpy.shutdown()

if __name__ == '__main__':
    main()

The indenation is not fully correct in this text box but it is in the file. The error it gives is of the following type:

[INFO] [1711998839.108264885] [pose_subscriber]: Hello I am working
[INFO] [1711998839.813227729] [pose_subscriber]: I will get the Pose for you now
Traceback (most recent call last):
  File "/home/tijmen/ros2_ws/install/tijmen_core_project/lib/tijmen_core_project/pose_subscriber.py", line 29, in <module>
    main()
  File "/home/tijmen/ros2_ws/install/tijmen_core_project/lib/tijmen_core_project/pose_subscriber.py", line 24, in main
    rclpy.spin(pose_subscriber)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
    executor.spin_once()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 739, in spin_once
    self._spin_once_impl(timeout_sec)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 736, in _spin_once_impl
    raise handler.exception()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
    self._handler.send(None)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 437, in handler
    await call_coroutine(entity, arg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 362, in _execute_subscription
    await await_or_execute(sub.callback, msg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
    return callback(*args)
  File "/home/tijmen/ros2_ws/install/tijmen_core_project/lib/tijmen_core_project/pose_subscriber.py", line 18, in listener_callback
    self.get_logger().info(msg.pose.position)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/impl/rcutils_logger.py", line 329, in info
    return self.log(message, LoggingSeverity.INFO, **kwargs)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/impl/rcutils_logger.py", line 318, in log
    _rclpy.rclpy_logging_rcutils_log(
TypeError: rclpy_logging_rcutils_log(): incompatible function arguments. The following argument types are supported:
    1. (arg0: int, arg1: str, arg2: str, arg3: str, arg4: str, arg5: int) -> None

Invoked with: <LoggingSeverity.INFO: 20>, 'pose_subscriber', geometry_msgs.msg.Point(x=-5.6917534846332944e-05, y=1.4944934235090915e-11, z=0.010007251957693237), 'listener_callback', '/home/tijmen/ros2_ws/install/tijmen_core_project/lib/tijmen_core_project/pose_subscriber.py', 18
[ros2run]: Process exited with failure 1
```
$\endgroup$

1 Answer 1

3
$\begingroup$

You are trying to log the position which is a message of type geometry_msgs/Point. This message contains the x, y and z coordinates of the pose you received. The self.get_logger().info() function takes in a string as an argument.

If you wanted to log the components of the position you could use an f-string like:

self.get_logger().info(f'x: {msg.pose.position.x}, y: {msg.pose.position.y}, z: {msg.pose.position.z}')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.