Ejemplo n.º 1
0
    def on_act_debug(self):
        if not self.ros_client.is_connected:
            QMessageBox.critical(self, "错误", '尚未连接到ROS')
            return
        if self.host == '127.0.0.1' or self.host == 'localhost':
            self.action_debug_client = self.ros_client
            cmd = 'rosrun action action_debuger'
        else:
            cmd = 'roslaunch start start_action_debug_robot.launch'
            try:
                if self.action_debug_client is None:
                    print("run action_debug_client at 127.0.0.1:9090")
                    self.action_debug_client = Ros('127.0.0.1', 9090)
                    self.action_debug_client.run()
                elif not self.action_debug_client.is_connected:
                    print("connecting action debug client")
                    self.action_debug_client.connect()
            except Exception as e:
                QMessageBox.critical(self, "错误", '无法连接到本地调试器 %s' % str(e))
                return

        act_service = Service(self.action_debug_client, '/debug/action/run',
                              'common/AddAngles')
        act_service.advertise(self.on_recv_action)
        os.popen(cmd)
Ejemplo n.º 2
0
def run_add_two_ints_service():
    ros_client = Ros('127.0.0.1', 9090)
    service = Service(ros_client, '/test_server', 'rospy_tutorials/AddTwoInts')

    def dispose_server():
        service.unadvertise()
        service.ros.call_later(1, service.ros.terminate)

    def add_two_ints(request, response):
        response['sum'] = request['a'] + request['b']
        if response['sum'] == 42:
            service.ros.call_later(2, dispose_server)

        return True

    def check_sum(result):
        assert (result['sum'] == 42)

    def invoke_service():
        client = Service(ros_client, '/test_server',
                         'rospy_tutorials/AddTwoInts')
        client.call(ServiceRequest({'a': 2, 'b': 40}), check_sum, print)

    service.advertise(add_two_ints)
    ros_client.call_later(1, invoke_service)
    ros_client.run_event_loop()
Ejemplo n.º 3
0
def run_empty_service():
    ros_client = Ros('127.0.0.1', 9090)
    ros_client.run()

    service = Service(ros_client, '/test_empty_service', 'std_srvs/Empty')
    service.advertise(lambda req, resp: True)
    time.sleep(1)

    client = Service(ros_client, '/test_empty_service', 'std_srvs/Empty')
    client.call(ServiceRequest())

    service.unadvertise()
    time.sleep(2)
    service.ros.terminate()
Ejemplo n.º 4
0
def run_add_two_ints_service():
    ros_client = Ros('127.0.0.1', 9090)
    ros_client.run()

    def add_two_ints(request, response):
        response['sum'] = request['a'] + request['b']

        return False

    service_name = '/test_sum_service'
    service_type = 'rospy_tutorials/AddTwoInts'
    service = Service(ros_client, service_name, service_type)
    service.advertise(add_two_ints)
    time.sleep(1)

    client = Service(ros_client, service_name, service_type)
    result = client.call(ServiceRequest({'a': 2, 'b': 40}))
    assert (result['sum'] == 42)

    service.unadvertise()
    time.sleep(2)
    service.ros.terminate()