def delayed_import_auto(distro=None, base_path=None): import os distro = distro or 'indigo' # default basepath working if pyros-setup is directly cloned in your workspace # This file think it is in devel/lib/python2.7/dist-packages/pyros_setup for some reason... # NOTE : maybe the default here is a bad idea, making it simpler than it should be for the user... base_path = base_path or os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..') try: import rospy # early except to prevent unintentional workaround in all modules here from pyros.rosinterface.topic import TopicBack from pyros.rosinterface.service import ServiceBack from pyros.rosinterface.param import ParamBack from pyros.rosinterface.ros_interface import RosInterface from pyros.rosinterface.pyros_ros import PyrosROS except ImportError: import pyros_setup pyros_setup.delayed_import_auto(distro, base_path) from pyros.rosinterface.topic import TopicBack # apparently this makes it more robust for celeros import from beat process... from pyros.rosinterface.service import ServiceBack from pyros.rosinterface.param import ParamBack from pyros.rosinterface.ros_interface import RosInterface from pyros.rosinterface.pyros_ros import PyrosROS # we return a relay of imported names, accessible the same way a direct import would be. return _PyrosSetup( TopicBack, ServiceBack, ParamBack, RosInterface, PyrosROS ) # not supported by import from celeros beat process... improvement needee in pyros setup ?
def run(self): """ Running in a zmp.Node process, providing zmp.services """ # Environment should be setup here if needed ( we re in another process ). sys.modules["pyros_setup"] = pyros_setup.delayed_import_auto( distro='indigo', base_path=self.base_path) # master has to be running here or we just wait for ever m, _ = pyros_setup.get_master(spawn=False) while not m.is_online(): time.sleep(0.5) # we initialize the node here, in subprocess, passing ros parameters. # disabling signal to avoid overriding callers behavior rospy.init_node(self.name, argv=self.str_argv, disable_signals=True) rospy.loginfo('PyrosROS {name} node started with args : {argv}'.format( name=self.name, argv=self.str_argv)) # TODO : install shutdown hook to shutdown if detected try: # this spins with regular frequency super(PyrosROS, self).run( ) # we override parent run to add one argument to ros interface except KeyboardInterrupt: rospy.logwarn('PyrosROS node stopped by keyboard interrupt')
import unittest from nose.tools import assert_equal, assert_true, nottest import time try: import rospy import rosgraph import roslaunch import std_msgs.msg as std_msgs except ImportError as exc: # this will except only if you didnt setup ROS environment first import os import pyros_setup import sys # pass here the path to your workspace as argument sys.modules["pyros_setup"] = pyros_setup.delayed_import_auto( base_path=os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..')) import rospy import rosgraph import roslaunch import std_msgs.msg as std_msgs launch = None roscore_process = None # ############################################################################ # # ### The aim of this file is to test strange behavior on core ROS modules ### # # ############################################################################ # # setup / teardown for EACH test to avoid side effects in same process
import os import time # Unit test import try: import rostest import rospy import roslaunch from std_msgs.msg import String, Empty from std_srvs.srv import Trigger, TriggerResponse from pyros_setup import rostest_nose except ImportError as exc: import os import sys import pyros_setup pyros_setup = pyros_setup.delayed_import_auto(base_path=os.path.join(os.path.dirname(__file__), '..', '..', '..', '..')) import rostest import rospy import roslaunch from std_msgs.msg import String, Empty from std_srvs.srv import Trigger, TriggerResponse from pyros_setup import rostest_nose from celeros import celeros_app from celeros import rostasks launch = None worker_process = None # TODO : maybe we need a config for tests specifically ( instead of using the default ) app = "celeros.app" # OR celeros.celeros_app OR celeros_app ( to match code )??