can't call ros2 service after adding one more publisher to other node
Hi everybody My project consists of 3 nodes:
- account service
- publisher
- trade service
when publisher has just one publisher, everything works fine and I can call services but after adding one more publisher to publisher node, services from account service node becomes unavailable(but I can see those services from ros2 service list), in other words I can not call them what I am doing wrong? here is the code for starting server:
def main():
# ros2 initialize and create an executor for all nodes
rclpy.init(args=None)
executor = SingleThreadedExecutor()
# creating account, publishing and service nodes
publisher_node = Publisher(name='ig_broker_publisher')
print('created publisher node')
account_service_node = AccountService(name='account_service', publisher_node=publisher_node)
print('created accoutn service node')
trader_service_node = TradeService(name='trade_service', account_service=account_service_node)
print('created trade service node')
# account_service_node is the core and has accounts and database manager
# add nodes to executor
executor.add_node(account_service_node)
executor.add_node(publisher_node)
executor.add_node(trader_service_node)
# execute until finish
executor.spin()
and the client script which calls the services is like this:
class AccountClientAsync(Node):
def __init__(self, name: str):
super().__init__(name)
self.connect_client = self.create_client(RequestConnectAccount, 'connect_service')
self.change_client = self.create_client(RequestConnectAccount, 'change_service')
self.switch_client = self.create_client(RequestSwitchAccount, 'switch_service')
while not self.connect_client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('service connect not available, waiting again...')
while not self.change_client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('service change not available, waiting again...')
while not self.switch_client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('service switch not available, waiting again...')
and this
def main(args=None):
rclpy.init(args=args)
account_client = AccountClientAsync(name='account_connect_client')
print('inside main function of client before making request')
if sys.argv[1] in ['CONNECT', 'CHANGE']:
account_client.send_connect_or_change_request()
elif sys.argv[1] == 'SWITCH':
account_client.send_switch_request()
else:
print('invalid request')
print('inside main function of client after making request')
while rclpy.ok():
rclpy.spin_once(account_client)
if account_client.future.done():
try:
response = account_client.future.result()
except Exception as e:
account_client.get_logger().info(
'Service call failed %r' % (e,))
else:
account_client.get_logger().info(response.result)
break
account_client.destroy_node()
rclpy.shutdown()
my code is stuck on :
'service connect not available, waiting again...'