-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
36 lines (26 loc) · 973 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
from subprocess import check_output
# import rosgraph
# def is_roscore_running():
# return rosgraph.is_master_online()
def categories_file_to_class_names(categories_file_path):
with open(categories_file_path, 'r') as f:
class_names = [e.strip() for e in f.readlines()]
return class_names
def get_rpi_ip():
cmd = "hostname -I | awk '{print \"\"$1\"\"}'"
return check_output(cmd, shell=True).decode('utf-8').rstrip()
def get_rpi_vpn_ip():
cmd = "ifconfig tun0 | grep 'inet ' | awk '{print \"\"$2\"\"}'"
return check_output(cmd, shell=True).decode('utf-8').rstrip()
def ensure_loop_rate(rate, loop_time):
""" Waits a bit to ensure a loop rate
i.e ensure_loop_rate(rate=1/fps, loop_time=time.time() - start_time)
Parameters
----------
rate : float
Loop rate in Hertz.
loop_time : float
The time that the loop took until its end.
"""
time.sleep(max(0, rate - loop_time))