ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Unable to publish varying list of PoseStamped. gives AttributeError: 'NoneType' object has no attribute 'secs' [closed]

asked 2021-04-26 08:01:23 -0500

aarsh_t gravatar image

updated 2021-04-26 08:04:44 -0500

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by aarsh_t
close date 2021-05-02 21:16:28.084151

Comments

buff.write(_get_struct_2I().pack(_x.secs, _x.nsecs))
AttributeError: 'NoneType' object has no attribute 'secs'

The error message suggests that your PoseStamped message does not have a timestamp. Can you confirm whether that's the case?

tryan gravatar image tryan  ( 2021-04-26 09:02:52 -0500 )edit
1

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.

aarsh_t gravatar image aarsh_t  ( 2021-04-26 10:08:52 -0500 )edit

I'm glad I could help!

tryan gravatar image tryan  ( 2021-04-26 10:18:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-26 10:16:54 -0500

tryan gravatar image
buff.write(_get_struct_2I().pack(_x.secs, _x.nsecs))
AttributeError: 'NoneType' object has no attribute 'secs'

The error message suggests that your PoseStamped message does not have a timestamp.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-26 08:01:23 -0500

Seen: 846 times

Last updated: Apr 26 '21