util.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2020 Mojin Robotics GmbH
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import sys
18 
19 import rospy
20 
21 
22 def countdown_sleep(duration, stepsize=1, text="{}"):
23  """
24  Print the numbers of a countdown on the terminal in-place, without using a new line for each number
25 
26  :param duration: How long to count down
27  :param stepsize: Time between steps
28  :param text: What text to display each tick. Must include a format string, eg. 'launch in {}...'
29  """
30  step, substep = divmod(duration, stepsize)
31  for i in range(int(step), 0, -stepsize):
32  if not rospy.is_shutdown():
33  sys.stdout.write("\r" + text.format(i))
34  sys.stdout.flush()
35  rospy.sleep(stepsize)
36  rospy.sleep(substep)
37 
38  if step > 0: sys.stdout.write('\n')
39  sys.stdout.flush()
40 
41 def round_tuple(tup, decimals):
42  """
43  Rounding operation broadcast over a tuple
44 
45  :param tup: tuple to be rounded
46  :param decimals: how many decimals to round to
47  :return: tuple of same dimension but with lower precision
48  """
49  return tuple([round(elem, decimals) for elem in tup])
def round_tuple(tup, decimals)
Definition: util.py:41
def countdown_sleep(duration, stepsize=1, text="{}")
Definition: util.py:22


scenario_test_tools
Author(s): Loy van Beek
autogenerated on Wed Apr 7 2021 03:03:18