hlrc / client / python / hlrc_client / RobotController.py @ 62d50515
History | View | Annotate | Download (3.492 KB)
| 1 | 0c286af0 | Simon Schulz | """
|
|---|---|---|---|
| 2 | This file is part of hlrc
|
||
| 3 |
|
||
| 4 | Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
||
| 5 | http://opensource.cit-ec.de/projects/hlrc
|
||
| 6 |
|
||
| 7 | This file may be licensed under the terms of the
|
||
| 8 | GNU General Public License Version 3 (the ``GPL''),
|
||
| 9 | or (at your option) any later version.
|
||
| 10 |
|
||
| 11 | Software distributed under the License is distributed
|
||
| 12 | on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
||
| 13 | express or implied. See the GPL for the specific language
|
||
| 14 | governing rights and limitations.
|
||
| 15 |
|
||
| 16 | You should have received a copy of the GPL along with this
|
||
| 17 | program. If not, go to http://www.gnu.org/licenses/gpl.html
|
||
| 18 | or write to the Free Software Foundation, Inc.,
|
||
| 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 20 |
|
||
| 21 | The development of this software was supported by the
|
||
| 22 | Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
||
| 23 | The Excellence Cluster EXC 277 is a grant of the Deutsche
|
||
| 24 | Forschungsgemeinschaft (DFG) in the context of the German
|
||
| 25 | Excellence Initiative.
|
||
| 26 | """
|
||
| 27 | |||
| 28 | import logging |
||
| 29 | from MiddlewareRSB import * |
||
| 30 | from MiddlewareROS import * |
||
| 31 | |||
| 32 | class RobotController: |
||
| 33 | def __init__(self, mw_name, scope, loglevel=logging.WARNING): |
||
| 34 | self.logger = logging.getLogger(__name__)
|
||
| 35 | |||
| 36 | # create nice and actually usable formatter and add it to the handler
|
||
| 37 | self.config_logger(loglevel)
|
||
| 38 | |||
| 39 | #store scope
|
||
| 40 | self.scope = scope
|
||
| 41 | |||
| 42 | if (mw_name.upper() == "RSB"): |
||
| 43 | self.logger.info("creating new middleware connection via RSB") |
||
| 44 | self.middleware = MiddlewareRSB(self.scope, loglevel) |
||
| 45 | elif (mw_name.upper() == "ROS"): |
||
| 46 | self.logger.info("creating new middleware connection via ROS") |
||
| 47 | self.middleware = MiddlewareROS(self.scope, loglevel) |
||
| 48 | else:
|
||
| 49 | self.logger.error("invalid middleware requested (%s). supported: {ROS, RSB}\n\n" % (mw_name)) |
||
| 50 | sys.exit(errno.EINVAL) |
||
| 51 | |||
| 52 | def config_logger(self, level): |
||
| 53 | formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
|
||
| 54 | ch = logging.StreamHandler() |
||
| 55 | #ch.setLevel(level)
|
||
| 56 | ch.setFormatter(formatter) |
||
| 57 | self.logger.setLevel(level)
|
||
| 58 | self.logger.addHandler(ch)
|
||
| 59 | |||
| 60 | def set_current_emotion(self, robot_emotion, blocking = False): |
||
| 61 | self.logger.debug("set_current_emotion(%s) %s" % (robot_emotion, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 62 | self.middleware.set_current_emotion(robot_emotion, blocking)
|
||
| 63 | |||
| 64 | def set_default_emotion(self, robot_emotion, blocking = False): |
||
| 65 | self.logger.debug("set_default_emotion(%s) %s" % (robot_emotion, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 66 | self.middleware.set_default_emotion(robot_emotion, blocking)
|
||
| 67 | |||
| 68 | def set_gaze_target(self, robot_gaze, blocking = False): |
||
| 69 | self.logger.debug("set_gaze_target(%s) %s" % (robot_gaze, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 70 | self.middleware.set_gaze_target(robot_gaze, blocking)
|
||
| 71 | |||
| 72 | def set_mouth_target(self, robot_mouth, blocking = False): |
||
| 73 | self.logger.debug("set_mouth_target(%s) %s" % (robot_mouth, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 74 | self.middleware.set_mouth_target(robot_mouth, blocking)
|
||
| 75 | |||
| 76 | def set_head_animation(self, robot_animation, blocking = False): |
||
| 77 | self.logger.debug("set_head_animation(%s) %s" % (robot_animation, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 78 | self.middleware.set_head_animation(robot_animation, blocking)
|
||
| 79 | |||
| 80 | def set_speak(self, text, blocking = False): |
||
| 81 | self.logger.debug("set_speak(%s) %s" % (text, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
||
| 82 | self.middleware.set_speak(text, blocking)
|
||
| 83 | |||
| 84 | def get_gaze_target(self): |
||
| 85 | result = self.middleware.get_gaze_target()
|
||
| 86 | self.logger.debug("get_gaze_target() returned %s" % (result)) |
||
| 87 | return self.middleware.get_gaze_target() |