当前位置: 首页>>代码示例>>Python>>正文


Python rospy.ServiceProxy方法代码示例

本文整理汇总了Python中rospy.ServiceProxy方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.ServiceProxy方法的具体用法?Python rospy.ServiceProxy怎么用?Python rospy.ServiceProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rospy的用法示例。


在下文中一共展示了rospy.ServiceProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fk_service_client

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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 
开发者ID:RethinkRobotics,项目名称:intera_sdk,代码行数:24,代码来源:fk_service_client.py

示例2: __init__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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.") 
开发者ID:NiryoRobotics,项目名称:niryo_one_ros,代码行数:24,代码来源:tool_ros_command_interface.py

示例3: _GetDetection

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [as 别名]
def _GetDetection(self, obj_name):
        """
        Calls the service to get a detection of a particular object.
        @param obj_name The name of the object to detect
        @return A 4x4 transformation matrix describing the pose of the object
        in world frame, None if the object is not detected
        """
        #Call detection service for a particular object
        detect_vncc = rospy.ServiceProxy(self.service_namespace+'/get_vncc_detections',
                                         vncc_msgs.srv.GetDetections)
        
        detect_resp = detect_vncc(object_name=obj_name)
        
        if detect_resp.ok == False:
            return None
            
        #Assumes one instance of object
        result = self._MsgToPose(detect_resp.detections[0])
        if (self.detection_frame is not None and self.world_frame is not None):
            result = self._LocalToWorld(result)
        result[:3,:3] = numpy.eye(3)
        return result 
开发者ID:personalrobotics,项目名称:prpy,代码行数:24,代码来源:vncc.py

示例4: get_object_relative_pose

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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 
开发者ID:NiryoRobotics,项目名称:niryo_one_ros,代码行数:26,代码来源:exemple_client_service.py

示例5: spawn_model

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [as 别名]
def spawn_model(model_name):
    """ Spawns a model in front of the RGBD camera.

        Args: None

        Returns: None
    """
    initial_pose = Pose()
    initial_pose.position.x = 0
    initial_pose.position.y = 1
    initial_pose.position.z = 1

    # Spawn the new model #
    model_path = rospkg.RosPack().get_path('sensor_stick')+'/models/'
    model_xml = ''

    with open (model_path + model_name + '/model.sdf', 'r') as xml_file:
        model_xml = xml_file.read().replace('\n', '')

    spawn_model_prox = rospy.ServiceProxy('gazebo/spawn_sdf_model', SpawnModel)
    spawn_model_prox('training_model', model_xml, '', initial_pose, 'world') 
开发者ID:udacity,项目名称:RoboND-Perception-Exercises,代码行数:23,代码来源:training_helper.py

示例6: execute

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:23,代码来源:script.py

示例7: __init__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [as 别名]
def __init__(self):

        rospy.init_node("mav_control_node")
        rospy.Subscriber("/mavros/local_position/pose", PoseStamped, self.pose_callback)
        rospy.Subscriber("/mavros/rc/in", RCIn, self.rc_callback)

        self.cmd_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=1)
        self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=1)
        self.rc_override = rospy.Publisher("/mavros/rc/override", OverrideRCIn, queue_size=1)

        # mode 0 = STABILIZE
        # mode 4 = GUIDED
        # mode 9 = LAND
        self.mode_service = rospy.ServiceProxy('/mavros/set_mode', SetMode)
        self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
        self.takeoff_service = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL)

        self.rc = RCIn()
        self.pose = Pose()
        self.timestamp = rospy.Time() 
开发者ID:thien94,项目名称:vision_to_mavros,代码行数:22,代码来源:mavros_control1.py

示例8: call_service

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [as 别名]
def call_service(self, req):
        """Calling the appropriate service depending on the given request type.
        Requests have to inherit from 'HMMRepRequestAbstractclass'.

        :param req: The request class instance for the request you want to make

        :return: The qsr_type and resulting data tuple. The data is in the data type produced by the response.
        """
        assert(issubclass(req.__class__, RepRequestAbstractclass))
        s = rospy.ServiceProxy(self.services[req.__class__],QSRProbRep)
        try:
            s.wait_for_service(timeout=10.)
            res = s(QSRProbRepRequest(data=json.dumps(req.kwargs)))
        except (rospy.ROSException, rospy.ROSInterruptException, rospy.ServiceException) as e:
            rospy.logerr(e)
            return None
        try:
            data = json.loads(res.data)
        except ValueError:
            data = str(res.data)
        return data 
开发者ID:strands-project,项目名称:strands_qsr_lib,代码行数:23,代码来源:ros_client.py

示例9: __init__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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() 
开发者ID:facebookresearch,项目名称:pyrobot,代码行数:22,代码来源:base_control_utils.py

示例10: RequestDMP

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:23,代码来源:dmp_utils.py

示例11: __call__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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) 
开发者ID:aws-robotics,项目名称:tts-ros1,代码行数:8,代码来源:synthesizer.py

示例12: test_plain_text_to_wav_via_polly_node

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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) 
开发者ID:aws-robotics,项目名称:tts-ros1,代码行数:28,代码来源:test_integration.py

示例13: test_plain_text_via_synthesizer_node

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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) 
开发者ID:aws-robotics,项目名称:tts-ros1,代码行数:28,代码来源:test_integration.py

示例14: test_plain_text_to_mp3_via_polly_node

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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) 
开发者ID:aws-robotics,项目名称:tts-ros1,代码行数:28,代码来源:test_integration.py

示例15: test_simple_ssml_via_polly_node

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceProxy [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) 
开发者ID:aws-robotics,项目名称:tts-ros1,代码行数:28,代码来源:test_integration.py


注:本文中的rospy.ServiceProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。