How to get x,y from /move_base/NavfnROS/plan [closed]

asked 2018-06-11 20:04:31 -0500

Liuche gravatar image

updated 2018-06-12 05:49:30 -0500

I want to record the msg that on the /move_base/NavfnROS/plan

These msg class is Path , but when i whrite a callback to catch the data of this topic I can't Get X,Y separately

my callback funtion is below:

def Global_Callback(data):
    global glo_x, glo_y
    glo_x = data.poses.pose.positon.x
    glo_x = data.poses.pose.positon.y

I run it ,it will show the failed msg below:

AttributeError: "list" object has no attribute 'pose'

Where am I doing wrong?

when I change funtion as this

def Global_Callback(data):
    global glo_x, glo_y
    glo_x = data.poses

It can run normally, But I Only want X and Y of these pose in the Path

edit retag flag offensive reopen merge delete

Closed for the following reason too localized by Liuche
close date 2018-06-13 05:21:31.574447

Comments

it's a list,operator[]

pengjiawei gravatar image pengjiawei  ( 2018-06-11 23:03:19 -0500 )edit

yes i know,but can i only grab the coordinate of position?

because i can use the same way to grab the coordinates of /odom

i want do same thing on this topic

Liuche gravatar image Liuche  ( 2018-06-11 23:12:53 -0500 )edit

Please stop "yelling" (using caps), there is no need.

@pengjiawei is correct: poses is a list, you cannot use the dot operator directly on it. You need to first index into it using the [] operator.

This is not a ROS problem, but a basic Python one.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-12 05:47:48 -0500 )edit

sorry for using caps, OK I'll try to split it.

ANW thank you for tour answer

Liuche gravatar image Liuche  ( 2018-06-12 05:53:38 -0500 )edit

Finally, I used the excel filter to successfully analyze the remaining simple data.

thank you~~

Liuche gravatar image Liuche  ( 2018-06-13 05:20:33 -0500 )edit

The following did not work for you?

for pose in data.poses:
    print ("{}; {}".format(pose.position.x, pose.position.y))
gvdhoorn gravatar image gvdhoorn  ( 2018-06-14 02:12:03 -0500 )edit

Hello! Because ROS I was the first time I was exposed to the programming language, so my concept of using Python is still very basic. I have not tried this method and I will try again!

Liuche gravatar image Liuche  ( 2018-06-14 04:06:20 -0500 )edit

I would recommend to first learn a bit of Python (without ROS) and then start looking at ROS again.

A lot of 'magical things' will suddenly probably become a lot more transparent to you.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-14 04:07:26 -0500 )edit