Skip to content
Snippets Groups Projects
Commit d54f962f authored by mehtank's avatar mehtank
Browse files

Command line interface for creating / testing components in rocolib using python -m rocolib

parent b3248b45
No related merge requests found
......@@ -9,7 +9,7 @@ from os.path import realpath
from os.path import relpath
__version__ = "0.2.0"
__version__ = "0.2.1"
__author__ = 'UCLA LEMUR'
__credits__ = 'The Laboratory for Embedded Machines and Ubiquitous Robots'
......
#!/bin/env python
import logging
import argparse
from rocolib.library import getComponent
from rocolib.api.composables.graph.Joint import FingerJoint
def test(component, params, thickness, display=False, display3D=False):
f = getComponent(component)
if params is not None:
for p in params:
f.setParameter(p[0], eval(p[1]))
if thickness is None:
t = 0
j = None
else:
t = thickness
j = FingerJoint(thickness=t)
f.makeOutput("output/" + component, display=display, display3D=display3D, thickness=t, joint=j)
if __name__ == '__main__':
LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
DEFAULT_LOG_LEVEL = "WARNING"
parser = argparse.ArgumentParser()
parser.add_argument("component", help="Name of the component you'd like to test")
parser.add_argument("--verbose", "-v", dest="log_level", action="append_const", const=-1)
parser.add_argument("--quiet", "-q", dest="log_level", action="append_const", const=1)
parser.add_argument("-t", type=float, help="Thickness if you are making with wood")
parser.add_argument("-d", action='store_true', help="Display 2D drawing")
parser.add_argument("-D", action='store_true', help="Display 3D drawing")
parser.add_argument("-P", nargs=2, action='append',
metavar=("NAME", "VALUE"),
help="Set component parameter NAME to value VALUE")
args = parser.parse_args()
log_level = LOG_LEVELS.index(DEFAULT_LOG_LEVEL)
# For each "-q" and "-v" flag, adjust the logging verbosity accordingly
# making sure to clamp off the value from 0 to 4, inclusive of both
for adjustment in args.log_level or ():
log_level = min(len(LOG_LEVELS) - 1, max(log_level + adjustment, 0))
log_level_name = LOG_LEVELS[log_level]
logging.basicConfig(level=getattr(logging, log_level_name))
test(args.component, args.P, thickness=args.t, display=args.d, display3D=args.D)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment