diff --git a/README.md b/README.md index 10f3755..8601661 100644 --- a/README.md +++ b/README.md @@ -179,11 +179,15 @@ def main(): YasminViewerPub("yasmin_demo", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": @@ -296,11 +300,15 @@ def main(): YasminViewerPub("YASMIN_SERVICE_CLIENT_DEMO", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": @@ -411,11 +419,15 @@ def main(): blackboard["n"] = 10 # execute FSM - outcome = sm(blackboard) - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm(blackboard) + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": @@ -501,11 +513,15 @@ def main(): YasminViewerPub("YASMIN_MONITOR_DEMO", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": @@ -655,11 +671,16 @@ def main(): # execute FSM blackboard = Blackboard() blackboard["waypoints_num"] = 2 - outcome = sm(blackboard) - yasmin.YASMIN_LOG_INFO(outcome) + + try: + outcome = sm(blackboard) + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": diff --git a/yasmin_demos/yasmin_demos/action_client_demo.py b/yasmin_demos/yasmin_demos/action_client_demo.py index 1f82a4d..8819d94 100755 --- a/yasmin_demos/yasmin_demos/action_client_demo.py +++ b/yasmin_demos/yasmin_demos/action_client_demo.py @@ -104,11 +104,15 @@ def main(): blackboard["n"] = 10 # execute FSM - outcome = sm(blackboard) - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm(blackboard) + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": diff --git a/yasmin_demos/yasmin_demos/monitor_demo.py b/yasmin_demos/yasmin_demos/monitor_demo.py index 59f2c62..7708ac4 100755 --- a/yasmin_demos/yasmin_demos/monitor_demo.py +++ b/yasmin_demos/yasmin_demos/monitor_demo.py @@ -83,11 +83,15 @@ def main(): YasminViewerPub("YASMIN_MONITOR_DEMO", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": diff --git a/yasmin_demos/yasmin_demos/nav_demo.py b/yasmin_demos/yasmin_demos/nav_demo.py index 1ba9f7b..d8a577e 100755 --- a/yasmin_demos/yasmin_demos/nav_demo.py +++ b/yasmin_demos/yasmin_demos/nav_demo.py @@ -157,11 +157,16 @@ def main(): # execute FSM blackboard = Blackboard() blackboard["waypoints_num"] = 2 - outcome = sm(blackboard) - yasmin.YASMIN_LOG_INFO(outcome) + + try: + outcome = sm(blackboard) + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": diff --git a/yasmin_demos/yasmin_demos/service_client_demo.py b/yasmin_demos/yasmin_demos/service_client_demo.py index d5c62a3..f4cdfba 100755 --- a/yasmin_demos/yasmin_demos/service_client_demo.py +++ b/yasmin_demos/yasmin_demos/service_client_demo.py @@ -106,11 +106,15 @@ def main(): YasminViewerPub("YASMIN_SERVICE_CLIENT_DEMO", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__": diff --git a/yasmin_demos/yasmin_demos/yasmin_demo.py b/yasmin_demos/yasmin_demos/yasmin_demo.py index 11536c0..b12d41b 100755 --- a/yasmin_demos/yasmin_demos/yasmin_demo.py +++ b/yasmin_demos/yasmin_demos/yasmin_demo.py @@ -93,11 +93,15 @@ def main(): YasminViewerPub("yasmin_demo", sm) # execute FSM - outcome = sm() - yasmin.YASMIN_LOG_INFO(outcome) + try: + outcome = sm() + yasmin.YASMIN_LOG_INFO(outcome) + except KeyboardInterrupt: + sm.cancel_state() # shutdown ROS 2 - rclpy.shutdown() + if rclpy.ok(): + rclpy.shutdown() if __name__ == "__main__":