本文整理汇总了Python中rclpy.node方法的典型用法代码示例。如果您正苦于以下问题:Python rclpy.node方法的具体用法?Python rclpy.node怎么用?Python rclpy.node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rclpy
的用法示例。
在下文中一共展示了rclpy.node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
node = EchoServer()
try:
rclpy.spin(node)
except KeyboardInterrupt:
print('server stopped cleanly')
except BaseException:
print('exception in server:', file=sys.stderr)
raise
finally:
# Destroy the node explicitly
# (optional - Done automatically when node is garbage collected)
node.destroy_node()
rclpy.shutdown()
示例2: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
parsed_args = parse_arguments(args=args)
rclpy.init(args=args)
node = RepeaterNode(message_type=parsed_args.message_type)
try:
rclpy.spin(node)
except KeyboardInterrupt:
print('repeater stopped cleanly')
except BaseException:
print('exception in repeater:', file=sys.stderr)
raise
finally:
node.destroy_node()
rclpy.shutdown()
示例3: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args):
if not args.csv:
truncate_length = args.truncate_length if not args.full_length else None
callback = subscriber_cb(truncate_length, args.no_arr, args.no_str)
else:
truncate_length = args.truncate_length if not args.full_length else None
callback = subscriber_cb_csv(truncate_length, args.no_arr, args.no_str)
qos_profile = qos_profile_from_short_keys(
args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability,
depth=args.qos_depth, history=args.qos_history)
with NodeStrategy(args) as node:
if args.message_type is None:
message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True)
else:
message_type = get_message(args.message_type)
if message_type is None:
raise RuntimeError('Could not determine the type for the passed topic')
subscriber(
node, args.topic_name, message_type, callback, qos_profile, args.lost_messages)
示例4: subscriber
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def subscriber(
node: Node,
topic_name: str,
message_type: MsgType,
callback: Callable[[MsgType], Any],
qos_profile: QoSProfile,
report_lost_messages: bool
) -> Optional[str]:
"""Initialize a node with a single subscription and spin."""
event_callbacks = None
if report_lost_messages:
event_callbacks = SubscriptionEventCallbacks(message_lost=message_lost_event_callback)
try:
node.create_subscription(
message_type, topic_name, callback, qos_profile, event_callbacks=event_callbacks)
except UnsupportedEventTypeError:
assert report_lost_messages
print(
f"The rmw implementation '{get_rmw_implementation_identifier()}'"
' does not support reporting lost messages'
)
rclpy.spin(node)
示例5: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args):
qos_profile = qos_profile_from_short_keys(
args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability,
depth=args.qos_depth, history=args.qos_history)
times = args.times
if args.once:
times = 1
with DirectNode(args, node_name=args.node_name) as node:
return publisher(
node.node,
args.message_type,
args.topic_name,
args.values,
1. / args.rate,
args.print,
times,
qos_profile,
args.keep_alive)
示例6: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
"""
Run a Talker node standalone.
This function is called directly when using an entrypoint. Entrypoints are configured in
setup.py. This along with the script installation in setup.cfg allows a talker node to be run
with the command `ros2 run examples_rclpy_executors talker`.
:param args: Arguments passed in from the command line.
"""
# Run standalone
rclpy.init(args=args)
try:
talker = Talker()
rclpy.spin(talker)
finally:
talker.destroy_node()
rclpy.shutdown()
示例7: spin_once
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def spin_once(self, timeout_sec=None):
"""
Execute a single callback, then return.
This is the only function which must be overridden by a custom executor. Its job is to
start executing one callback, then return. It uses the method `wait_for_ready_callbacks`
to get work to execute.
:param timeout_sec: Seconds to wait. Block forever if None. Don't wait if <= 0
:type timeout_sec: float or None
"""
# wait_for_ready_callbacks yields callbacks that are ready to be executed
try:
handler, group, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
except StopIteration:
pass
else:
if node in self.high_priority_nodes:
self.hp_executor.submit(handler)
else:
self.lp_executor.submit(handler)
示例8: test_waitable_with_client
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def test_waitable_with_client(self):
self.waitable = ClientWaitable(self.node)
self.node.add_waitable(self.waitable)
server = self.node.create_service(EmptySrv, 'test_client', lambda req, resp: resp)
while not _rclpy.rclpy_service_server_is_available(self.waitable.client):
time.sleep(0.1)
thr = self.start_spin_thread(self.waitable)
_rclpy.rclpy_send_request(self.waitable.client, EmptySrv.Request())
thr.join()
assert self.waitable.future.done()
assert isinstance(self.waitable.future.result()['client'], EmptySrv.Response)
self.node.destroy_service(server)
示例9: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
node = FibonacciActionServer()
try:
rclpy.spin(node)
except KeyboardInterrupt:
print('server stopped cleanly')
except BaseException:
print('exception in server:', file=sys.stderr)
raise
finally:
node.destroy_node()
rclpy.shutdown()
示例10: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
node = ListenerNode()
try:
rclpy.spin(node)
except KeyboardInterrupt:
print('listener stopped cleanly')
except BaseException:
print('exception in listener:', file=sys.stderr)
raise
finally:
node.destroy_node()
rclpy.shutdown()
示例11: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
node = ControllerNode()
try:
rclpy.spin(node)
except KeyboardInterrupt:
print('controller stopped cleanly')
except BaseException:
print('exception in controller:', file=sys.stderr)
raise
finally:
node.destroy_node()
rclpy.shutdown()
示例12: add_arguments
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def add_arguments(self, parser, cli_name):
arg = parser.add_argument(
'topic_name',
help="Name of the ROS topic to publish to (e.g. '/chatter')")
arg.completer = TopicNameCompleter(
include_hidden_topics_key='include_hidden_topics')
arg = parser.add_argument(
'message_type',
help="Type of the ROS message (e.g. 'std_msgs/String')")
arg.completer = TopicTypeCompleter(
topic_name_key='topic_name')
arg = parser.add_argument(
'values', nargs='?', default='{}',
help='Values to fill the message with in YAML format '
"(e.g. 'data: Hello World'), "
'otherwise the message will be published with default values')
arg.completer = TopicMessagePrototypeCompleter(
topic_type_key='message_type')
parser.add_argument(
'-r', '--rate', metavar='N', type=positive_float, default=1.0,
help='Publishing rate in Hz (default: 1)')
parser.add_argument(
'-p', '--print', metavar='N', type=int, default=1,
help='Only print every N-th published message (default: 1)')
group = parser.add_mutually_exclusive_group()
group.add_argument(
'-1', '--once', action='store_true',
help='Publish one message and exit')
group.add_argument(
'-t', '--times', type=nonnegative_int, default=0,
help='Publish this number of times and then exit')
parser.add_argument(
'--keep-alive', metavar='N', type=positive_float, default=0.1,
help='Keep publishing node alive for N seconds after the last msg '
'(default: 0.1)')
parser.add_argument(
'-n', '--node-name',
help='Name of the created publishing node')
add_qos_arguments_to_argument_parser(
parser, is_publisher=True, default_preset='system_default')
示例13: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_subscriber.destroy_node()
rclpy.shutdown()
示例14: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_publisher.destroy_node()
rclpy.shutdown()
示例15: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import node [as 别名]
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()