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