diff --git a/source/Tutorials/Intermediate/Tf2/Writing-A-Tf2-Static-Broadcaster-Py.rst b/source/Tutorials/Intermediate/Tf2/Writing-A-Tf2-Static-Broadcaster-Py.rst index b3ae335f1ed..90762f982b6 100644 --- a/source/Tutorials/Intermediate/Tf2/Writing-A-Tf2-Static-Broadcaster-Py.rst +++ b/source/Tutorials/Intermediate/Tf2/Writing-A-Tf2-Static-Broadcaster-Py.rst @@ -166,26 +166,28 @@ Now open the file called ``static_turtle_tf2_broadcaster.py`` using your preferr def main(): + logger = rclpy.logging.get_logger('logger') + + # obtain parameters from command line arguments + if len(sys.argv) != 8: + logger.info('Invalid number of parameters. Usage: \n' + '$ ros2 run learning_tf2_py static_turtle_tf2_broadcaster' + 'child_frame_name x y z roll pitch yaw') + sys.exit(1) + + if sys.argv[1] == 'world': + logger.info('Your static turtle name cannot be "world"') + sys.exit(2) + + # pass parameters and initialize node try: - logger = rclpy.logging.get_logger('logger') - - # obtain parameters from command line arguments - if len(sys.argv) != 8: - logger.info('Invalid number of parameters. Usage: \n' - '$ ros2 run learning_tf2_py static_turtle_tf2_broadcaster' - 'child_frame_name x y z roll pitch yaw') - sys.exit(1) - - if sys.argv[1] == 'world': - logger.info('Your static turtle name cannot be "world"') - sys.exit(2) - - # pass parameters and initialize node - with rclpy.init(): - node = StaticFramePublisher(sys.argv) - rclpy.spin(node) + rclpy.init() + node = StaticFramePublisher(sys.argv) + rclpy.spin(node) except (KeyboardInterrupt, ExternalShutdownException): pass + finally: + rclpy.shutdown() 2.1 Examine the code ~~~~~~~~~~~~~~~~~~~~