respeaker_gencfg.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # Author: furushchev <furushchev@jsk.imi.i.u-tokyo.ac.jp>
00004 
00005 import os
00006 import sys
00007 from respeaker_node import PARAMETERS, init_respeaker
00008 
00009 
00010 def main(out):
00011     dev = init_respeaker()
00012     if not dev:
00013         print('No device found. Please connect a device.')
00014         return
00015     with open(out, "w") as f:
00016         f.write("""\
00017 #!/usr/bin/env python
00018 #
00019 # WARNING!!
00020 # This file is automatically generated.
00021 # DO NOT MODIFY THIS FILE!
00022 #
00023 # To generate this file, please run:
00024 # cd /path/to/this/package
00025 # python ./scripts/respeaker_gencfg.py
00026 #
00027 
00028 from dynamic_reconfigure.parameter_generator_catkin import *
00029 
00030 gen = ParameterGenerator()
00031 
00032 #       name    type     level     description     default      min      max""")
00033 
00034         for key, val in PARAMETERS.items():
00035             type_, max_, min_, rw_ = val[2:6]
00036             desc_ = " ".join(val[6:])
00037             def_ = dev.read(key)
00038             if rw_ != "rw":
00039                 continue
00040             if type_ == "int" and max_ == 1 and min_ == 0:
00041                 if def_ == 1:
00042                     def_ = True
00043                 else:
00044                     def_ = False
00045                 f.write("""
00046 gen.add("{name}", bool_t, 0, "{desc}", {def_})""".format(
00047     name=key, desc=desc_, def_=def_))
00048             elif type_ == "int":
00049                 f.write("""
00050 gen.add("{name}", int_t, 0, "{desc}", {def_}, {min_}, {max_})""".format(
00051     name=key, desc=desc_, def_=def_, min_=min_, max_=max_))
00052             elif type_ == "float":
00053                 f.write("""
00054 gen.add("{name}", double_t, 0, "{desc}", {def_:f}, {min_:f}, {max_:f})""".format(
00055     name=key, desc=desc_, def_=def_, min_=min_, max_=max_))
00056             else:
00057                 print "Param '{name}' is ignored.".format(name=key)
00058 
00059         f.write("""
00060 
00061 exit(gen.generate("respaker_ros", "respeaker_ros", "Respeaker"))
00062 """)
00063 
00064     os.chmod(out, 0775)
00065 
00066     print "Saved cfg to %s" % out
00067 
00068 
00069 if __name__ == '__main__':
00070     if len(sys.argv) > 1:
00071         outpath = sys.argv[1]
00072     else:
00073         outpath = os.path.join(
00074             os.path.abspath(os.path.dirname(__file__)),
00075             "..", "cfg", "Respeaker.cfg")
00076     main(outpath)


respeaker_ros
Author(s): Yuki Furuta
autogenerated on Wed Jul 10 2019 03:24:12