00001 #!/usr/bin/python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2010 \n 00007 # Fraunhofer Institute for Manufacturing Engineering 00008 # and Automation (IPA) \n\n 00009 # 00010 ################################################################# 00011 # 00012 # \note 00013 # Project name: care-o-bot 00014 # \note 00015 # ROS stack name: cob_apps 00016 # \note 00017 # ROS package name: cob_dashboard 00018 # 00019 # \author 00020 # Author: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00021 # \author 00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00023 # 00024 # \date Date of creation: Aug 2010 00025 # 00026 # \brief 00027 # Implementation of ROS node for dashboard. 00028 # 00029 ################################################################# 00030 # 00031 # Redistribution and use in source and binary forms, with or without 00032 # modification, are permitted provided that the following conditions are met: 00033 # 00034 # - Redistributions of source code must retain the above copyright 00035 # notice, this list of conditions and the following disclaimer. \n 00036 # - Redistributions in binary form must reproduce the above copyright 00037 # notice, this list of conditions and the following disclaimer in the 00038 # documentation and/or other materials provided with the distribution. \n 00039 # - Neither the name of the Fraunhofer Institute for Manufacturing 00040 # Engineering and Automation (IPA) nor the names of its 00041 # contributors may be used to endorse or promote products derived from 00042 # this software without specific prior written permission. \n 00043 # 00044 # This program is free software: you can redistribute it and/or modify 00045 # it under the terms of the GNU Lesser General Public License LGPL as 00046 # published by the Free Software Foundation, either version 3 of the 00047 # License, or (at your option) any later version. 00048 # 00049 # This program is distributed in the hope that it will be useful, 00050 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00051 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00052 # GNU Lesser General Public License LGPL for more details. 00053 # 00054 # You should have received a copy of the GNU Lesser General Public 00055 # License LGPL along with this program. 00056 # If not, see <http://www.gnu.org/licenses/>. 00057 # 00058 ################################################################# 00059 00060 import rospy 00061 from simple_script_server import * 00062 00063 ## Implements configurable buttons 00064 class buttons: 00065 def __init__(self): 00066 self.sss = simple_script_server() 00067 self.panels = [] 00068 self.CreateControlPanel() 00069 00070 ## Creates the control panel out of configuration from ROS parameter server 00071 def CreateControlPanel(self): 00072 param_prefix = "/dashboard/control_buttons" 00073 if not rospy.has_param(param_prefix): 00074 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",param_prefix) 00075 return False 00076 group_param = rospy.get_param(param_prefix) 00077 #print group_param 00078 group_param = self.SortDict(group_param) 00079 #print group_param 00080 00081 for group in group_param: 00082 group_name = group[1]["group_name"] 00083 component_name = group[1]["component_name"] # \todo check component name with robot_components.yaml files 00084 button_list = group[1]["buttons"] 00085 buttons = [] 00086 for button in button_list: 00087 #print "button = ",button 00088 if button[1] == "move": 00089 buttons.append(self.CreateButton(button[0],self.sss.move,component_name,button[2])) 00090 elif button[1] == "trigger": 00091 buttons.append(self.CreateButton(button[0],self.sss.trigger,component_name,button[2])) 00092 elif button[1] == "mode": 00093 buttons.append(self.CreateButton(button[0],self.sss.set_operation_mode,component_name,button[2])) 00094 else: 00095 rospy.logerr("Function <<%s>> not known to dashboard",button[1]) 00096 return False 00097 group = (group_name,buttons) 00098 00099 # add nav buttons 00100 if component_name == "base": # \todo get base name from robot_components.yaml 00101 param_prefix = "/dashboard/nav_buttons" 00102 if not rospy.has_param(param_prefix): 00103 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",param_prefix) 00104 return False 00105 nav_buttons_param = rospy.get_param(param_prefix) 00106 nav_button_list = nav_buttons_param["buttons"] 00107 #print nav_button_list 00108 for button in nav_button_list: 00109 #print "button = ",button 00110 buttons.append(self.CreateButton(button[0],self.sss.move,component_name,button[2])) 00111 self.panels.append(group) 00112 00113 ## Creates one button with functionality 00114 def CreateButton(self,button_name,function,component_name,parameter_name): 00115 button = (button_name,function,(component_name,parameter_name,False)) 00116 return button 00117 00118 ## Sorts a dictionary alphabetically 00119 def SortDict(self,dictionary): 00120 keys = sorted(dictionary.iterkeys()) 00121 k=[] 00122 #print "keys = ", keys 00123 #for key in keys: 00124 # print "values = ", dictionary[key] 00125 return [[key,dictionary[key]] for key in keys]