Ask Your Question
0

Can't see my python node in rosnode list?

asked 2019-08-15 17:09:39 -0500

Anonymous gravatar image

updated 2019-08-15 19:50:20 -0500

I am trying to simulate a simple code in Gazebo to takeoff, but there is no response. However, I do not have any error codes and after typing rosnode list I don't see my python node. Could some please explain to me what could be the cause of this?

#!/usr/bin/env python 

#import library ros 
import rospy 
from geometry_msgs.msg import Twist
from std_msgs.msg import Empty

rospy.init_node('my_drone_node',anonymous=True)

empty= Empty()

pub_takeoff = rospy.Publisher('/ardrone/takeoff',Empty,queue_size =10)

land_drone = rospy.Publisher('ardrone/land',Empty,queue_size=10)

pub_takeoff.publish(empty)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-08-15 19:58:33 -0500

It appears your node is only very short lived. When your code runs, it inits ROS, creates publishers, tries to publish and then exits. You'll be able to see it in the node list if you add a rospy.spin() at the end as that prevents the direct exit. That won't help with the functionality you want to use, however.

When creating publishers and directly afterwards publishing on them you have to be aware that this won't work in most cases as detailed here, as publishers need to register with the master before they actually become active. The quick fix to that is adding a sleep after publisher creation.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-08-15 17:09:39 -0500

Seen: 15 times

Last updated: Aug 15