Created
April 9, 2021 12:56
-
-
Save eborghi10/489ec36c36af6eb65d657deab17a87ba to your computer and use it in GitHub Desktop.
ROSInterruptException example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
name = "caught_exception" | |
rospy.init_node(name) | |
r = rospy.Rate(1.) | |
start = rospy.Time.now() | |
while not rospy.is_shutdown(): | |
rospy.logwarn(name) | |
try: | |
r.sleep() | |
except rospy.ROSInterruptException: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
name = "dying_node" | |
rospy.init_node(name) | |
r = rospy.Rate(1.) | |
start = rospy.Time.now() | |
while not rospy.is_shutdown(): | |
rospy.logwarn(name) | |
r.sleep() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
name = "killer_node" | |
rospy.init_node(name) | |
r = rospy.Rate(1.) | |
start = rospy.Time.now() | |
while not rospy.is_shutdown() and (rospy.Time.now() - start) < rospy.Duration(5.): | |
rospy.logwarn(name) | |
r.sleep() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<launch> | |
<node pkg="gazebo_ros" name="gzserver" type="gzserver" required="true"/> | |
<node pkg="my_pkg" name="killer" type="killer_node.py" output="screen" required="true"/> | |
<node pkg="my_pkg" name="testing" type="dying_node.py" output="screen" required="false"/> | |
<!-- These two nodes solve the issue from above --> | |
<!-- <node pkg="my_pkg" name="testing" type="caught_exception.py" output="screen" required="false"/> --> | |
<!-- <node pkg="my_pkg" name="testing" type="timer_node.py" output="screen" required="false"/> --> | |
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rospy | |
def timer(event): | |
print 'Timer called at ' + str(event.current_real) | |
name = "timer_node" | |
rospy.init_node(name) | |
rospy.Timer(rospy.Duration(1.), timer) | |
rospy.spin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment