I cant get data from topic

asked 2022-06-29 10:28:56 -0500

gurselturkeri gravatar image

updated 2022-06-29 10:39:43 -0500

I want to get data from rtmap topic. But something wrong in my code.

import rospy
from nav_msgs.msg import Path
from geometry_msgs.msg import PoseStamped
 import pandas as pd


def callback(data):
    pose = PoseStamped()
    pose.pose.header.frame_id = "map"
    pose.pose.position.x = float(data.pose.position.x)
    print(pose.position.x)

def listener():
    rospy.init_node("Oret_pose")
    rospy.Subscriber("/zed/mapPath",Path,callback)
    rospy.spin()
if __name__ == '__main__':
    listener()

image description

edit retag flag offensive close merge delete

Comments

1

It's not clear why you feel there's an error with your code here: what behavior have you observed with your code? What were you expecting to see compared to what is actually taking place here?

cst0 gravatar image cst0  ( 2022-06-29 10:48:58 -0500 )edit

i want to get x position and y position from "/zed/mapPath" topics and this topic type is nav_msgs/Path.

gurselturkeri gravatar image gurselturkeri  ( 2022-06-29 11:06:11 -0500 )edit

Yes, I can see that from the question. Unfortunately, you haven't provided any detail about the behavior of your code, or what you were expecting to see compared to what is actually happening, or what other nodes you have running, etc. As a result, it is not possible for anyone to answer this question other than wild guessing.

cst0 gravatar image cst0  ( 2022-06-29 11:18:55 -0500 )edit

You do seem to be trying to access a member of the message that doesn't exist, however. The path is an array of poses, each one has a pose with a position with an x. You're attempting to access a pose, which won't work.

cst0 gravatar image cst0  ( 2022-06-29 11:21:07 -0500 )edit