Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for service with variable timeout #1090

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions gazebo_ros/scripts/spawn_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def __init__(self, args):
help='unpause physics after spawning entity')
parser.add_argument('-wait', type=str, metavar='ENTITY_NAME',
help='Wait for entity to exist')
parser.add_argument('-spawn_service_timeout', type=float, metavar='TIMEOUT',
default=5.0, help='Spawn service wait timeout')
Karsten1987 marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('-x', type=float, default=0,
help='x component of initial position, meters')
parser.add_argument('-y', type=float, default=0,
Expand Down Expand Up @@ -215,7 +217,7 @@ def entity_xml_cb(msg):
initial_pose.orientation.y = q[2]
initial_pose.orientation.z = q[3]

success = self._spawn_entity(entity_xml, initial_pose)
success = self._spawn_entity(entity_xml, initial_pose, self.args.spawn_service_timeout)
if not success:
self.get_logger().error('Spawn service failed. Exiting.')
return 1
Expand Down Expand Up @@ -254,10 +256,16 @@ def entity_xml_cb(msg):

return 0

def _spawn_entity(self, entity_xml, initial_pose):
def _spawn_entity(self, entity_xml, initial_pose, timeout=5.0):
if timeout < 0:
self.get_logger().error('spawn_entity timeout must be greater than zero')
return False
self.get_logger().info(
'Waiting for service %s/spawn_entity, timeout = %.f' % (
self.args.gazebo_namespace, timeout))
self.get_logger().info('Waiting for service %s/spawn_entity' % self.args.gazebo_namespace)
client = self.create_client(SpawnEntity, '%s/spawn_entity' % self.args.gazebo_namespace)
if client.wait_for_service(timeout_sec=5.0):
if client.wait_for_service(timeout_sec=timeout):
req = SpawnEntity.Request()
req.name = self.args.entity
req.xml = str(entity_xml, 'utf-8')
Expand Down