-
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.
Merge PR #10 from osu-capstone-afrl/JSON-improvements
Centralize Path Definition Parameters
- Loading branch information
Showing
5 changed files
with
125 additions
and
45 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
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 |
---|---|---|
@@ -1,7 +1,22 @@ | ||
{ | ||
"type":"steppedrings", | ||
"size":[0.06, 0.04, 0.14], | ||
"posn":[0.7, 0, 0.3], | ||
"orientation":[[0.866, -0.5, 0],[0.5, 0.866, 0],[0, 0, 1]], | ||
"comment":"For steppedrings with rotated camera, use size=[0.06, 0.04, 0.14], posn=[0.06, 0.04, 0.14]" | ||
"PathType":"SteppedRings", | ||
"ObjectInfo":{ | ||
"size":[0.06, 0.04, 0.14], | ||
"position":[0.7, 0, 0.3], | ||
"orientation":[[0.866, -0.5, 0],[0.5, 0.866, 0],[0, 0, 1]] | ||
}, | ||
"SteppedRings": { | ||
"scale":null, | ||
"offset":null, | ||
"level_count": null, | ||
"density": null | ||
}, | ||
"InclinedPlanes": { | ||
"count":null, | ||
"clearance":null, | ||
"plane_scale": null, | ||
"slope": null, | ||
"offset": null | ||
}, | ||
"comment":"For SteppedRings with rotated camera, use size=[0.06, 0.04, 0.14], posn=[0.06, 0.04, 0.14]" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from path_plans import InclinedPlane | ||
from path_plans import SteppedRings | ||
from path_plans import OrthogonalCapture | ||
import numpy as np | ||
import argparse | ||
import inspect | ||
import json | ||
import sys | ||
import os | ||
current = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def get_path_from_json(structure): | ||
""" Accepts a dictionary from a JSON file with information about an object | ||
and settings for a path plan and returns the specified path plan. | ||
Assumes any parameters set to None (null in JSON notation) should be | ||
the default value. | ||
@param structure: dictionary of of a loaded json file. | ||
""" | ||
size = structure['ObjectInfo']['size'] | ||
position = structure['ObjectInfo']['position'] | ||
orientation = np.array(structure['ObjectInfo']['orientation']) | ||
path_type = structure['PathType'] | ||
if path_type == 'SteppedRings': | ||
a = inspect.getargspec(SteppedRings.__init__) | ||
defaults = dict(zip(a.args[-len(a.defaults):],a.defaults)) | ||
|
||
opt = structure['SteppedRings'] | ||
for k in opt.keys(): | ||
if opt[k] is None: | ||
opt[k] = defaults[k] | ||
|
||
path = SteppedRings(size, | ||
position, | ||
orientation, | ||
scale=opt['scale'], | ||
offset=opt['offset'], | ||
level_count=opt['level_count'], | ||
density=opt['density'], | ||
) | ||
elif path_type == 'InclinedPlane': | ||
a = inspect.getargspec(InclinedPlane.__init__) | ||
defaults = dict(zip(a.args[-len(a.defaults):],a.defaults)) | ||
|
||
opt = structure['InclinedPlane'] | ||
for k in opt.keys(): | ||
if opt[k] is None: | ||
opt[k] = defaults[k] | ||
|
||
path = InclinedPlane(size, | ||
position, | ||
orientation, | ||
count=opt['count'], | ||
clearance=opt['clearance'], | ||
plane_scale=opt['plane_scale'], | ||
slope=opt['slope'], | ||
offset=opt['offset'], | ||
) | ||
else: | ||
path = None | ||
exit('[ERROR] Invalid path type in JSON file.') | ||
|
||
return path | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description="Input JSON file name") | ||
parser.add_argument('-json_name', '--json-name', type=str, default='detected_object.json') | ||
args = parser.parse_args() | ||
json_name = args.json_name | ||
fname = os.path.join(current, json_name) | ||
with open(fname, "r") as read_file: | ||
json_structure = json.load(read_file) | ||
|
||
path_plan = get_path_from_json(json_structure) |