Пример #1
0
class AuthenticationTest(unittest.TestCase):
    def setUp(self):
        self.startTime = time.time()
        self._manager = ExecutorManager()
        self._manager.start()
        self._exec = Executor(ip="83.212.96.15", port=8127)
        self._exec.connect()
        self._manager.add(self._exec)
        self._count = 0

    def tearDown(self):
        t = time.time() - self.startTime
        print("%s: %.3f" % (self.id(), t))

    def _clb(self, status, data):
        print("Received Message: {0}".format(data))
        self._count += 1
        print(self._count)

    def _onautherror(self):
        print("AUTHENTICATION ERROR!")

    def test_auth_pass_secret(self):
        self._exec.authenticate("DDccaldGJdYNSuod")
        time.sleep(1)
        self._manager.kill()

    def test_auth_pass_secret_filepath(self):
        self._exec.authenticate(secret_from_file=SECRET_FILE,
                                onerror=self._onautherror)
        time.sleep(1)
        self._manager.kill()
Пример #2
0
class ActionClientTest(unittest.TestCase):
    def setUp(self):
        self.startTime = time.time()
        self._manager = ExecutorManager()
        self._manager.start()
        self._exec = Executor(ip="83.212.96.15", port="8115")
        self._exec.connect()
        self._manager.add(self._exec)
        self._exec.authenticate("44UCmQiX3mZtxC7y", onerror=self._onautherror)
        self._goal_reached = False

    def tearDown(self):
        t = time.time() - self.startTime
        print("%s: %.3f" % (self.id(), t))
        self._manager.kill()

    def _onautherror(self):
        print("AUTHENTICATION ERROR!")

    def _on_result(self, data, status, header):
        print("Received Result: ")
        pprint(data)
        pprint(status)
        pprint(header)
        self._goal_reached = True

    def _on_feedback(self, data, status, header):
        print("Received Feedback: ")
        pprint(data)
        pprint(status)
        pprint(header)

    def _on_status(self, data, header):
        print("Received Status: ")
        pprint(data)
        pprint(header)

    def test_move_base(self):
        server_name = "robot1/move_base"
        action_type = "move_base_msgs/MoveBase"
        req = {
            "target_pose": {
                "frame_id": "world",
                "pose": {
                    "position": {
                        "x": 0.0
                    },
                    "orientation": {
                        "w": 1.0
                    }
                }
            }
        }
        self.ac = ActionClient(self._exec, server_name, action_type)
        self.goal = Goal(req,
                         on_result=self._on_result,
                         on_feedback=self._on_feedback,
                         on_status=self._on_status)
        self.ac.send_goal(self.goal)

        while not self._goal_reached:
            time.sleep(0.2)
        self._manager.close_all()
        self._manager.stop()
        self._manager.join()
Пример #3
0
class Bridge(Base):
    """Abstract Bridge class"""
    def __init__(self, ip, port, secret=None, secret_fpath=None):
        self._ip = ip
        self._port = port
        self._secret = secret
        self._secret_fpath = secret_fpath
        signal.signal(signal.SIGINT, lambda *x: self.stop())
        self._manager = ExecutorManager()
        self._exec = Executor(ip=ip, port=port)
        self._exec.connect()
        self._manager.add(self._exec)
        self._rosapi = ROSApi(executor=self._exec)
        rospy.init_node(self.__class__.__name__, anonymous=True)
        self._resp = None
        self._flag = False

    @property
    def rosApi(self):
        """Returns an instance of the ROSApi"""
        return self._rosapi

    def start_executor(self):
        """Start executor"""
        self._manager.start()

    def auth(self):
        """Perform authentication to remote ros env through rosbridge"""
        self._exec.authenticate(self._secret, self._secret_fpath)

    def stop(self):
        """Stop executor"""
        logger.debug("Shutting down proxy")
        self._manager.kill()
        rospy.signal_shutdown("Interrupted by User")

    def terminated(self):
        """Check whether or not all websocket connections are closed"""
        for ws in self._manager.websockets.itervalues():
            if not ws.terminated:
                return False
        return True

    def run_forever(self):
        """Keep main thread running, via iterative sleep operations"""
        self.run()
        while True:
            if self.terminated():
                break
            time.sleep(3)

    def run(self):
        try:
            self.start_executor()
            self._start_remote_endpoint()
            self._start_local_endpoint()
        except KeyboardInterrupt:
            self.stop()

    def _start_local_endpoint(self):
        raise NotImplementedError("")

    def _start_remote_endpoint(self):
        raise NotImplementedError("")
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import time
from rosbridge_pyclient import Executor, ExecutorManager
import os

DIRPATH = os.path.dirname(os.path.realpath(__file__))

manager = ExecutorManager()


def onautherror():
    print("AUTHENTICATION ERROR!")
    manager.kill()


if __name__ == '__main__':
    manager.start()
    executor = Executor(ip="83.212.96.15", port=8127)
    executor.connect()
    manager.add(executor)
    executor.authenticate("DDccaldGJdYNSuod", onerror=onautherror)