def main(args=None): rclpy.init(args=args) #Executor to control all topic nodes executor = MultiThreadedExecutor() nodeList = [] #std_msgs/String topics -- topics = ['rosout', 'actions', 'status'] rosout_node = RosoutListener() executor.add_node(rosout_node) logger.info(f'creating node for rosout messages') nodeList.append(rosout_node) for topic in topics: #Node creation for all topics subscriber = TopicNode(topic) executor.add_node(subscriber) nodeList.append(subscriber) print(f'creating node for string topic /{topic} messages') try: executor.spin() finally: executor.shutdown() for subscriber in nodeList: subscriber.destroy_node() rclpy.shutdown()
def main(args=None): time.sleep(1) # to measure the load on instantiation rclpy.init(args=args) try: nodes = {} for i in range(int(os.environ["ROS2_TEST_NUM_PER_GROUP"])): nodes[f'pub{i:03d}'] = NodePublish(cli_args=[ "--ros-args", "-r", f"__node:=node_publish_{i:03d}", ]) nodes[f'sub{i:03d}'] = NodeSubscribe(cli_args=[ "--ros-args", "-r", f"__node:=node_subscribe_{i:03d}", ]) executor = MultiThreadedExecutor() [executor.add_node(node) for node in nodes.values()] try: executor.spin() finally: executor.shutdown() [node.destroy_node() for node in nodes.values()] finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) pipeline_manager = PipelineManager() executor = MultiThreadedExecutor() executor.add_node(pipeline_manager) executor.spin() pipeline_manager.destroy_node() executor.shutdown() rclpy.shutdown()
def _main(): rclpy.init() executor = MultiThreadedExecutor() component_manager = ComponentManager(executor, "PyComponentManager") executor.add_node(component_manager) executor.spin() rclpy.shutdown()
def main(args=None): """Run the test script.""" rclpy.init(args=args) executor = MultiThreadedExecutor() node = ROSTestRunnerNode(executor) executor.add_node(node) executor.spin() node.destroy_node() rclpy.shutdown()
def main(args=None): rclpy.init(args=args) leg_names = ['front_left', 'middle_left', 'rear_left', 'rear_right', 'middle_right', 'front_right'] executor = MultiThreadedExecutor(num_threads=7) # EachLegGaitノード6スレッド+RoughWalkノード1スレッド+1スレッド for leg_name in leg_names: executor.add_node(EachLegGait(namespace='hapthexa/leg/'+leg_name)) executor.add_node(RoughWalk()) executor.spin() rclpy.shutdown()
def main(args=None): global executor rclpy.init(args=args) try: executor = MultiThreadedExecutor() manager_node = TaskSchedulerManager() executor.add_node(manager_node) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) trajectory_planner = TrajectoryPlanner() executor = MultiThreadedExecutor( num_threads=2 ) # when simulating we need two threads for the time to be updates i.e. when using "self.get_clock().now()" executor.add_node(trajectory_planner) executor.spin() # Destroy the node explicitly trajectory_planner.destroy_node() rclpy.shutdown()
def main(): from rclpy.executors import MultiThreadedExecutor rclpy.init() node = BlockingWaitsForTransform() # this node blocks in a callback, so a MultiThreadedExecutor is required executor = MultiThreadedExecutor() executor.add_node(node) try: executor.spin() except KeyboardInterrupt: pass executor.shutdown() rclpy.shutdown()
def main(args=None): rclpy.init(args=args) executor = MultiThreadedExecutor(num_threads=8) local_navigation = LocalNavigation() executor.add_node(local_navigation) executor.spin() executor.shutdown() # release resources (don't forget this) oalQuit()
def main(args=None): global executor rclpy.init(args=args) try: executor = MultiThreadedExecutor() executor.add_node(SubtaskRoomLightOn()) executor.add_node(SubtaskRoomLightOff()) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()
def main(args=None): # Pythonクライアントライブラリの初期化 rclpy.init(args=args) executor = MultiThreadedExecutor() rcv = Reciever() executor.add_node(rcv) try: executor.spin() except KeyboardInterrupt: pass executor.shutdown() rcv.destroy_node()
def main(args=None): rclpy.init(args=args) try: executor = MultiThreadedExecutor() node_a = FakeLifecycleNode('A') node_b = FakeLifecycleNode('B') executor.add_node(node_a) executor.add_node(node_b) lc = LifecycleClient() try: lc.configure_system() executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) sleep(2) lc.activate_system() executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) sleep(2) # give the system some time to converge lc.change_A_mode('AA') executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) sleep(3) # give the system some time to converge lc.change_A_mode( 'AA' ) # this is the tested aspect: call redundant, should be ignored executor.spin_once(timeout_sec=1) executor.spin_once(timeout_sec=1) sleep(2) # give the system some time to converge lc.change_A_mode('BB') executor.spin() finally: executor.shutdown() node_a.destroy_node() node_b.destroy_node() finally: rclpy.shutdown() return 0
def main(args=None): rclpy.init(args=args) node_A = MyNodePublisher("node_pub_A", 0.5) node_B = MyNodePublisher("node_pub_B", 1) executor = MultiThreadedExecutor(2) executor.add_node(node_A) executor.add_node(node_B) executor.spin() node_A.destroy_node() node_B.destroy_node() rclpy.shutdown()
def main(args=None): rclpy.init(args=args) try: calculator = Calculator() executor = MultiThreadedExecutor(num_threads=4) executor.add_node(calculator) try: executor.spin() except KeyboardInterrupt: calculator.get_logger().info('Keyboard Interrupt (SIGINT)') finally: executor.shutdown() calculator.arithmetic_action_server.destroy() calculator.destroy_node() finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) node_A = MyNodeSubscriber("node_sub_A") node_B = MyNodeSubscriber("node_pub_B") executor = MultiThreadedExecutor(2) executor.add_node(node_A) executor.add_node(node_B) executor.spin() node_A.destroy_node() node_B.destroy_node() rclpy.shutdown()
def main(args=None): global executor rclpy.init(args=args) try: executor = MultiThreadedExecutor() task_scheduler_manager = TaskSchedulerManager() executor.add_node(task_scheduler_manager) try: executor.spin() finally: executor.shutdown() task_scheduler_manager.destroy_node() finally: rclpy.shutdown()
def main(args=None): """ Executes the pipeline manager node Uses a multi threaded executor for the pipeline manager and continuously spins until stopped, then destroys the pipeline manager and shuts down the infastructure """ rclpy.init(args=args) pipeline_manager = PipelineManager() executor = MultiThreadedExecutor() executor.add_node(pipeline_manager) try: executor.spin() except KeyboardInterrupt: pass # To force exit code 0 executor.shutdown() rclpy.shutdown()
def main(args=None): rclpy.init(args=None) # needed to init rclcpp ros for moveit_bindings node = Node("bitbots_localization_handler", automatically_declare_parameters_from_overrides=True) dsd = init(node) node.create_timer(1 / 25.0, dsd.update) multi_executor = MultiThreadedExecutor() multi_executor.add_node(node) try: multi_executor.spin() except KeyboardInterrupt: pass node.destroy_node()
def main(): rclpy.init() hello_sub = HelloSub() try: executor = MultiThreadedExecutor(num_threads=2) executor.add_node(hello_sub) executor.spin() print('Added thread!') # original_spin(hello_sub) # does not work! # 2 lines below are for testing out multithreaded workload in ROS2 [Failed attempt] # for spinning nodes in the background # spin_thread1 = Thread(target=rclpy.spin, args=(hello_sub, )) # spin_thread1.start() except KeyboardInterrupt: pass executor.shutdown() hello_sub.destroy_node() rclpy.shutdown()
def main(args=None): '''start interaction with shell''' #TODO init parameter # print(args) shell = Shell() Process(target=write_string, args=(shell, )).start() rclpy.init(args=args) shell_read = ReadShell(shell) shell_write = WriteShell(shell) executor = MultiThreadedExecutor() executor.add_node(shell_read) executor.add_node(shell_write) executor.spin() executor.shutdown() shell_read.destroy_node() shell_write.destroy_node()
def main(): args = parse_args() rclpy.init() exe = MultiThreadedExecutor() node = HelloAvlActionServerNode(args.name, args.delay) if args.make_available_when is not None: node.make_available_when(args.make_available_when) node.get_logger().info("Node started") exe.add_node(node) exe.spin() node.abort() node.get_logger().info("Node finished")
def main(args=None): rclpy.init(args=args) try: # MultiThreadedExecutor executes callbacks with a thread pool. If num_threads is not # specified then num_threads will be multiprocessing.cpu_count() if it is implemented. # Otherwise it will use a single thread. This executor will allow callbacks to happen in # parallel, however the MutuallyExclusiveCallbackGroup in DoubleTalker will only allow its # callbacks to be executed one at a time. The callbacks in Listener are free to execute in # parallel to the ones in DoubleTalker however. executor = MultiThreadedExecutor(num_threads=4) executor.add_node(DoubleTalker()) executor.add_node(Listener()) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) try: # MultiThreadedExecutor executes callbacks with a thread pool. If num_threads is not # specified then num_threads will be multiprocessing.cpu_count() if it is implemented. # Otherwise it will use a single thread. This executor will allow callbacks to happen in # parallel, however the MutuallyExclusiveCallbackGroup in DoubleTalker will only allow its # callbacks to be executed one at a time. The callbacks in Listener are free to execute in # parallel to the ones in DoubleTalker however. executor = MultiThreadedExecutor(num_threads=4) executor.add_node(DoubleTalker()) executor.add_node(Listener()) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) # Referenced from robotpilot/ros2-seminar-examples # https://github.com/robotpilot/ros2-seminar-examples/blob/main/topic_service_action_rclpy_example/topic_service_action_rclpy_example/calculator/main.py try: maze_action_server = MazeActionServer() executor = MultiThreadedExecutor() executor.add_node(maze_action_server) try: executor.spin() except KeyboardInterrupt: maze_action_server.get_logger().info('Keyboard Interrupt (SIGINT)') finally: executor.shutdown() maze_action_server._action_server.destroy() maze_action_server.destroy_node() finally: rclpy.shutdown()
def main(args=None): rclpy.init(args=args) loop = asyncio.new_event_loop() try: minimal_service = MinimalService(loop) wait_node = WaitNode() executor = MultiThreadedExecutor() # executor = CustomThreadedExecutor(loop) executor.add_node(minimal_service) executor.add_node(wait_node) try: executor.spin() finally: executor.shutdown() minimal_service.destroy_node() wait_node.destroy_node() finally: rclpy.shutdown()
def main_multi(args=None): # Pythonクライアントライブラリの初期化 rclpy.init(args=args) # minimal_publisherノードの作成 minimal_publisher = MinimalPublisher() minimal_subscriber = MinimalSubscriber() executor = MultiThreadedExecutor() executor.add_node(minimal_publisher) executor.add_node(minimal_subscriber) try: executor.spin() except KeyboardInterrupt: pass executor.shutdown() minimal_publisher.destroy_node() minimal_subscriber.destroy_node() # Pythonクライアントライブラリの終了 rclpy.shutdown()
def thread_ros(self): print("Starting thread of ros threads") # executor = MultiThreadedExecutor(num_threads=4) # executor.add_node(self.node) # executor.spin() # When we will be solid: try: executor = MultiThreadedExecutor(num_threads=4) executor.add_node(self.node) try: executor.spin() except KeyboardInterrupt: act_on_simulation(ascii(STOP)) print('server stopped cleanly') finally: act_on_simulation(ascii(STOP)) executor.shutdown() self.node.destroy_node() finally: print("nothing")
def main(args=None): rclpy.init(args=args) try: manager_node = OdriveMotorManager() controller_node = OdriveMotorController(manager_node) executor = MultiThreadedExecutor() executor.add_node(manager_node) executor.add_node(controller_node) try: executor.spin() finally: executor.shutdown() manager_node.destroy_node() controller_node.destroy_node() finally: manager_node.reboot_odrive() rclpy.shutdown()
def main(args=None): global executor rclpy.init(args=args) try: executor = MultiThreadedExecutor() executor.add_node(SubtaskMove()) executor.add_node(SubtaskGrasp()) executor.add_node(SubtaskRelease()) executor.add_node(SubtaskOpen()) executor.add_node(SubtaskClose()) executor.add_node(SubtaskSensing()) executor.add_node(SubtaskRandomMove()) executor.add_node(SubtaskWait()) executor.add_node(SubtaskSpeakerAnnounce()) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()
def main(args=None): global executor rclpy.init(args=args) try: executor = MultiThreadedExecutor() executor.add_node(SubtaskBedLinkUp()) executor.add_node(SubtaskBedLinkDown()) executor.add_node(SubtaskBedHeadUp()) executor.add_node(SubtaskBedHeadDown()) executor.add_node(SubtaskBedFootUp()) executor.add_node(SubtaskBedFootDown()) executor.add_node(SubtaskBedHeightUp()) executor.add_node(SubtaskBedHeightDown()) try: executor.spin() finally: executor.shutdown() finally: rclpy.shutdown()