class PubSubTest(unittest.TestCase): def setUp(self): self.startTime = time.time() self._manager = ExecutorManager() self._manager.start() self._exec = Executor() self._exec.connect() self._manager.add(self._exec) def tearDown(self): t = time.time() - self.startTime print("%s: %.3f" % (self.id(), t)) def _clb(self, msg): print("Received Message: {0}".format(msg)) def test_publish_string(self): self._pub = Publisher(self._exec, "/robot/test_string", "std_msgs/String") self._sub = Subscriber(self._exec, "/robot/test_string", "std_msgs/String", self._clb) start = time.time() stop = start while (stop - start) < 5: print(stop - start) self._pub.publish({"data": "Publisher {0}".format(self._pub.id)}) time.sleep(1) stop = time.time() self._pub.unregister() self._manager.stop()
def setUp(self): self.startTime = time.time() self._manager = ExecutorManager() self._manager.start() self._exec = Executor() self._exec.connect() self._manager.add(self._exec)
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 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 __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)
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)
class ActionClientTest(unittest.TestCase): def setUp(self): self.startTime = time.time() self._manager = ExecutorManager() self._manager.start() self._exec = Executor() 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 _on_result(self, data, status): print("Received Result: {0}".format(data)) self._count += 1 def _on_feedback(self, data, status): print("Received Feedback: {0}".format(data)) def _on_status(self, data): print("Received Status: {0}".format(data)) def test_fibonacci(self): server_name = "fibonacci" action_type = "demo_action_server/Fibonacci" self.ac = ActionClient(self._exec, server_name, action_type) self.goal = Goal({'order': 7}, on_result=self._on_result, on_feedback=self._on_feedback, on_status=self._on_status) self.ac.send_goal(self.goal) resF = False req = {"a": 1, "b": 2} while self._count == 0: time.sleep(0.2) self._manager.close_all() self._manager.stop() self._manager.join()
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()
class ServiceClientTest(unittest.TestCase): def setUp(self): self.startTime = time.time() self._manager = ExecutorManager() self._manager.start() self._exec = Executor() 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) # if self._count > 2: # self._resF = True # self._managed.close_all() # self._manager.stop() # self._manager.join() def test_add_two_ints(self): self._svc = ServiceClient(self._exec, "/add_two_ints", "demo_service/AddTwoInts") self._svc2 = ServiceClient(self._exec, "/add_two_ints", "demo_service/AddTwoInts") resF = False req = {"a": 1, "b": 2} self._svc.call(req, self._clb) self._svc2.call(req, self._clb) while self._count < 2: time.sleep(0.1) self._manager.close_all() self._manager.stop() self._manager.join()
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()
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)