forked from hchengwang/Software-duckietown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b4580b
commit dec8c16
Showing
41 changed files
with
650 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ jobs: | |
git clone [email protected]:duckietown/duckiefleet-fall2017.git $DUCKIEFLEET_ROOT | ||
make test-download-logs | ||
make test-circle | ||
- run: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config echo 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/bag_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import subprocess | ||
|
||
import yaml | ||
|
||
from duckietown_utils import logger | ||
|
||
from .caching import get_cached | ||
from .instantiate_utils import indent | ||
|
||
|
||
__all__ = ['rosbag_info', 'rosbag_info_cached'] | ||
|
||
def rosbag_info_cached(filename): | ||
def f(): | ||
return rosbag_info(filename) | ||
basename = os.path.basename(filename) | ||
cache_name = 'rosbag_info/' + basename | ||
return get_cached(cache_name, f, quiet=True) | ||
|
||
|
||
|
||
def rosbag_info(bag): | ||
stdout = subprocess.Popen(['rosbag', 'info', '--yaml', bag], | ||
stdout=subprocess.PIPE).communicate()[0] | ||
try: | ||
info_dict = yaml.load(stdout) | ||
except: | ||
logger.error('Could not parse yaml:\n%s' % indent(stdout, '| ')) | ||
raise | ||
return info_dict |
35 changes: 35 additions & 0 deletions
35
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/bag_reading.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import time | ||
|
||
from duckietown_utils import logger | ||
from duckietown_utils.exceptions import DTBadData | ||
|
||
|
||
def d8n_bag_read_with_progress(log, topic): | ||
import rosbag # @UnresolvedImport | ||
bag = rosbag.Bag(log.filename) | ||
length = log.length | ||
n = 0 | ||
msg_time0 = None | ||
# write a message every once in a while | ||
INTERVAL = 1 | ||
first = last = time.time() | ||
for topic, msg, msg_time in bag.read_messages(topics=[topic]): | ||
# compute progess | ||
msg_time = msg_time.to_sec() | ||
if msg_time0 is None: | ||
msg_time0 = msg_time | ||
progress = float(msg_time-msg_time0) / length | ||
|
||
# current time | ||
n += 1 | ||
t = time.time() | ||
if t - last > INTERVAL: | ||
last = t | ||
fps = n / (t-first) | ||
logger.debug('%6d %4.1f%% %5.1f fps' % (n, progress * 100, fps)) | ||
yield msg | ||
if n == 0: | ||
s = 'Could not find any message for topic %r.' % topic | ||
raise DTBadData(s) | ||
bag.close() | ||
|
23 changes: 23 additions & 0 deletions
23
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/bag_writing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from contextlib import contextmanager | ||
import os | ||
import rosbag | ||
|
||
from duckietown_utils import logger | ||
from duckietown_utils.mkdirs import d8n_make_sure_dir_exists | ||
|
||
|
||
@contextmanager | ||
def d8n_write_to_bag_context(out_bag_filename): | ||
""" | ||
with d8n_write_to_bag_context(filename) as bag: | ||
bag.write(topic_name, msg) | ||
""" | ||
d8n_make_sure_dir_exists(out_bag_filename) | ||
out_bag = rosbag.Bag(out_bag_filename + '.tmp', 'w') | ||
yield out_bag | ||
out_bag.close() | ||
os.rename(out_bag_filename + '.tmp', out_bag_filename) | ||
logger.info('Written bag to %s' % out_bag_filename) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/exceptions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/image_conversions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from cv_bridge import CvBridge # @UnresolvedImport | ||
|
||
__all__ = ['d8n_image_msg_from_cv_image'] | ||
|
||
class ImageConversions(): | ||
|
||
bridge = None | ||
|
||
def d8n_image_msg_from_cv_image(cv_image, image_format, same_timestamp_as = None): | ||
""" | ||
Makes an Image message from a CV image. | ||
if same_timestamp_as is not None, we copy the timestamp | ||
from that image. | ||
image_format: 'bgr8' or 'mono' or similar | ||
""" | ||
if ImageConversions.bridge is None: | ||
ImageConversions.bridge = CvBridge() | ||
image_msg_out = ImageConversions.bridge.cv2_to_imgmsg(cv_image, image_format) | ||
if same_timestamp_as is not None: | ||
image_msg_out.header.stamp = same_timestamp_as.header.stamp | ||
return image_msg_out | ||
|
36 changes: 36 additions & 0 deletions
36
catkin_ws/src/00-infrastructure/duckietown/include/duckietown_utils/mkdirs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# copied from compmake | ||
|
||
import os | ||
|
||
__all__ = [ | ||
'make_sure_dir_exists', | ||
'mkdirs_thread_safe', | ||
] | ||
|
||
|
||
def d8n_make_sure_dir_exists(filename): | ||
""" | ||
Makes sure that the path to file exists, by creating directories. | ||
""" | ||
dirname = os.path.dirname(filename) | ||
# dir == '' for current dir | ||
if dirname != '' and not os.path.exists(dirname): | ||
mkdirs_thread_safe(dirname) | ||
|
||
|
||
def mkdirs_thread_safe(dst): | ||
""" Make directories leading to 'dst' if they don't exist yet""" | ||
if dst == '' or os.path.exists(dst): | ||
return | ||
head, _ = os.path.split(dst) | ||
if os.sep == ':' and not ':' in head: | ||
head += ':' | ||
mkdirs_thread_safe(head) | ||
try: | ||
mode = 511 # 0777 in octal | ||
os.mkdir(dst, mode) | ||
except OSError as err: | ||
if err.errno != 17: # file exists | ||
raise | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.