def testPyrosROSCtx(): # start ros system , before PyrosROS process and Client otherwise Client assumes there is problem ( discovery timeout ) # we might need to load pyros_setup here... try: import pyros_utils except ImportError: # TODO : find a proper way to log from a test like here... try: #_logger.warning("loading pyros_setup and configuring your ROS environment") import pyros_setup # This will load the pyros_setup configuration from the environment pyros_setup.configurable_import().configure().activate() import pyros_utils except ImportError: # This is expected when testing pyros by itself raise nose.SkipTest( "pyros_utils could not be imported, and trying to import pyros_setup for dynamic ros setup failed." ) master, roscore_proc = pyros_utils.get_master( spawn=True) # we start the master if needed assert master.is_online() with pyros_ctx(node_impl=pyros_interfaces_ros.PyrosROS) as ctx: assert isinstance(ctx.client, PyrosClient) # TODO : assert the context manager does his job ( HOW ? ) if roscore_proc is not None: roscore_proc.terminate() while roscore_proc.is_alive(): time.sleep(0.2) # waiting for roscore to die
def pyros(): # IMPORTANT : Without pyros_setup configuration activated, # the develop packages are set in sys.path AFTER the site-packages and dist-packages # This is because of incompatibilities between ROS and python ways of handling PYTHONPATH. # It is usually not a problem, unless : # - you are working in a devel space with catkin_pip and expect to use a editable package from there # - you have the same package installed somewhere else in the PYTHONPATH # And in that case it might end up being *before* the source dir in sys.path # # => Without pyros_setup, the installed version will be preferred # This is the python (and tools) way of working, since PYTHONPATH purpose is to override file-based setup, # like editable packages. # # => With pyros_setup, the devel version will be preferred # This is the ROS way of working, since PYTHONPATH order determine the order of folder when looking for a package. # # Both will work fine in most cases, but one might want to keep this corner case in mind... # TODO : get rid of this. See https://github.com/asmodehn/catkin_pip/issues/106 print("sys.path before pyros_setup {pyros_setup.__file__} :\n{sys.path}". format(**globals())) # We need to pass the proper workspace here pyros_setup.configurable_import().configure({ 'WORKSPACES': [devel_space() ], # This should be the same as pytest devel_space fixture 'DISTRO': pyros_setup.DETECTED_DISTRO, }).activate()
def testPyrosROSCtx(): # start ros system , before PyrosROS process and Client otherwise Client assumes there is problem ( discovery timeout ) # we might need to load pyros_setup here... try: import pyros_utils except ImportError: # TODO : find a proper way to log from a test like here... try : #_logger.warning("loading pyros_setup and configuring your ROS environment") import pyros_setup # This will load the pyros_setup configuration from the environment pyros_setup.configurable_import().configure().activate() import pyros_utils except ImportError: # This is expected when testing pyros by itself raise nose.SkipTest("pyros_utils could not be imported, and trying to import pyros_setup for dynamic ros setup failed.") master, roscore_proc = pyros_utils.get_master(spawn=True) # we start the master if needed assert master.is_online() with pyros_ctx(node_impl=pyros_interfaces_ros.PyrosROS) as ctx: assert isinstance(ctx.client, PyrosClient) # TODO : assert the context manager does his job ( HOW ? ) if roscore_proc is not None: roscore_proc.terminate() while roscore_proc.is_alive(): time.sleep(0.2) # waiting for roscore to die
def test_rospy_imported_config(setup, cmdopt): rospy = None try: import rospy # this will fail (see setup()) except ImportError: # Proper Way of handling Import Error with pyros-setup # Careful this might mean the system installed one if you re not working in virtualenv import pyros_setup # no need to change package settings here, but we still need to call the configuration step for the import... pyros_setup = pyros_setup.configurable_import() # Loading instance configuration from default file pyros_setup.configure() if cmdopt: # dynamically replacing the configured distro we got from default config # with the one specified interactively for this test, if present. pyros_setup.configure({"DISTRO": cmdopt}) # We need to allow this to fail if the instance configuration is not setup properly (no option), # this way the user can debug and fix his configuration. pyros_setup.activate() # you do the setup as expected by ROS try: # we now have access to all imported content (directly or through redirection _PyrosSetup class) assert hasattr(pyros_setup, "configurable_import") except ImportError: assert False import rospy assert rospy is not None
def test_rospy_imported_config(setup, cmdopt): rospy = None try: import rospy # this will fail (see setup()) except ImportError: # Proper Way of handling Import Error with pyros-setup # Careful this might mean the system installed one if you re not working in virtualenv import pyros_setup # no need to change package settings here, but we still need to call the configuration step for the import... setup = pyros_setup.configurable_import() # Loading instance configuration from default file setup.configure() if cmdopt: # dynamically replacing the configured distro we got from default config # with the one specified interactively for this test, if present. setup.configure({'DISTRO': cmdopt}) # We need to allow this to fail if the instance configuration is not setup properly (no option), # this way the user can debug and fix his configuration. setup.activate() # you do the setup as expected by ROS try: # we now have access to all imported content (directly or through redirection _PyrosSetup class) assert hasattr(pyros_setup, 'configurable_import') except ImportError: assert False import rospy assert rospy is not None
if __name__ == '__main__': __name__ = 'optional_fields' __package__ = 'pyros_schemas.ros' import pyros_schemas.ros try: # To be able to run doctest directly we avoid relative import import genpy import rospy except ImportError: # Because we need to access Ros message types here (from ROS env or from virtualenv, or from somewhere else) import pyros_setup # We rely on default configuration to point us to the proper distro pyros_setup.configurable_import().configure().activate() import genpy import rospy # From here we can pick this up from ROS if missing in python env. import inspect import functools import marshmallow.utils from .basic_fields import RosNested, RosList class RosOptAsList(RosList): """Any ros field, optional in deserialized (python dict) form. In Ros is it represented by a list of that field type, and can be empty. :param kwargs: The same keyword arguments that :class:`List` receives. required is set to True by default.
try: import rospy import roslaunch import rosgraph import rosnode except ImportError: # if ROS environment is not setup, we emulate it. print("!!! Original import failed. Attempting Pyros-Setup...") import pyros_setup pyros_setup.configurable_import().configure('mysetup.cfg').activate() # this will use mysetup.cfg from pyros-setup instance folder import rospy import roslaunch import rosgraph import rosnode print("rospy from: " + rospy.__file__) print("roslaunch from: " + roslaunch.__file__) print("rosgraph from: " + rosgraph.__file__) print("rosnode from: " + rosnode.__file__)
#!/usr/bin/env python import math from pyparsing import * from PyQt5.QtCore import pyqtSignal, QObject try: import rospy from geometry_msgs.msg import Pose, Point, Quaternion except ImportError: import pyros_setup pyros_setup.configurable_import().configure('myself.cfg').activate() import rospy from geometry_msgs.msg import Pose, Point, Quaternion from pilz_robot_programming.robot import Robot """ Moving and robot program related functions are located here. Robot code is in format : PTP X111.111 Y111.111 Z111.111 qX qY qZ qW VSCALE RELATIVE N1 PTP X120.21 Y7.213 Z0.0123 qx1.00230 qy0.00293 qz1 qw0 RELATIVE N2 START_SQ N342 SERVO 1 S160 N32 SET_FRAME prbt_base N2 PTP J1:123.23 J2:12.221 J3:-231.321 J4:12.030 J5:95.33 J6:0.23 RELATIVE N12 CIRC X0 Y0 Z0 iX0 iY0 iZ0 Where: PTP = the movement type of the PTP, LIN CIRC