ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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:

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)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

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

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: ", in your callback? Check ROS documentation there for correct form of ROS1 subscriber. The array poses can be acquired as the field of

edit flag offensive delete link more



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

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

@ljaniec when I used 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



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

Seen: 112 times

Last updated: Jan 24 '22