@@ -253,6 +253,7 @@ def create_topic_publisher_node(robot_name, robot_configs_path=None, topic_confi
253253 robot_configs_path = robot_configs_path if robot_configs_path else None
254254 topic_configs_path = topic_configs_path if topic_configs_path else None
255255
256+ pub = None
256257 try :
257258 # Create topic publisher node and publisher instance
258259 _ , pub = create_topic_publisher_node (this_robot , robot_configs_path , topic_configs_path , node )
@@ -263,6 +264,51 @@ def create_topic_publisher_node(robot_name, robot_configs_path=None, topic_confi
263264 pass
264265 finally :
265266 # Cleanup
266- pub .shutdown ()
267+ if pub is not None :
268+ pub .shutdown ()
267269 node .destroy_node ()
268270 rclpy .shutdown ()
271+
272+ def main ():
273+ rclpy .init (args = None )
274+ node = rclpy .create_node ("topic_publisher" )
275+ logger = node .get_logger ()
276+
277+ # Declare parameters
278+ node .declare_parameter ("robot_name" , "" )
279+ node .declare_parameter ("robot_configs" , "" )
280+ node .declare_parameter ("topic_configs" , "" )
281+
282+ # Get robot from the parameters
283+ this_robot = node .get_parameter ("robot_name" ).get_parameter_value ().string_value
284+ if not this_robot :
285+ logger .error ("robot_name parameter is required" )
286+ rclpy .shutdown ()
287+ sys .exit (1 )
288+
289+ # Get config file paths from parameters
290+ robot_configs_path = node .get_parameter ("robot_configs" ).get_parameter_value ().string_value
291+ topic_configs_path = node .get_parameter ("topic_configs" ).get_parameter_value ().string_value
292+
293+ # Use empty strings as None for the function
294+ robot_configs_path = robot_configs_path if robot_configs_path else None
295+ topic_configs_path = topic_configs_path if topic_configs_path else None
296+
297+ pub = None
298+ try :
299+ # Create topic publisher node and publisher instance
300+ _ , pub = create_topic_publisher_node (this_robot , robot_configs_path , topic_configs_path , node )
301+
302+ # Run the publisher
303+ pub .run ()
304+ except KeyboardInterrupt :
305+ pass
306+ finally :
307+ # Cleanup
308+ if pub is not None :
309+ pub .shutdown ()
310+ node .destroy_node ()
311+ rclpy .shutdown ()
312+
313+ if __name__ == "__main__" :
314+ main ()
0 commit comments