Unable to publish varying list of PoseStamped. gives AttributeError: 'NoneType' object has no attribute 'secs' [closed]
I have created Path_arr.msg as mentioned,
string frame_id
geometry_msgs/PoseStamped[] poses
And I want to publish next 5 states of robot that should be subscribed by other local in range robots, for That I have code as below. All other part of code runs good so I am posting only necessary part of code.
next5_pub = rospy.Publisher(('/'+robot.ns+'/next5'), Path_arr, queue_size=10)
next5 = Path_arr()
next5.frame_id = robot.ns
on_goal = False
rate = rospy.Rate(5)
i = 0
while not rospy.is_shutdown() and not on_goal:
# path is array of PoseStamped
pose = path[i]
# Move the robot
if not on_goal:
linear_goal(pose, robot, mapInfo,on_goal=on_goal)
if pose.header.frame_id == robot.goal.header.frame_id:
on_goal=True
# collect next 5 pose from path to publish
if len(path)-path.index(pose) <6 :
adding = len(path)-path.index(pose)
path.extend([path[-1]]*adding)
next5.poses = path[path.index(pose)+1:path.index(pose)+6]
i+=1
next5_pub.publish(next5)
rate.sleep()
While running this node It doesn't give any error. Even rostopic list
has topic named /waffle1/next5
. But when I try to subscribe to the topic. It crash the node and give the following error.
Traceback (most recent call last):
File "/home/user/ros/src/path_planning/scripts/algo1.py", line 128, in <module>
next5_pub.publish(next5)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 882, in publish
self.impl.publish(data)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 1066, in publish
serialize_message(b, self.seq, message)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 152, in serialize_message
msg.serialize(b)
File "/home/user/ros/devel/lib/python3/dist-packages/path_planning/msg/_Path_arr.py", line 117, in serialize
buff.write(_get_struct_2I().pack(_x.secs, _x.nsecs))
AttributeError: 'NoneType' object has no attribute 'secs'
At first I had doubt that I might not have datatype of PoseStamped in variable path. But after checking the type of elements in the path I confirm it is PoseStamped
type(path[0])
<class 'geometry_msgs.msg._PoseStamped.PoseStamped'>
On other side When I try to publish static array from outside the while loop, It doesn't give error while subscribing. I am not sure what error I am making here.
Thank you.
The error message suggests that your
PoseStamped
message does not have a timestamp. Can you confirm whether that's the case?Well it was the problem. I was not using time stamp in all the poses in list because it was not necessary. But it was producing the error. Thank you for the solution. If you can copy-paste your above comment to the answers I can accept the solution.
I'm glad I could help!