本文整理汇总了Python中rclpy.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python rclpy.shutdown方法的具体用法?Python rclpy.shutdown怎么用?Python rclpy.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rclpy
的用法示例。
在下文中一共展示了rclpy.shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [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: daemon_node
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def daemon_node():
if is_daemon_running(args=[]):
with DaemonNode(args=[]) as node:
node.system.shutdown()
assert spawn_daemon(args=[], wait_until_spawned=5.0)
with DaemonNode(args=[]) as node:
attempts = 3
delay_between_attempts = 2 # seconds
for _ in range(attempts):
node_names_and_namespaces = node.get_node_names_and_namespaces()
if [TEST_NODE_NAME, TEST_NODE_NAMESPACE] in node_names_and_namespaces:
break
time.sleep(delay_between_attempts)
else:
pytest.fail(
f'daemon failed to discover {TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}'
)
yield node
node.system.shutdown()
示例3: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [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()
示例4: _rostopic_bw
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def _rostopic_bw(node, topic, window_size=DEFAULT_WINDOW_SIZE):
"""Periodically print the received bandwidth of a topic to console until shutdown."""
# pause bw until topic is published
msg_class = get_msg_class(node, topic, blocking=True, include_hidden_topics=True)
if msg_class is None:
node.destroy_node()
return
rt = ROSTopicBandwidth(node, window_size)
node.create_subscription(
msg_class,
topic,
rt.callback,
qos_profile_sensor_data,
raw=True
)
print(f'Subscribed to [{topic}]')
timer = node.create_timer(1, rt.print_bw)
while rclpy.ok():
rclpy.spin_once(node)
node.destroy_timer(timer)
node.destroy_node()
rclpy.shutdown()
示例5: closeEvent
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def closeEvent(self, event=None):
try:
# Signal worker threads should stop
self.keepThreads = False
# Give time to threads to stop
time.sleep(0.1)
if os.path.exists(os.path.join(os.getcwd(),"tmp")):
shutil.rmtree(os.path.join(os.getcwd(),"tmp"))
# ROS2 cleanup
self.executor.shutdown()
self.node.destroy_node()
rclpy.shutdown(context=self.context)
sys.exit(0)
except:
raise
#########################################################
# UI interaction handlers #
#########################################################
示例6: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
rclpy.init(args=args)
node = rclpy.create_node('minimal_subscriber')
subscription = node.create_subscription(
String, 'topic', lambda msg: node.get_logger().info('I heard: "%s"' % msg.data), 10)
subscription # prevent unused variable warning
rclpy.spin(node)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
node.destroy_node()
rclpy.shutdown()
示例7: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
global g_node
rclpy.init(args=args)
g_node = rclpy.create_node('minimal_subscriber')
subscription = g_node.create_subscription(String, 'topic', chatter_callback, 10)
subscription # prevent unused variable warning
while rclpy.ok():
rclpy.spin_once(g_node)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
g_node.destroy_node()
rclpy.shutdown()
示例8: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
rclpy.init(args=args)
node = rclpy.create_node('minimal_publisher')
publisher = node.create_publisher(String, 'topic', 10)
msg = String()
i = 0
while rclpy.ok():
msg.data = 'Hello World: %d' % i
i += 1
node.get_logger().info('Publishing: "%s"' % msg.data)
publisher.publish(msg)
sleep(0.5) # seconds
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
node.destroy_node()
rclpy.shutdown()
示例9: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
rclpy.init(args=args)
minimal_client = MinimalClientAsync()
minimal_client.send_request()
while rclpy.ok():
rclpy.spin_once(minimal_client)
if minimal_client.future.done():
try:
response = minimal_client.future.result()
except Exception as e:
minimal_client.get_logger().info(
'Service call failed %r' % (e,))
else:
minimal_client.get_logger().info(
'Result of add_two_ints: for %d + %d = %d' %
(minimal_client.req.a, minimal_client.req.b, response.sum))
break
minimal_client.destroy_node()
rclpy.shutdown()
示例10: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
rclpy.init(args=args)
try:
talker = DoubleTalker()
listener = Listener()
# 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(talker)
executor.add_node(listener)
try:
executor.spin()
finally:
executor.shutdown()
listener.destroy_node()
talker.destroy_node()
finally:
rclpy.shutdown()
示例11: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
"""
Run a Listener 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 listener node to be run
with the command `ros2 run examples_rclpy_executors listener`.
:param args: Arguments passed in from the command line.
"""
rclpy.init(args=args)
try:
listener = Listener()
rclpy.spin(listener)
finally:
listener.destroy_node()
rclpy.shutdown()
示例12: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [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()
示例13: main
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def main(args=None):
rclpy.init(args=args)
try:
listener = Listener()
talker = Talker()
estopper = Estopper()
executor = PriorityExecutor()
executor.add_high_priority_node(estopper)
executor.add_node(listener)
executor.add_node(talker)
try:
executor.spin()
finally:
executor.shutdown()
estopper.destroy_node()
talker.destroy_node()
listener.destroy_node()
finally:
rclpy.shutdown()
示例14: test_create_raw_subscription
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def test_create_raw_subscription(self):
executor = SingleThreadedExecutor(context=self.context)
executor.add_node(self.node)
basic_types_pub = self.node.create_publisher(BasicTypes, 'raw_subscription_test', 1)
self.raw_subscription_msg = None # None=No result yet
self.node.create_subscription(
BasicTypes,
'raw_subscription_test',
self.raw_subscription_callback,
1,
raw=True
)
basic_types_msg = BasicTypes()
cycle_count = 0
while cycle_count < 5 and self.raw_subscription_msg is None:
basic_types_pub.publish(basic_types_msg)
cycle_count += 1
executor.spin_once(timeout_sec=1)
self.assertIsNotNone(self.raw_subscription_msg, 'raw subscribe timed out')
self.assertIs(type(self.raw_subscription_msg), bytes, 'raw subscribe did not return bytes')
# The length might be implementation dependant, but shouldn't be zero
# There may be a canonical serialization in the future at which point this can be updated
self.assertNotEqual(len(self.raw_subscription_msg), 0, 'raw subscribe invalid length')
executor.shutdown()
示例15: test_use_global_arguments
# 需要导入模块: import rclpy [as 别名]
# 或者: from rclpy import shutdown [as 别名]
def test_use_global_arguments(self):
context = rclpy.context.Context()
rclpy.init(
args=['process_name', '--ros-args', '-r', '__node:=global_node_name'],
context=context
)
try:
node1 = rclpy.create_node(
'my_node', namespace='/my_ns', use_global_arguments=True, context=context)
node2 = rclpy.create_node(
'my_node', namespace='/my_ns', use_global_arguments=False, context=context)
self.assertEqual('global_node_name', node1.get_name())
self.assertEqual('my_node', node2.get_name())
node1.destroy_node()
node2.destroy_node()
finally:
rclpy.shutdown(context=context)