本文整理汇总了Python中rospy.wait_for_service方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.wait_for_service方法的具体用法?Python rospy.wait_for_service怎么用?Python rospy.wait_for_service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rospy
的用法示例。
在下文中一共展示了rospy.wait_for_service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fk_service_client
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def fk_service_client(limb = "right"):
ns = "ExternalTools/" + limb + "/PositionKinematicsNode/FKService"
fksvc = rospy.ServiceProxy(ns, SolvePositionFK)
fkreq = SolvePositionFKRequest()
joints = JointState()
joints.name = ['right_j0', 'right_j1', 'right_j2', 'right_j3',
'right_j4', 'right_j5', 'right_j6']
joints.position = [0.763331, 0.415979, -1.728629, 1.482985,
-1.135621, -1.674347, -0.496337]
# Add desired pose for forward kinematics
fkreq.configuration.append(joints)
# Request forward kinematics from base to "right_hand" link
fkreq.tip_names.append('right_hand')
try:
rospy.wait_for_service(ns, 5.0)
resp = fksvc(fkreq)
except (rospy.ServiceException, rospy.ROSException), e:
rospy.logerr("Service call failed: %s" % (e,))
return False
# Check if result valid
示例2: get_endeffector_pos
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def get_endeffector_pos(self):
fkreq = SolvePositionFKRequest()
joints = JointState()
joints.name = self._limb_right.joint_names()
joints.position = [self._limb_right.joint_angle(j)
for j in joints.name]
# Add desired pose for forward kinematics
fkreq.configuration.append(joints)
fkreq.tip_names.append('right_hand')
try:
rospy.wait_for_service(self.name_of_service, 5)
resp = self.fksvc(fkreq)
except (rospy.ServiceException, rospy.ROSException), e:
rospy.logerr("Service call failed: %s" % (e,))
return False
示例3: get_object_relative_pose
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def get_object_relative_pose(self, obj_type="SQUARE", obj_color="BLUE", ret_image=True):
service_name = self.__services_name['object_pose_service']
rospy.wait_for_service(service_name)
try:
detection_service = rospy.ServiceProxy(service_name, ObjDetection)
response = detection_service(obj_type=obj_type, obj_color=obj_color,
workspace_ratio=25. / 16, ret_image=ret_image)
ret_status = self.__status_interpreter_obj_detection[response.status]
if ret_status != "SUCCESSFUL":
print "Object not detected: " + ret_status
msg_res = response.obj_pose
obj_type = response.obj_type
obj_color = response.obj_color
if ret_image:
im_ret = extract_img_from_ros_msg(response.img)
else:
im_ret = None
return ret_status, msg_res, obj_type, obj_color, im_ret
except rospy.ServiceException, e:
print "Service call failed: %s" % e
示例4: call_service
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def call_service(self, service_name, service_msg_type, args):
"""
Wait for the service called service_name
Then call the service with args
:param service_name:
:param service_msg_type:
:param args: Tuple of arguments
:raises NiryoOneException: Timeout during waiting of services
:return: Response
"""
# Connect to service
try:
rospy.wait_for_service(service_name, self.service_timeout)
except rospy.ROSException, e:
raise NiryoOneException(e)
# Call service
示例5: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def __init__(self):
rospy.wait_for_service('niryo_one/tools/ping_and_set_dxl_tool')
rospy.wait_for_service('niryo_one/tools/open_gripper')
rospy.wait_for_service('niryo_one/tools/close_gripper')
rospy.wait_for_service('niryo_one/tools/pull_air_vacuum_pump')
rospy.wait_for_service('niryo_one/tools/push_air_vacuum_pump')
self.service_ping_dxl_tool = rospy.ServiceProxy('niryo_one/tools/ping_and_set_dxl_tool', PingDxlTool)
self.service_open_gripper = rospy.ServiceProxy('niryo_one/tools/open_gripper', OpenGripper)
self.service_close_gripper = rospy.ServiceProxy('niryo_one/tools/close_gripper', CloseGripper)
self.service_pull_air_vacuum_pump = rospy.ServiceProxy('niryo_one/tools/pull_air_vacuum_pump',
PullAirVacuumPump)
self.service_push_air_vacuum_pump = rospy.ServiceProxy('niryo_one/tools/push_air_vacuum_pump',
PushAirVacuumPump)
self.service_setup_digital_output_tool = rospy.ServiceProxy('niryo_one/rpi/set_digital_io_mode', SetDigitalIO)
self.service_activate_digital_output_tool = rospy.ServiceProxy('niryo_one/rpi/set_digital_io_state',
SetDigitalIO)
rospy.loginfo("Interface between Tools Controller and Ros Control has been started.")
示例6: set_dxl_leds
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def set_dxl_leds(color):
leds = [0, 0, 0, 8] # gripper LED will not be used
if color == LED_RED:
leds = [1, 1, 1, 8]
elif color == LED_GREEN:
leds = [2, 2, 2, 8]
elif color == LED_BLUE:
leds = [4, 4, 4, 8]
# 4 is yellow, no yellow
elif color == LED_BLUE_GREEN:
leds = [6, 6, 6, 8]
elif color == LED_PURPLE:
leds = [5, 5, 5, 8]
elif color == LED_WHITE:
leds = [7, 7, 7, 8]
try:
rospy.wait_for_service('/niryo_one/set_dxl_leds', timeout=1)
except rospy.ROSException, e:
rospy.logwarn("Niryo ROS control LED service is not up!")
示例7: execute
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def execute(self, inputs, outputs, gvm):
turtle_name = inputs["turtle_name"]
x = inputs["x_pos"]
y = inputs["y_pos"]
phi = inputs["phi"]
service = "/spawn"
rospy.wait_for_service(service)
spawn_turtle_service = rospy.ServiceProxy(service, Spawn)
resp1 = spawn_turtle_service(x, y, phi, turtle_name)
self.logger.info("ROS external module: executed the {} service".format(service))
turtle_pos_subscriber = rospy.Subscriber("/" + turtle_name + "/pose", Pose, check_turtle_pose)
r = rospy.Rate(10)
global pose_received
# wait until the first pose message was received
while not pose_received:
r.sleep()
return 0
示例8: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def __init__(self, configs):
self.configs = configs
self.ROT_VEL = self.configs.BASE.MAX_ABS_TURN_SPEED
self.LIN_VEL = self.configs.BASE.MAX_ABS_FWD_SPEED
self.MAP_FRAME = self.configs.BASE.MAP_FRAME
self.BASE_FRAME = self.configs.BASE.VSLAM.VSLAM_BASE_FRAME
self.point_idx = self.configs.BASE.TRACKED_POINT
rospy.wait_for_service(self.configs.BASE.PLAN_TOPIC, timeout=3)
try:
self.plan_srv = rospy.ServiceProxy(self.configs.BASE.PLAN_TOPIC, GetPlan)
except rospy.ServiceException:
rospy.logerr(
"Timed out waiting for the planning service. \
Make sure build_map in script and \
use_map in roslauch are set to the same value"
)
self.start_state = build_pose_msg(0, 0, 0, self.BASE_FRAME)
self.tolerance = self.configs.BASE.PLAN_TOL
self._transform_listener = tf.TransformListener()
示例9: RequestDMP
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def RequestDMP(u,dt,k_gain,d_gain,num_basis_functions):
ndims = len(u[0])
k_gains = [k_gain]*ndims
d_gains = [d_gain]*ndims
ex = DMPTraj()
for i in range(len(u)):
pt = DMPPoint()
pt.positions = u[i] # always sends positions regardless of actual content
ex.points.append(pt)
ex.times.append(dt * i) # make sure times are reasonable
rospy.wait_for_service('learn_dmp_from_demo')
try:
lfd = rospy.ServiceProxy('learn_dmp_from_demo', LearnDMPFromDemo)
resp = lfd(ex, k_gains, d_gains, num_basis_functions)
except rospy.ServiceException, e:
print "Service call failed: %s"%e
示例10: __call__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def __call__(self, **kwargs):
rospy.loginfo('will call service {}'.format(self.service_name))
from tts.srv import Polly
rospy.wait_for_service(self.service_name)
polly = rospy.ServiceProxy(self.service_name, Polly)
return polly(polly_action='SynthesizeSpeech', **kwargs)
示例11: test_plain_text_to_wav_via_polly_node
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def test_plain_text_to_wav_via_polly_node(self):
rospy.wait_for_service('polly')
polly = rospy.ServiceProxy('polly', Polly)
test_text = 'Mary has a little lamb, little lamb, little lamb.'
res = polly(polly_action='SynthesizeSpeech', text=test_text)
self.assertIsNotNone(res)
self.assertTrue(type(res) is PollyResponse)
r = json.loads(res.result)
self.assertIn('Audio Type', r, 'result should contain audio type')
self.assertIn('Audio File', r, 'result should contain file path')
self.assertIn('Amazon Polly Response Metadata', r, 'result should contain metadata')
audio_type = r['Audio Type']
audio_file = r['Audio File']
md = r['Amazon Polly Response Metadata']
self.assertTrue("'HTTPStatusCode': 200," in md)
self.assertEqual('audio/ogg', audio_type)
self.assertTrue(audio_file.endswith('.ogg'))
import subprocess
o = subprocess.check_output(['file', audio_file], stderr=subprocess.STDOUT)
import re
m = re.search(r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
self.assertIsNotNone(m)
示例12: test_plain_text_via_synthesizer_node
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def test_plain_text_via_synthesizer_node(self):
rospy.wait_for_service('synthesizer')
speech_synthesizer = rospy.ServiceProxy('synthesizer', Synthesizer)
text = 'Mary has a little lamb, little lamb, little lamb.'
res = speech_synthesizer(text=text)
self.assertIsNotNone(res)
self.assertTrue(type(res) is SynthesizerResponse)
r = json.loads(res.result)
self.assertIn('Audio Type', r, 'result should contain audio type')
self.assertIn('Audio File', r, 'result should contain file path')
self.assertIn('Amazon Polly Response Metadata', r, 'result should contain metadata')
audio_type = r['Audio Type']
audio_file = r['Audio File']
md = r['Amazon Polly Response Metadata']
self.assertTrue("'HTTPStatusCode': 200," in md)
self.assertEqual('audio/ogg', audio_type)
self.assertTrue(audio_file.endswith('.ogg'))
import subprocess
o = subprocess.check_output(['file', audio_file], stderr=subprocess.STDOUT)
import re
m = re.search(r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
self.assertIsNotNone(m)
示例13: test_plain_text_to_mp3_via_polly_node
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def test_plain_text_to_mp3_via_polly_node(self):
rospy.wait_for_service('polly')
polly = rospy.ServiceProxy('polly', Polly)
test_text = 'Mary has a little lamb, little lamb, little lamb.'
res = polly(polly_action='SynthesizeSpeech', text=test_text, output_format='mp3')
self.assertIsNotNone(res)
self.assertTrue(type(res) is PollyResponse)
r = json.loads(res.result)
self.assertIn('Audio Type', r, 'result should contain audio type')
self.assertIn('Audio File', r, 'result should contain file path')
self.assertIn('Amazon Polly Response Metadata', r, 'result should contain metadata')
audio_type = r['Audio Type']
audio_file = r['Audio File']
md = r['Amazon Polly Response Metadata']
self.assertTrue("'HTTPStatusCode': 200," in md)
self.assertEqual('audio/mpeg', audio_type)
self.assertTrue(audio_file.endswith('.mp3'))
import subprocess
o = subprocess.check_output(['file', audio_file], stderr=subprocess.STDOUT)
import re
m = re.search(r'.*MPEG.*layer III.*', o, flags=re.MULTILINE)
self.assertIsNotNone(m)
示例14: test_simple_ssml_via_polly_node
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def test_simple_ssml_via_polly_node(self):
rospy.wait_for_service('polly')
polly = rospy.ServiceProxy('polly', Polly)
text = '<speak>Mary has a little lamb, little lamb, little lamb.</speak>'
res = polly(polly_action='SynthesizeSpeech', text=text, text_type='ssml')
self.assertIsNotNone(res)
self.assertTrue(type(res) is PollyResponse)
r = json.loads(res.result)
self.assertIn('Audio Type', r, 'result should contain audio type')
self.assertIn('Audio File', r, 'result should contain file path')
self.assertIn('Amazon Polly Response Metadata', r, 'result should contain metadata')
audio_type = r['Audio Type']
audio_file = r['Audio File']
md = r['Amazon Polly Response Metadata']
self.assertTrue("'HTTPStatusCode': 200," in md)
self.assertEqual('audio/ogg', audio_type)
self.assertTrue(audio_file.endswith('.ogg'))
import subprocess
o = subprocess.check_output(['file', audio_file], stderr=subprocess.STDOUT)
import re
m = re.search(r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
self.assertIsNotNone(m)
示例15: do_synthesize
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import wait_for_service [as 别名]
def do_synthesize(goal):
"""calls synthesizer service to do the job"""
rospy.wait_for_service('synthesizer')
synthesize = rospy.ServiceProxy('synthesizer', Synthesizer)
return synthesize(goal.text, goal.metadata)