motions_loader.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 #
00004 # Copyright (c) 2014 PAL Robotics SL. All Rights Reserved
00005 #
00006 # Permission to use, copy, modify, and/or distribute this software for
00007 # any purpose with or without fee is hereby granted, provided that the
00008 # above copyright notice and this permission notice appear in all
00009 # copies.
00010 #
00011 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00012 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00013 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
00014 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00015 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00016 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00017 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00018 #
00019 # Authors:
00020 # * Sammy Pfeiffer
00021 '''
00022 @author: Sammy Pfeiffer
00023 
00024 Script that tries to load initially private motions
00025 (in the case of working in PAL premises)
00026 and if the package is not found loads the default
00027 public ones
00028 '''
00029 
00030 from rospkg import RosPack, ResourceNotFound
00031 from rosparam import upload_params
00032 from yaml import load
00033 
00034 PRIVATE_PKG_NAME = 'reemc_motions_proprietary'
00035 PUBLIC_PKG_NAME = 'reemc_bringup'
00036 
00037 PRIVATE_CONFIG_YAML = 'reemc_motions.yaml'
00038 PUBLIC_CONFIG_YAML = 'reemc_motions.yaml'
00039 
00040 def load_params_from_yaml(complete_file_path):
00041     '''Gets the params from a yaml file given the complete path of the
00042     file and uploads those to the param server.
00043     This is convenience function as rosparam.load_file does not
00044     give this functionality as found here:
00045     http://answers.ros.org/question/169866/load-yaml-with-code/'''
00046     f = open(complete_file_path, 'r')
00047     yamlfile = load(f)
00048     f.close()
00049     upload_params('/', yamlfile )
00050 
00051 if __name__ == '__main__':
00052     rp = RosPack()
00053     print "Loading public motions from: " + PUBLIC_PKG_NAME
00054     pub_pkg_path = rp.get_path(PUBLIC_PKG_NAME)
00055     pub_config_yaml = PUBLIC_CONFIG_YAML
00056     pub_full_path = pub_pkg_path + '/config/' + pub_config_yaml
00057     load_params_from_yaml(pub_full_path)
00058     print "Trying to find private package: " + PRIVATE_PKG_NAME
00059     try:
00060         pkg_path = rp.get_path(PRIVATE_PKG_NAME)
00061         config_yaml = PRIVATE_CONFIG_YAML
00062         full_path = pkg_path + '/config/' + config_yaml
00063         print "Loading params from: " +  full_path
00064         load_params_from_yaml(full_path)
00065     except ResourceNotFound:
00066         print "Not found, only using public motions."
00067 
00068     print "Finished."
00069     


reemc_bringup
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Fri Aug 28 2015 12:24:28