示例#1
0
def main():

    rclpy.init(args=None)

    node = rclpy.create_node('minimal_action_node')
    executor = MultiThreadedExecutor()
    exit_future = rclpy.Future()

    asw = ActionServerWrapperThread(node, exit_future)
    asw.start()

    time.sleep(
        0.5
    )  # without this instruction this error is thrown at the end of the program:
    # PyCapsule_GetPointer called with invalid PyCapsule object #3

    acw = ActionClientWrapperThread(node, exit_future)
    acw.start()

    while not exit_future.done():
        rclpy.spin_until_future_complete(node,
                                         exit_future,
                                         executor=executor,
                                         timeout_sec=1)

    acw.destroy()
    asw.destroy()

    executor.shutdown()
    node.destroy_node()
    rclpy.shutdown()
示例#2
0
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()
示例#3
0
 def test_multi_threaded_executor_executes(self):
     self.assertIsNotNone(self.node.handle)
     executor = MultiThreadedExecutor(context=self.context)
     try:
         self.assertTrue(self.func_execution(executor))
     finally:
         executor.shutdown()
示例#4
0
def main(args=None):
    logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
                        level=logging.INFO,
                        datefmt='%Y-%m-%d %H:%M:%S')

    rclpy.init(args=args)

    executor = MultiThreadedExecutor()
    odom_node = TransformLoggerNode('odom', 'base_link', executor=executor)
    map_node = TransformLoggerNode('map', 'base_link', executor=executor)
    executor.add_node(odom_node)
    executor.add_node(map_node)
    try:
        #rclpy.spin(log_node)
        while True:
            executor.spin_once()
            #logging.info(f"num nodes is: {len(executor.get_nodes())}")
            if len(executor.get_nodes()) == 0:
                break
            if odom_node.is_done() and map_node.is_done():
                break

    except:
        logging.warning(f"hit exception")
        pass
        #executor.shutdown()
    finally:
        logging.warning(f"cleaning up")
        odom_node.plot_data()
        map_node.plot_data()
        plt.pause(1)
        plt.show(block=True)
        odom_node.destroy_node()
        map_node.destroy_node()
示例#5
0
def start_a_message_equality_tester_node_and_get_result(future_result : Future, exe : MultiThreadedExecutor, expected_data : Dict):

    node = MessageEqualityTesterNode('topic', 'std_msgs/msg/String', expected_data, future_result)
    
    exe.add_node(node)

    exe.spin_until_future_complete(future_result)

    node.destroy_node()

    return future_result.result()
 def __init__(self, exit_future):
     multiprocessing.Process.__init__(self)
     self._node = rclpy.create_node('minimal_action_server')
     self._executor = MultiThreadedExecutor()
     self._exit_future = exit_future
     
     self._action_server = ActionServer(
         self._node,
         Fibonacci,
         'fibonacci',
         execute_callback=self.execute_callback,
         callback_group=ReentrantCallbackGroup(),
         goal_callback=self.goal_callback,
         cancel_callback=self.cancel_callback)
示例#7
0
 def __init__(self, nodes: list = []):
     self.nodes = nodes
     # self.executor = SingleThreadedExecutor() # commented out to test out MultiThreadedExecutor and see how it works
     self.executor = MultiThreadedExecutor(
         num_threads=2)  # if num_threads is 1, it executes as single thread
     if len(nodes) is 0:
         self.executor.shutdown()
         rclpy.shutdown()
         raise ValueError('Not any node was given!')
     elif len(nodes) > 1:
         for node in nodes:
             self.executor.add_node(node)
     else:
         self.executor.add_node(node)
示例#8
0
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()
示例#9
0
def main(args=None):
    global logger
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_action_server')
    logger = node.get_logger()

    # Use a ReentrantCallbackGroup to enable processing multiple goals concurrently
    # Default goal callback accepts all goals
    # Default cancel callback rejects cancel requests
    action_server = ActionServer(node,
                                 Fibonacci,
                                 'fibonacci',
                                 execute_callback=execute_callback,
                                 cancel_callback=cancel_callback,
                                 callback_group=ReentrantCallbackGroup())

    # Use a MultiThreadedExecutor to enable processing goals concurrently
    executor = MultiThreadedExecutor()

    rclpy.spin(node, executor=executor)

    action_server.destroy()
    node.destroy_node()
    rclpy.shutdown()
示例#10
0
def main(args=None):
    rclpy.init(args=args)
    server = Supervisor()
    # Use a MultiThreadedExecutor to enable processing goals concurrently
    executor = MultiThreadedExecutor()
    rclpy.spin(server, executor=executor)
    rclpy.shutdown()
示例#11
0
def main(args=None):
    rclpy.init(args=args)
    minimal_action_server = MinimalActionServer()
    executor = MultiThreadedExecutor()
    rclpy.spin(minimal_action_server, executor=executor)
    minimal_action_server.destroy()
    rclpy.shutdown()
示例#12
0
    def test_multi_goal_accept(self):
        executor = MultiThreadedExecutor(context=self.context)
        action_server = ActionServer(
            self.node,
            Fibonacci,
            'fibonacci',
            execute_callback=self.execute_goal_callback,
            callback_group=ReentrantCallbackGroup(),
            handle_accepted_callback=lambda gh: None,
        )

        goal_msg = Fibonacci.Impl.SendGoalService.Request()
        goal_msg.goal_id = UUID(uuid=list(uuid.uuid4().bytes))
        future0 = self.mock_action_client.send_goal(goal_msg)
        goal_msg.goal_id = UUID(uuid=list(uuid.uuid4().bytes))
        future1 = self.mock_action_client.send_goal(goal_msg)
        goal_msg.goal_id = UUID(uuid=list(uuid.uuid4().bytes))
        future2 = self.mock_action_client.send_goal(goal_msg)

        rclpy.spin_until_future_complete(self.node, future0, executor)
        rclpy.spin_until_future_complete(self.node, future1, executor)
        rclpy.spin_until_future_complete(self.node, future2, executor)

        self.assertTrue(future0.result().accepted)
        self.assertTrue(future1.result().accepted)
        self.assertTrue(future2.result().accepted)
        action_server.destroy()
示例#13
0
    def setUpClass(cls):
        cls.context = rclpy.context.Context()
        rclpy.init(context=cls.context)
        cls.node = rclpy.create_node(TEST_NODE,
                                     namespace=TEST_NAMESPACE,
                                     context=cls.context)

        cls.executor = MultiThreadedExecutor(context=cls.context,
                                             num_threads=2)
        cls.executor.add_node(cls.node)

        cls.node.declare_parameter('bool_param', True)
        cls.node.declare_parameter('int_param', 42)
        cls.node.declare_parameter('double_param', 1.23)
        cls.node.declare_parameter('str_param', 'Hello World')
        cls.node.declare_parameter(
            'foo' + PARAMETER_SEPARATOR_STRING + 'str_param', 'foo')
        cls.node.declare_parameter(
            'foo' + PARAMETER_SEPARATOR_STRING + 'bar' +
            PARAMETER_SEPARATOR_STRING + 'str_param', 'foobar')

        # We need both the test node and 'dump'
        # node to be able to spin
        cls.exec_thread = threading.Thread(target=cls.executor.spin)
        cls.exec_thread.start()
def main(args=None):
    rclpy.init(args=args)
    qos = QoSProfile(reliability=QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
                     depth=1,
                     history=QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST)

    try:
        deepracer_offroad_navigation_node = DeepracerOffroadNavigationNode(qos)
        executor = MultiThreadedExecutor()

        def signal_handler(signum, frame):
            """Callback function to handle registered signal handler
               to join and stop executing running thread created.
            Args:
                signum: The signal number.
                frame: the current stack frame (None or a frame object).
            """
            deepracer_offroad_navigation_node.get_logger().info("Signal Handler initiated")
            deepracer_offroad_navigation_node.thread_shutdown()
            deepracer_offroad_navigation_node.wait_for_thread()

        # Register SIGINT handler
        signal.signal(signal.SIGINT, signal_handler)
        rclpy.spin(deepracer_offroad_navigation_node, executor)
    except Exception as ex:
        deepracer_offroad_navigation_node.get_logger().error(f"Exception in Deepracer Offroad Navigation Node: {ex}")
        deepracer_offroad_navigation_node.destroy_node()
        rclpy.shutdown()

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    deepracer_offroad_navigation_node.destroy_node()
    rclpy.shutdown()
示例#15
0
def start_multi_equality_tester(future : Future, exe : MultiThreadedExecutor):

    topic_and_expected_values_pairs = [
        TopicAndValuesPair('topic1', 'std_msgs/msg/String', {'data' : 'hello1'}),
        TopicAndValuesPair('topic2', 'std_msgs/msg/String', {'data' : 'hello2'}),
        TopicAndValuesPair('topic3', 'std_msgs/msg/String', {'data' : 'hello3'}),
    ]

    node = MultiMessageEqualityTesterNode(topic_and_expected_values_pairs, EqualityType.ALLOF, future)

    exe.add_node(node)

    exe.spin_until_future_complete(future)

    node.destroy_node()
    return future.result()
示例#16
0
def main(args=None) -> None:
    """!
    Main Functions of Local Console Node
    """
    # Initialize ROS communications for a given context.
    setProcessName("planner-node")
    rclpy.init(args=args)

    # Execute work and block until the context associated with the
    # executor is shutdown.
    planner_node = PlannerNode()

    # Runs callbacks in a pool of threads.
    executor = MultiThreadedExecutor()

    # Execute work and block until the context associated with the
    # executor is shutdown. Callbacks will be executed by the provided
    # executor.
    rclpy.spin(planner_node, executor)

    # Clear thread
    planner_node.clear()

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    planner_node.destroy_node()
    rclpy.shutdown()
示例#17
0
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()
示例#18
0
def main(args=None):
    rclpy.init(args=args)

    paella_action_server = PaellaActionServer()
    executor = MultiThreadedExecutor()
    rclpy.spin(paella_action_server, executor=executor)
    paella_action_server.destroy()
    rclpy.shutdown()
示例#19
0
def main(args=None):
    """Run a ROSPIT test session."""
    rclpy.init(args=args)
    executor = MultiThreadedExecutor()
    node = ROSTestRunnerNode(executor)
    action_client = ActionClient(node, ExecuteXMLTestSuite,
                                 '/execute_xml_test_suite')
    node.declare_parameter('path')
    executor.add_node(node)
    t1 = ExecuteCall(node, action_client)
    t2 = ExecuteSpin(node, executor)
    t1.start()
    t2.start()
    t1.join()
    t2.spinning = False
    t2.join()
    rclpy.shutdown()
示例#20
0
    def test_cancel_goal_accept(self):
        def execute_callback(goal_handle):
            # Wait, to give the opportunity to cancel
            time.sleep(3.0)
            self.assertTrue(goal_handle.is_cancel_requested)
            goal_handle.canceled()
            return Fibonacci.Result()

        def cancel_callback(request):
            return CancelResponse.ACCEPT

        executor = MultiThreadedExecutor(context=self.context)
        action_server = ActionServer(
            self.node,
            Fibonacci,
            'fibonacci',
            callback_group=ReentrantCallbackGroup(),
            execute_callback=execute_callback,
            handle_accepted_callback=lambda gh: None,
            cancel_callback=cancel_callback,
        )

        goal_uuid = UUID(uuid=list(uuid.uuid4().bytes))
        goal_order = 10
        goal_msg = Fibonacci.Impl.SendGoalService.Request()
        goal_msg.goal_id = goal_uuid
        goal_msg.goal.order = goal_order
        goal_future = self.mock_action_client.send_goal(goal_msg)
        rclpy.spin_until_future_complete(self.node, goal_future, executor)
        goal_handle = goal_future.result()
        self.assertTrue(goal_handle.accepted)

        cancel_srv = CancelGoal.Request()
        cancel_srv.goal_info.goal_id = goal_uuid
        cancel_srv.goal_info.stamp.sec = 0
        cancel_srv.goal_info.stamp.nanosec = 0
        cancel_future = self.mock_action_client.cancel_goal(cancel_srv)
        rclpy.spin_until_future_complete(self.node, cancel_future, executor)
        cancel_result = cancel_future.result()
        self.assertEqual(len(cancel_result.goals_canceling), 1)
        assert all(
            cancel_result.goals_canceling[0].goal_id.uuid == goal_uuid.uuid)

        action_server.destroy()
        executor.shutdown()
示例#21
0
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()
示例#22
0
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()
示例#23
0
def main(args=None):
    rclpy.init(args=args)

    action_server = RandomCrawlActionServer()
    executor = MultiThreadedExecutor()
    rclpy.spin(action_server, executor=executor)

    action_server.destroy()
    rclpy.shutdown()
示例#24
0
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)
    action_client = NavigationActionClient()
    action_client.get_logger().info('********************************')

    executor = MultiThreadedExecutor()
    rclpy.spin(action_client, executor)

    action_client.get_logger().info('=================================')
示例#26
0
def main(args=None):
    rclpy.init(args=args)
    software_update_node = SoftwareUpdateNode()
    executor = MultiThreadedExecutor()
    rclpy.spin(software_update_node, executor)
    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    software_update_node.destroy_node()
    rclpy.shutdown()
示例#27
0
def main(args=None):
    rclpy.init()
    node = SampleActionServer()

    executor = MultiThreadedExecutor()
    # executor = SingleThreadedExecutor()
    rclpy.spin(node, executor=executor)
    
    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()
示例#29
0
def main(args=None):
    rclpy.init(args=args)
    with USBMonitorNode() as usb_monitor_node:
        executor = MultiThreadedExecutor()
        rclpy.spin(usb_monitor_node, executor)
        # Destroy the node explicitly
        # (optional - otherwise it will be done automatically
        # when the garbage collector destroys the node object)
    usb_monitor_node.destroy_node()
    rclpy.shutdown()
def main(args=None):
    rclpy.init(args=args)
    model_loader_node = ModelLoaderNode()
    executor = MultiThreadedExecutor()
    rclpy.spin(model_loader_node, executor)
    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    model_loader_node.destroy_node()
    rclpy.shutdown()
示例#31
0
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()