Revision 64f5c90e
| client/python/hlrc_client/MiddlewareROS.py | ||
|---|---|---|
| 28 | 28 |
from Middleware import * |
| 29 | 29 |
import errno |
| 30 | 30 |
|
| 31 |
try: |
|
| 32 |
import roslib; |
|
| 33 |
|
|
| 34 |
import rospy |
|
| 35 |
import actionlib |
|
| 36 |
from hlrc_server.msg import * |
|
| 37 |
|
|
| 38 |
except ImportError as exception: |
|
| 39 |
sys.stderr.write("ImportError: {}\n> HINT: try to export PYTHONPATH=$PYTHONPATH:$YOUR_PREFIX/lib/python2.7/site-packages/\n\n".format(exception))
|
|
| 40 |
sys.exit(errno.ENOPKG) |
|
| 31 |
import roslib; |
|
| 32 |
import rospy |
|
| 33 |
import actionlib |
|
| 34 |
from hlrc_server.msg import * |
|
| 41 | 35 |
|
| 42 | 36 |
class MiddlewareROS(Middleware): |
| 43 | 37 |
#default timeout to wait in case of blocking calls |
| ... | ... | |
| 172 | 166 |
goal.tilt_offset = gaze.tilt_offset |
| 173 | 167 |
|
| 174 | 168 |
#type |
| 175 |
if (gaze.gaze_type == RobotGaze.ABSOLUTE): |
|
| 176 |
goal.gaze_type = gazetargetGoal.ABSOLUTE |
|
| 169 |
if (gaze.gaze_type == RobotGaze.GAZETARGET_ABSOLUTE):
|
|
| 170 |
goal.gaze_type = gazetargetGoal.GAZETARGET_ABSOLUTE
|
|
| 177 | 171 |
else: |
| 178 |
goal.gaze_type = gazetargetGoal.RELATIVE |
|
| 172 |
goal.gaze_type = gazetargetGoal.GAZETARGET_RELATIVE
|
|
| 179 | 173 |
|
| 180 | 174 |
goal.timestamp = rospy.Time.from_sec(gaze.timestamp) |
| 181 | 175 |
|
| client/python/hlrc_client/MiddlewareRSB.py | ||
|---|---|---|
| 30 | 30 |
|
| 31 | 31 |
import rsb |
| 32 | 32 |
import rsb.converter |
| 33 |
try: |
|
| 34 |
import rst |
|
| 35 |
import rstsandbox |
|
| 36 |
from rst.robot.EmotionState_pb2 import EmotionState |
|
| 37 |
from rst.robot.Animation_pb2 import Animation |
|
| 38 |
from rst.robot.GazeTarget_pb2 import GazeTarget |
|
| 39 |
from rst.robot.MouthTarget_pb2 import MouthTarget |
|
| 40 |
except ImportError, e: |
|
| 41 |
print("Warning, RSB could be imported, but the required message types do not exist: ")
|
|
| 42 |
print e |
|
| 43 |
|
|
| 44 |
#except ImportError as exception: |
|
| 45 |
# sys.stderr.write("ImportError: {}\n> HINT: try to export PYTHONPATH=$PYTHONPATH:$YOUR_PREFIX/lib/python2.7/site-packages/\n\n".format(exception))
|
|
| 46 |
# sys.exit(errno.ENOPKG) |
|
| 33 |
import rst |
|
| 34 |
import rstsandbox |
|
| 35 |
from rst.robot.EmotionState_pb2 import EmotionState |
|
| 36 |
from rst.robot.Animation_pb2 import Animation |
|
| 37 |
from rst.robot.GazeTarget_pb2 import GazeTarget |
|
| 38 |
from rst.robot.MouthTarget_pb2 import MouthTarget |
|
| 47 | 39 |
|
| 48 | 40 |
class MiddlewareRSB(Middleware): |
| 49 | 41 |
####################################################################### |
| client/python/hlrc_client/RobotController.py | ||
|---|---|---|
| 26 | 26 |
""" |
| 27 | 27 |
|
| 28 | 28 |
import logging |
| 29 |
try: |
|
| 30 |
import rsb |
|
| 31 |
import rst |
|
| 32 |
import rstsandbox |
|
| 33 |
from rst.robot.EmotionState_pb2 import EmotionState |
|
| 34 |
from rst.robot.Animation_pb2 import Animation |
|
| 35 |
from rst.robot.GazeTarget_pb2 import GazeTarget |
|
| 36 |
from rst.robot.MouthTarget_pb2 import MouthTarget |
|
| 37 |
except ImportError, e: |
|
| 38 |
print("Warning, RSB import error: ")
|
|
| 39 |
print e |
|
| 40 |
RSB_SUPPORT = False |
|
| 41 |
else: |
|
| 42 |
from MiddlewareRSB import * |
|
| 43 |
RSB_SUPPORT = True |
|
| 44 |
|
|
| 45 |
from MiddlewareROS import * |
|
| 46 | 29 |
import sys |
| 30 |
import errno |
|
| 47 | 31 |
|
| 48 | 32 |
class RobotController: |
| 49 | 33 |
def __init__(self, mw_name, scope, loglevel=logging.WARNING): |
| ... | ... | |
| 66 | 50 |
|
| 67 | 51 |
|
| 68 | 52 |
if (self.mw.upper() == "RSB"): |
| 69 |
if (not RSB_SUPPORT): |
|
| 70 |
self.logger.error("ERROR: no RSB support detected")
|
|
| 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))
|
|
| 71 | 58 |
sys.exit(errno.EINVAL) |
| 72 |
else: |
|
| 73 |
self.logger.info("creating new middleware connection via RSB")
|
|
| 74 |
self.middleware = MiddlewareRSB(self.scope, self.loglevel) |
|
| 59 |
|
|
| 60 |
#import worked, safe to intantiate RSB mw now |
|
| 61 |
self.middleware = MiddlewareRSB(self.scope, self.loglevel) |
|
| 62 |
|
|
| 75 | 63 |
elif (self.mw.upper() == "ROS"): |
| 76 | 64 |
self.logger.info("creating new middleware connection via ROS")
|
| 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 |
|
| 77 | 72 |
self.middleware = MiddlewareROS(self.scope, self.loglevel) |
| 78 | 73 |
else: |
| 79 | 74 |
self.logger.error("invalid middleware requested (%s). supported: {ROS, RSB}\n\n" % (self.mw))
|
| client/python/hlrc_client/RobotGaze.py | ||
|---|---|---|
| 24 | 24 |
Forschungsgemeinschaft (DFG) in the context of the German |
| 25 | 25 |
Excellence Initiative. |
| 26 | 26 |
""" |
| 27 |
|
|
| 28 | 27 |
import time |
| 29 | 28 |
|
| 30 |
|
|
| 31 | 29 |
class RobotGaze: |
| 30 |
GAZETARGET_ABSOLUTE = 0 |
|
| 31 |
GAZETARGET_RELATIVE = 1 |
|
| 32 |
|
|
| 33 |
def __init__(self): |
|
| 34 |
self.pan = 0.0 |
|
| 35 |
self.tilt = 0.0 |
|
| 36 |
self.roll = 0.0 |
|
| 37 |
self.vergence = 0.0 |
|
| 38 |
self.pan_offset = 0.0 |
|
| 39 |
self.tilt_offset = 0.0 |
|
| 40 |
self.gaze_type = RobotGaze.GAZETARGET_ABSOLUTE |
|
| 41 |
self.timestamp = time.time() |
|
| 42 |
|
|
| 43 |
def __str__(self): |
|
| 44 |
if self.gaze_type == RobotGaze.GAZETARGET_ABSOLUTE: |
|
| 45 |
type_s = "ABSOLUTE" |
|
| 46 |
else: |
|
| 47 |
type_s = "RELATIVE" |
|
| 48 |
return "RobotGaze = { PTR={%6.2f %6.2f %6.2f} vergence=%6.2f PT_offset={%6.2f %6.2f} [%s]}" \
|
|
| 49 |
% (self.pan, self.tilt, self.roll, self.vergence, self.pan_offset, self.tilt_offset, type_s) |
|
| 32 | 50 |
|
| 33 |
def __init__(self): |
|
| 34 |
self.GAZETARGET_ABSOLUTE = 0 |
|
| 35 |
self.GAZETARGET_RELATIVE = 1 |
|
| 36 |
self.pan = 0.0 |
|
| 37 |
self.tilt = 0.0 |
|
| 38 |
self.roll = 0.0 |
|
| 39 |
self.vergence = 0.0 |
|
| 40 |
self.pan_offset = 0.0 |
|
| 41 |
self.tilt_offset = 0.0 |
|
| 42 |
self.gaze_type = self.GAZETARGET_ABSOLUTE |
|
| 43 |
self.timestamp = time.time() |
|
| 44 |
|
|
| 45 |
def __str__(self): |
|
| 46 |
if self.gaze_type == self.GAZETARGET_ABSOLUTE: |
|
| 47 |
type_s = "ABSOLUTE" |
|
| 48 |
else: |
|
| 49 |
type_s = "RELATIVE" |
|
| 50 |
return "RobotGaze = { PTR={%6.2f %6.2f %6.2f} vergence=%6.2f PT_offset={%6.2f %6.2f} [%s]}" \
|
|
| 51 |
% (self.pan, self.tilt, self.roll, self.vergence, self.pan_offset, self.tilt_offset, type_s) |
|
| client/python/test.py | ||
|---|---|---|
| 43 | 43 |
r.set_speak("test 123")
|
| 44 | 44 |
|
| 45 | 45 |
g = RobotGaze() |
| 46 |
g.gaze_type = RobotGaze.GAZETARGET_ABSOLUTE |
|
| 46 | 47 |
|
| 47 | 48 |
m = RobotMouth() |
| 48 | 49 |
m.position_center = 10.0 |
| ... | ... | |
| 50 | 51 |
r.set_mouth_target(m) |
| 51 | 52 |
|
| 52 | 53 |
while(True): |
| 54 |
g.timestamp = time.time() |
|
| 53 | 55 |
g.pan = g.pan + 5.0; |
| 54 | 56 |
if (g.pan > 20.0): |
| 55 | 57 |
g.pan = -20.0 |
| server/src/main.cpp | ||
|---|---|---|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
//human motion connection: |
| 82 |
printf("> initializing humotion client\n");
|
|
| 83 | 82 |
humotion::client::Client *client = new humotion::client::Client(scope, mw_humotion); |
| 84 | 83 |
|
| 85 | 84 |
printf("> all done. hlrc server ready\n");
|
Also available in: Unified diff