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

Rospy not working even though it is imported?

asked 2016-03-15 10:25:19 -0500

pgigioli gravatar image

My python script used to run but now does not work. It does not give any errors but only returns a blank terminal. It is also executable. Below is a simplified version of the code with the output. It seems the rospy functions are not working even though rospy is imported. When I wrote the script as an individual script, it worked fine but as soon as I started messing with it so that it could be included in the launch file, it stopped working. Any ideas?

 #!/usr/bin/env python
 import rospy
 import roslib

 print "test1"
 if __name__ == '__main__':
       print "test2"
       rospy.loginfo("test3")
       rospy.init_node('autodocking', anonymous=True)

OUTPUT:
test1
test2
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-03-15 10:38:01 -0500

lucasw gravatar image

The rospy.loginfo (and any other rospy function) ought to go after the init_node.

edit flag offensive delete link more

Comments

That solved the issue when I run the script individually but now when I run the script from a launch file or from rosrun, I get the error "from: can't read /var/mail/move_base_msgs.msg; from: can't read /var/mail/std_msgs.msg, etc." (basically all of the imports that I have) and nothing prints.

pgigioli gravatar image pgigioli  ( 2016-03-15 10:46:08 -0500 )edit
0

answered 2016-03-15 11:05:20 -0500

pgigioli gravatar image

I fixed the problem. I had accidentally removed the shebang statement #!/usr/bin/env python. I also had to remove the build and run depend statements in package.xml for this node and remove the add_executable statement in the CMakeLists.txt for this node. Thanks!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-15 10:21:49 -0500

Seen: 1,922 times

Last updated: Mar 15 '16