async def main() -> None: async with aioros.init_node("test_publisher"): async with aioros.create_publication("/chatter", String) as publisher: counter = count() while aioros.is_running(): msg = String(f"Message {next(counter)}") await publisher.publish(msg) await anyio.sleep(0.00001)
async def main() -> None: async with aioros.init_node("test_action_client"): async with aioros.create_action_client("fibonacci", FibonacciAction) as client: await client.wait_for_server() call = await client.send_goal(FibonacciGoal(order=5)) async for feedback in call.feedback(): print("Feedback", feedback) print("Result", await call.wait_for_result())
async def pub() -> None: async with aioros.init_node("test_publisher", configure_logging=False): async with aioros.create_publication("/foo", String, latched=True) as publisher: counter = count() while aioros.is_running(): msg = String(f"Message {next(counter)}") logger.info("Publish %s", msg) await publisher.publish(msg) await anyio.sleep(1.0)
async def create_master_node(): async with init_master() as master: async with init_node( "test_node", master_uri=master.xmlrpc_uri, register_signal_handler=False, configure_logging=False, ) as node: yield MasterNode(master, node)
async def test_service() -> None: async with init_master() as master: async with init_node( "some_server", master_uri=master.xmlrpc_uri, register_signal_handler=False, configure_logging=False, ) as server: async with anyio.create_task_group() as task_group: task_group.start_soon( server.create_server("/set_bool", SetBool, service_cb).serve) async with init_node( "test_client", master_uri=master.xmlrpc_uri, register_signal_handler=False, configure_logging=False, ) as node: await wait_until_registered(master.xmlrpc_uri) assert (master.registry.services["/set_bool"].api == server.tcpros_uri) async with node.create_client("/set_bool", SetBool) as client: for _ in range(10): result = await client.call(SetBoolRequest(True)) print(result) assert result.success is True assert result.message == "True" async with node.create_client("/set_bool", SetBool, persistent=True) as client: for _ in range(10): result = await client.call(SetBoolRequest(True)) print(result) assert result.success is True assert result.message == "True" task_group.cancel_scope.cancel() assert "/set_bool" not in master.registry.services assert not master.registry.nodes assert not master.registry.services
async def test_pubsub() -> None: async with init_master() as master: async with init_node( "test_publisher", master_uri=master.xmlrpc_uri, register_signal_handler=False, configure_logging=False, ) as publisher_node, init_node( "test_subscriber", master_uri=master.xmlrpc_uri, register_signal_handler=False, configure_logging=False, ) as subscriber_node: async with publisher_node.create_publication( "/topic", String, latched=True ) as publisher, subscriber_node.create_subscription( "/topic", String) as subscription: pub_reg = next(iter(master.registry.publications["/topic"])) sub_reg = next(iter(master.registry.subscriptions["/topic"])) assert pub_reg.caller_id == publisher_node.full_name assert sub_reg.caller_id == subscriber_node.full_name assert pub_reg.api == publisher_node.xmlrpc_uri assert sub_reg.api == subscriber_node.xmlrpc_uri await publisher.publish(String("Test")) async for msg in subscription: print(msg) assert msg.data == "Test" break for i in range(10): await publisher.publish(String(f"Test {i}")) i = 0 async for msg in subscription: print(msg) assert msg.data == f"Test {i}" i += 1 if i == 10: break assert not master.registry.publications assert not master.registry.subscriptions assert not master.registry.nodes assert not master.registry.topic_types
async def main() -> None: async with aioros.init_node("set_bool_client"): async with aioros.create_client( "/set_bool", SetBool, persistent=True ) as client: request = SetBoolRequest(True) while True: result = await client.call(request) request.data = not request.data logger.info("Result: %s", result) await anyio.sleep(1)
async def main() -> None: async with aioros.init_node("clock", initialize_time=False): await aioros.set_param("/use_sim_time", True) async with aioros.create_publication("/clock", Clock) as publisher: clock = Clock() ts = anyio.current_time() while aioros.is_running(): for _ in range(10): print(clock) await publisher.publish(clock) clock.clock.nsecs += 100000000 ts += 0.1 await anyio.sleep_until(ts) clock.clock.secs += 1 clock.clock.nsecs = 0
async def main(): async with aioros.init_node("some_node") as node: async with anyio.create_task_group() as tg: try: print(await node.get_param("foo")) except KeyError: print("no such param") print(await node.has_param("foo")) await node.set_param("bar", 123) print(await node.get_param("bar")) await node.delete_param("bar") print(await node.get_param_names()) tg.start_soon( node.create_server("/foo", SetBool, service_cb).serve) tg.start_soon(publish, node) # tg.start_soon(subscribe, node) # async with node.create_client("/set_bool", SetBool) as client: # result = await client.call(SetBoolRequest(data=True)) # print(result.success) # print(result) print(aioros.get_time()) await anyio.sleep(1000)
async def main() -> None: async with aioros.init_node("test_subscriber"): async with aioros.create_subscription("/chatter", String) as subscription: async for msg in subscription: logger.info("Received %s", msg)
async def main() -> None: async with aioros.init_node("test_param_subscriber"): print(await aioros.get_param_cached("/foo")) await anyio.sleep_forever()
async def sub() -> None: async with aioros.init_node("test_subscriber", configure_logging=False): async with aioros.create_subscription("/foo", String) as subscription: async for msg in subscription: logger.info("Received %s", msg)
async def main() -> None: async with aioros.init_node("some_server"): await aioros.create_server("/set_bool", SetBool, service_cb).serve()
async def main() -> None: async with aioros.init_node("test_subscriber"): async with aioros.create_subscription("/foo", AutoMessage) as subscription: async for msg in subscription: logger.info("Received %s", msg)