ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
if __name__ == '__main__':
doesn't matter at here (in the second code), also you could run your code without it like here:
.
.
.
# MAIN
try:
process()
except rospy.ROSInterruptException:
pass
i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':
The main difference between First code and Second code is that the Second code used the rospy.spin()
method which is a built-in ROS loop that triggers the publisher and subscriber in another thread, so you wouldn't need to an inner while in your code like the First example.
2 | No.2 Revision |
if __name__ == '__main__':
doesn't matter at here (in the second code), also you could run your code without it like here:
.
.
.
# MAIN
try:
process()
except rospy.ROSInterruptException:
pass
i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':
The main difference between First code and Second code is that the Second First code used the rospy.spin()
method which is a built-in ROS loop that triggers the publisher publisher
and subscriber subscriber
in another thread, so you wouldn't need to an inner while while
in your code like the First Second example.