Revision f8fa1217 client/python/hlrc_client/RobotController.py
client/python/hlrc_client/RobotController.py | ||
---|---|---|
31 | 31 |
|
32 | 32 |
class RobotController: |
33 | 33 |
def __init__(self, mw_name, scope, loglevel=logging.WARNING): |
34 |
"""initialise |
|
35 |
:param mw_name: which mw to use, currentyl ROS and RSB are supported |
|
36 |
:param scope: base scope we want to listen on |
|
37 |
:param loglevel: optional log level |
|
38 |
""" |
|
34 | 39 |
self.logger = logging.getLogger(__name__) |
35 | 40 |
|
36 | 41 |
# create nice and actually usable formatter and add it to the handler |
37 | 42 |
self.config_logger(loglevel) |
38 | 43 |
|
39 |
#store scope
|
|
44 |
#store |
|
40 | 45 |
self.scope = scope |
46 |
self.mw = mw_name |
|
47 |
self.loglevel = loglevel |
|
41 | 48 |
|
42 |
if (mw_name.upper() == "RSB"): |
|
49 |
self.middleware = None |
|
50 |
|
|
51 |
|
|
52 |
if (self.mw.upper() == "RSB"): |
|
43 | 53 |
self.logger.info("creating new middleware connection via RSB") |
44 |
self.middleware = MiddlewareRSB(self.scope, loglevel) |
|
45 |
elif (mw_name.upper() == "ROS"):
|
|
54 |
self.middleware = MiddlewareRSB(self.scope, self.loglevel)
|
|
55 |
elif (self.mw.upper() == "ROS"):
|
|
46 | 56 |
self.logger.info("creating new middleware connection via ROS") |
47 |
self.middleware = MiddlewareROS(self.scope, loglevel) |
|
57 |
self.middleware = MiddlewareROS(self.scope, self.loglevel)
|
|
48 | 58 |
else: |
49 |
self.logger.error("invalid middleware requested (%s). supported: {ROS, RSB}\n\n" % (mw_name))
|
|
59 |
self.logger.error("invalid middleware requested (%s). supported: {ROS, RSB}\n\n" % (self.mw))
|
|
50 | 60 |
sys.exit(errno.EINVAL) |
51 | 61 |
|
62 |
def __del__(self): |
|
63 |
"""destructor |
|
64 |
""" |
|
65 |
self.logger.debug("destructor of RobotController called") |
|
66 |
|
|
52 | 67 |
def config_logger(self, level): |
68 |
"""initialise a nice logger formatting |
|
69 |
:param level: log level |
|
70 |
""" |
|
53 | 71 |
formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s') |
54 | 72 |
ch = logging.StreamHandler() |
55 | 73 |
#ch.setLevel(level) |
... | ... | |
58 | 76 |
self.logger.addHandler(ch) |
59 | 77 |
|
60 | 78 |
def set_current_emotion(self, robot_emotion, blocking = False): |
79 |
"""set the current emotion |
|
80 |
:param robot_emotion: a RobotEmotion object |
|
81 |
:param blocking: should this call block during execution? |
|
82 |
""" |
|
61 | 83 |
self.logger.debug("set_current_emotion(%s) %s" % (robot_emotion, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
62 | 84 |
self.middleware.set_current_emotion(robot_emotion, blocking) |
63 | 85 |
|
64 | 86 |
def set_default_emotion(self, robot_emotion, blocking = False): |
87 |
"""set the default emotion |
|
88 |
:param robot_emotion: a RobotEmotion object |
|
89 |
:param blocking: should this call block during execution? |
|
90 |
""" |
|
65 | 91 |
self.logger.debug("set_default_emotion(%s) %s" % (robot_emotion, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
66 | 92 |
self.middleware.set_default_emotion(robot_emotion, blocking) |
67 | 93 |
|
68 | 94 |
def set_gaze_target(self, robot_gaze, blocking = False): |
95 |
"""set a gaze target |
|
96 |
:param robot_gaze: a RobotGaze object |
|
97 |
:param blocking: should this call block during execution? |
|
98 |
""" |
|
99 |
|
|
69 | 100 |
self.logger.debug("set_gaze_target(%s) %s" % (robot_gaze, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
70 | 101 |
self.middleware.set_gaze_target(robot_gaze, blocking) |
71 | 102 |
|
72 | 103 |
def set_mouth_target(self, robot_mouth, blocking = False): |
104 |
"""set a mouth target |
|
105 |
:param robot_mouth: a RobotMouth object |
|
106 |
:param blocking: should this call block during execution? |
|
107 |
""" |
|
73 | 108 |
self.logger.debug("set_mouth_target(%s) %s" % (robot_mouth, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
74 | 109 |
self.middleware.set_mouth_target(robot_mouth, blocking) |
75 | 110 |
|
76 | 111 |
def set_head_animation(self, robot_animation, blocking = False): |
112 |
"""set a head animation |
|
113 |
:param robot_animation: a RobotAnimation object |
|
114 |
:param blocking: should this call block during execution? |
|
115 |
""" |
|
77 | 116 |
self.logger.debug("set_head_animation(%s) %s" % (robot_animation, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
78 | 117 |
self.middleware.set_head_animation(robot_animation, blocking) |
79 | 118 |
|
80 | 119 |
def set_speak(self, text, blocking = False): |
120 |
"""request the robot to say something using tts |
|
121 |
:param text: text to synthesize |
|
122 |
:param blocking: should this call block during execution? |
|
123 |
""" |
|
81 | 124 |
self.logger.debug("set_speak(%s) %s" % (text, ("BLOCKING" if blocking else "NON_BLOCKING"))) |
82 | 125 |
self.middleware.set_speak(text, blocking) |
83 | 126 |
|
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() |
|
127 |
#def get_gaze_target(self): |
|
128 |
# result = self.middleware.get_gaze_target() |
|
129 |
# self.logger.debug("get_gaze_target() returned %s" % (result)) |
|
130 |
# return self.middleware.get_gaze_target() |
Also available in: Unified diff