Created
January 19, 2017 00:35
-
-
Save Zackory/567615196db11ce792941484fdcefb1a to your computer and use it in GitHub Desktop.
A python implementation of bee-map.c for lab 1 in CS8803: STR.
This file contains hidden or 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
| from __future__ import print_function | |
| import os, sys | |
| import numpy as np | |
| # Author: Zackory Erickson | |
| class Map: | |
| mapsize_x = 0 | |
| mapsize_y = 0 | |
| resolution = 0 | |
| offset_x = 0 | |
| offset_y = 0 | |
| prob = None | |
| min_x = float('inf') | |
| max_x = 0 | |
| min_y = float('inf') | |
| max_y = 0 | |
| def read_beesoft_map(mapName): | |
| if not os.path.isfile(mapName): | |
| print('Could not open file:', mapName) | |
| return None | |
| print('Reading map:', mapName) | |
| m = Map() | |
| x = 0 | |
| with open(mapName, 'r') as f: | |
| for line in f: | |
| # Remove trailing '\n' and collapse excess spaces | |
| line = (' '.join(line.strip().split())).split() | |
| if 'robot_specifications->global_mapsize_x' in line: | |
| continue | |
| elif 'robot_specifications->global_mapsize_y' in line: | |
| continue | |
| elif 'robot_specifications->resolution' in line: | |
| m.resolution = int(line[-1]) | |
| print('Map resolution: %d cm' % m.resolution) | |
| elif 'robot_specifications->autoshifted_x' in line: | |
| m.offset_x = int(line[-1]) | |
| print('Map offsetX: %d cm' % m.offset_x) | |
| elif 'robot_specifications->autoshifted_y' in line: | |
| m.offset_y = int(line[-1]) | |
| print('Map offsetY: %d cm' % m.offset_y) | |
| elif 'global_map[0]:' in line: | |
| m.mapsize_x = int(line[-2]) | |
| m.mapsize_y = int(line[-1]) | |
| m.prob = -np.ones((m.mapsize_x, m.mapsize_y)) | |
| print('Map size:', m.mapsize_x, m.mapsize_y) | |
| else: | |
| if line and m.prob is None: | |
| print('Unable to parse file %s\nIs it properly formatted?' % mapName) | |
| return None | |
| elif not line: | |
| continue | |
| # Insert probabilities into our map | |
| for y, value in enumerate([float(v) for v in line]): | |
| if value >= 0: | |
| m.prob[x, y] = 1 - value | |
| if x < m.min_x: m.min_x = x | |
| elif x > m.max_x: m.max_x = x | |
| if y < m.min_y: m.min_y = y | |
| elif y > m.max_y: m.max_y = y | |
| x += 1 | |
| return m | |
| if __name__ == '__main__': | |
| read_beesoft_map(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment