Robotics StackExchange | Archived questions

Can't see my python node in rosnode list?

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)

Asked by Anonymous on 2019-08-15 17:09:39 UTC

Comments

Answers

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.

Asked by Stefan Kohlbrecher on 2019-08-15 19:58:33 UTC

Comments