ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

How to get length of array if poses from nav_msgs/Path.msg

asked 2022-01-23 12:53:27 -0600

distro gravatar image

Does anyone know how to use the message type nav_msgs/Path.msg. according to the wiki it is an array of poses that are used to plan a path but it I'm unable to get the msg in array form. I need to get the length of the array for my purposes which is why I'm asking. How do I go about that? right now I just have this:

#!/usr/bin/python3
import rospy
from nav_msgs.msg import Path
from rospy.numpy_msg import numpy_msg
import numpy as np

def callback(msg):
    print("list: ", msg)

rospy.init_node("tester_3")
rospy.Subscriber("/move_base/NavfnROS/plan",Path,callback)
rospy.spin()
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-01-24 13:45:18 -0600

distro gravatar image

updated 2022-01-24 13:46:42 -0600

Thanks guys! I typed pose instead of poses, that messed me up. Its fixed now, its len(msg.poses)

edit flag offensive delete link more
1

answered 2022-01-23 14:05:57 -0600

ljaniec gravatar image

updated 2022-01-23 16:49:20 -0600

Shouldn't it be rather print("list: ", msg.data) in your callback? Check ROS documentation there for correct form of ROS1 subscriber. The array poses can be acquired as the field of msg.data.

edit flag offensive delete link more

Comments

1

You can access the whole Path with msg.data and the pose list with msg.data.pose. To get the length, you would need to use print("list: ", len(msg.data.poses)).

miura gravatar image miura  ( 2022-01-23 16:44:16 -0600 )edit

@ljaniec when I used msg.data it gave an error about Path not having attribute data or something like that.

distro gravatar image distro  ( 2022-01-24 12:06:29 -0600 )edit

@ljaniec I figured it out thanks!

distro gravatar image distro  ( 2022-01-24 13:48:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2022-01-23 12:53:27 -0600

Seen: 112 times

Last updated: Jan 24 '22