description: The names of the input_keys to be written to file. type: list of str output_keys: [] outcomes: - succeeded - aborted {% endblock meta %} {% from "Utils.tpl.py" import import_module, from_import, render_init_callbacks, render_execute_callbacks, render_callbacks, render_input_keys, render_output_keys, render_transitions, render_remapping %} {% extends "State.tpl.py" %} {% block imports %} {{ super() }} {{ import_module(defined_headers, 'csv') }} {% endblock imports %} {% block class_defs %} {{ super() }} {% if 'class_WriteCSVFileState' not in defined_headers %} class WriteCSVFileState(smach.State): """ This state formats input keys specified by the 'data_keys' input key and writes them to a CSV file specified by the 'file' input key. """ def __init__(self, delimiter=',', input_keys = ['file', 'data_keys'], output_keys = [], callbacks=None): smach.State.__init__(self, outcomes=['succeeded', 'aborted'], input_keys=input_keys, output_keys=output_keys) # Save delimiter self._delimiter = delimiter
- msg_output: description: A possible output key for the topic data. type: str outcomes: - succeeded - aborted {% endblock meta %} {% extends "WaitForMsgState.tpl.py" %} {% from "Utils.tpl.py" import import_module, render_init_callbacks, render_execute_callbacks %} {% block imports %} {{ super() }} {{ import_module(defined_headers, 'rostopic') }} {{ import_module(defined_headers, 'rospy') }} {{ import_module(defined_headers, 'roslib') }} {% endblock imports %} {% block class_defs %} {{ super() }} {% if 'class_ReadTopicState' not in defined_headers %} class ReadTopicState(smach.State): def __init__(self, input_keys=['topic'], output_keys=['output'], callbacks = None): smach.State.__init__(self, input_keys=input_keys, output_keys=output_keys, outcomes=['succeeded', 'aborted']) {{ render_init_callbacks() }} def execute(self, userdata):
{% from "Utils.tpl.py" import import_module, render_transitions, render_remapping, render_input_keys, render_output_keys, render_def_lambda_callbacks, render_init_callbacks, render_execute_callbacks, render_callbacks, render_userdata %} {% block imports %} {{ import_module(defined_headers, 'random') }} {% endblock imports %} {% block defs %} {% if 'foo_animals_cb' not in defined_headers %} # Define normal callback for 'animals' output key @smach.cb_interface(input_keys=['animals'], output_keys=['animals'], outcomes=['succeeded']) def foo_animals_cb(userdata): userdata['animals'].append('turtles') return 'succeeded' {% do defined_headers.append('foo_animals_cb') %}{% endif %} {% if 'foo_numbers_cb' not in defined_headers %} # Define normal callback for 'numbers' output key @smach.cb_interface(input_keys=['numbers'], output_keys=['numbers'], outcomes=['succeeded']) def foo_numbers_cb(userdata): userdata['numbers'].append(userdata['numbers'][-1]+1) return 'succeeded' {% do defined_headers.append('foo_numbers_cb') %}{% endif %} {% endblock defs %} {% block class_defs %} {% if 'class_Foo' not in defined_headers %} class Foo(smach.State):
The file, files or file specification for deletion. A deletion loop is called on glob.glob(userdata.file). type: str output_keys: [] outcomes: - succeeded - aborted {% endblock meta %} {% from "Utils.tpl.py" import import_module, render_init_callbacks, render_execute_callbacks %} {% extends "State.tpl.py" %} {% block imports %} {{ super() }} {{ import_module(defined_headers, 'rospy') }} {{ import_module(defined_headers, 'os') }} {{ import_module(defined_headers, 'glob') }} {% endblock imports %} {% block class_defs %} {{ super() }} {% if 'class_DeleteFileState' not in defined_headers %} class DeleteFileState(smach.State): """ This state deletes files. """ def __init__(self, input_keys = ['file'], output_keys = [], callbacks=None): smach.State.__init__(self, outcomes=['succeeded', 'aborted'], input_keys=input_keys, output_keys=output_keys) {{ render_init_callbacks() }}
PublishMsgState. language: Python framework: SMACH type: None tags: [core] includes: [] extends: [] variables: [] input_keys: [] output_keys: [] {% endblock meta %} {% from "Utils.tpl.py" import import_module, from_import %} {% block imports %} {{ import_module(defined_headers, 'roslib') }} {{ import_module(defined_headers, 'rosgraph') }} {% endblock imports %} {% block class_defs %} {% if 'class_MsgPublisherObserver' not in defined_headers %} class MsgPublisherObserver(object): """ Subscribes to a topic and maintains dicts of messages & publishers that are updated with the topic subscription callback. """ def __init__(self, sub_topic='/tf'): # Get a reference to the ROS master self._master = rosgraph.Master('msg_publisher_observer') # Save sub_topic
includes: [] extends: [] variables: [] input_keys: [] output_keys: [] {% endblock meta %} # # Based on the original code described here: # http://wiki.ros.org/executive_smach/AdditionalStateTypes # https://github.com/felix-kolbe/uashh-rvl-ros-pkg/blob/master/uashh_smach/src/uashh_smach/util.py # {% from "Utils.tpl.py" import import_module %} {% block imports %} {{ import_module(defined_headers, 'tf2_ros') }} {% endblock imports %} {% block class_defs %} {% if 'class_TF2ListenerSingleton' not in defined_headers %} class TF2ListenerSingleton(object): """To avoid running multiple transform listeners, this singleton class provides one tf2 buffer and listener that are initialised and retrieved via class methods init() and get(). """ _buffer = None _listener = None @classmethod def init(cls): """Ignores multiple calls."""
https://github.com/francisc0garcia/sensor_board/blob/master/src/classes/bags/recorder.py language: Python framework: SMACH type: None tags: [core] includes: [] extends: [] variables: [] input_keys: [] output_keys: [] {% endblock meta %} {% from "Utils.tpl.py" import import_module, from_import %} {% block imports %} {{ import_module(defined_headers, 'rospy') }} {{ import_module(defined_headers, 'rosbag') }} {{ import_module(defined_headers, 'roslib') }} {{ import_module(defined_headers, 'rosgraph') }} {{ import_module(defined_headers, 'threading') }} {% if 'import_Queue' not in defined_headers %} try: from queue import Queue except ImportError: from Queue import Queue {% do defined_headers.append('import_Queue') %} {% endif %} {% endblock imports %} {% block class_defs %} {% if 'class_ROSBagAPIThreadRecorder' not in defined_headers %}
See: https://answers.ros.org/question/10714/start-and-stop-rosbag-within-a-python-script/ language: Python framework: SMACH type: None tags: [core] includes: [] extends: [] variables: [] input_keys: [] output_keys: [] {% endblock meta %} {% from "Utils.tpl.py" import import_module, from_import %} {% block imports %} {{ import_module(defined_headers, 'rospy') }} {{ import_module(defined_headers, 'os') }} {{ import_module(defined_headers, 'subprocess') }} {# }{{ import_module(defined_headers, 'psutil') }} #} {{ import_module(defined_headers, 'signal') }} {{ import_module(defined_headers, 'time') }} {% endblock imports %} {% block class_defs %} {% if 'class_ROSBagCLIProcessRecorder' not in defined_headers %} class ROSBagCLIProcessRecorder(object): """A rosbag recorder class that uses subprocess calls to the rosbag CLI (command-line interface) recording tool in order to circumvent threading and Python GIL (global interpreter lock) issues. """ def __init__(self):
Userdata keys that the message callback needs to write to. type: list of str input_keys: [] output_keys: [] outcomes: - succeeded - aborted {% endblock meta %} {% from "Utils.tpl.py" import import_module, render_transitions, render_remapping, render_output_keys %} {% extends "State.tpl.py" %} {% block imports %} {{ super() }} {{ import_module(defined_headers, 'threading') }} {% endblock imports %} {% block class_defs %} {{ super() }} {% if 'class_WaitForMsgState' not in defined_headers %} class WaitForMsgState(smach.State): """This class acts as a generic message listener with blocking, timeout, latch and flexible usage. It is meant to be extended with a case specific class that initializes this one appropriately and contains the msg_cb (or overrides execute if really needed). Its waitForMsg method implements the core functionality: waiting for the message, returning the message itself or None on timeout. Its execute method wraps the waitForMsg and returns succeeded or aborted, depending on the returned
input_keys: [] output_keys: [] {% endblock meta %} {% from "Utils.tpl.py" import import_module, render_outcomes, render_userdata %} {% set defined_headers = [] %} {% set local_vars = [] %} {% block base_header %} #!/usr/bin/env python {{ base_header }} {% endblock base_header %} {% block imports %} {{ import_module(defined_headers, 'roslib') }}{% if manifest is defined %}; roslib.load_manifest('{{ manifest }}'){% endif %} {{ import_module(defined_headers, 'rospy') }} {{ import_module(defined_headers, 'smach') }} {{ import_module(defined_headers, 'smach_ros') }} {{ imports }} {% endblock imports %} {% block defs %} {{ defs }} {% endblock defs %} {% block class_defs %} {{ class_defs }} {% endblock class_defs %} {% block cb_defs %}
- time: description: The length of time to sleep for in seconds. type: float input_keys: [] output_keys: [] outcomes: - succeeded {% endblock meta %} {% from "Utils.tpl.py" import import_module, render_transitions %} {% extends "State.tpl.py" %} {% block imports %} {{ super() }} {{ import_module(defined_headers, 'rospy') }} {% endblock imports %} {% block class_defs %} {{ super() }} {% if 'class_SleepState' not in defined_headers %} class SleepState(smach.State): def __init__(self, time, input_keys = [], output_keys = [], callbacks = [], outcomes=['succeeded']): smach.State.__init__(self, input_keys=input_keys, output_keys=output_keys, outcomes=outcomes) self._time = time def execute(self, userdata): rospy.sleep(self._time)
input_keys: [] output_keys: [] {% endblock meta %} {% from "Utils.tpl.py" import import_module, render_outcomes, render_userdata %} {% set defined_headers = [] %} {% set local_vars = [] %} {% block base_header %} #!/usr/bin/env python {{ base_header }} {% endblock base_header %} {% block imports %} {{ import_module(defined_headers, 'smach') }} {{ imports }} {% endblock imports %} {% block defs %} {{ defs }} {% endblock defs %} {% block class_defs %} {{ class_defs }} {% endblock class_defs %} {% block cb_defs %} {{ cb_defs }} {% endblock cb_defs %}
#!/usr/bin/env python import osimport sysimport subprocessfrom importlib import import_module if __name__ == '__main__': # We need to set the PYTHONPATH environment variable # because otherwise subprocesses on Travis CI won't # include this directory in the pythonpath root_dir = os.path.dirname(os.path.realpath(__file__)) os.environ['PYTHONPATH'] = root_dir + os.pathsep + os.environ.get('PYTHONPATH', '') # Test using django.test.runner.DiscoverRunner os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' # We need to use subprocess.call instead of django's execute_from_command_line # because we can only setup django's settings once, and it's bad # practice to change them at runtime subprocess.call(['django-admin', 'test', '--nomigrations']) subprocess.call(['django-admin', 'test', '-n']) # Test using django_nose.NoseTestSuiteRunner os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.nose_settings' for module in ('nose', 'django_nose',): try: import_module(module) except ImportError: print("Testing failed: could not import {0}, try pip installing it".format(module)) sys.exit(1) # Add pdb flag as this is only supported by nose subprocess.call(['django-admin', 'test', 'tests.myapp.nose_tests', '--nomigrations', '--pdb']) subprocess.call(['django-admin', 'test', 'tests.myapp.nose_tests', '-n', '--pdb'])