Ejemplo n.º 1
0
    def configure_stream_manager(self, stream_manager, **kwargs):
        if stream_manager in MORSE_DATASTREAM_MODULE:
            stream_manager_classpath = MORSE_DATASTREAM_MODULE[stream_manager]
        else:
            stream_manager_classpath = stream_manager

        Configuration.link_stream_manager_config(stream_manager_classpath, kwargs)
Ejemplo n.º 2
0
    def configure_stream_manager(self, stream_manager, **kwargs):
        if stream_manager in MORSE_DATASTREAM_MODULE:
            stream_manager_classpath = MORSE_DATASTREAM_MODULE[stream_manager]
        else:
            stream_manager_classpath = stream_manager

        Configuration.link_stream_manager_config(stream_manager_classpath,
                                                 kwargs)
Ejemplo n.º 3
0
    def _configure_default_interface(self, component, interface):
        for child in component.children:
            if child.is_morseable():
                if not Configuration.has_datastream_configuration(child, interface) and \
                   child.is_exportable():
                    child.add_stream(interface)

                if not Configuration.has_service_configuration(child, interface):
                    child.add_service(interface)

                self._configure_default_interface(child, interface)
Ejemplo n.º 4
0
    def _configure_default_interface(self, component, interface):
        for child in component.children:
            if child.is_morseable():
                if not Configuration.has_datastream_configuration(child, interface) and \
                   child.is_exportable():
                    child.add_stream(interface)

                if not Configuration.has_service_configuration(
                        child, interface):
                    child.add_service(interface)

                self._configure_default_interface(child, interface)
Ejemplo n.º 5
0
    def _handle_default_interface(self):
        """
        Handle the semantic of default interface.

        For each robot, for each of this children, if the child has no
        specific configuration for its 'default_interface', the function
        adds it automatically.
        """
        for component in AbstractComponent.components:
            if isinstance(component, Robot) and component.default_interface:
                for child in component.children:
                    if child.is_morseable():
                        if not Configuration.has_datastream_configuration(child, component.default_interface):
                            child.add_stream(component.default_interface)
                        if not Configuration.has_service_configuration(child, component.default_interface):
                            child.add_service(component.default_interface)
Ejemplo n.º 6
0
    def _handle_default_interface(self):
        """
        Handle the semantic of default interface.

        For each robot, for each of this children, if the child has no
        specific configuration for its 'default_interface', the function
        adds it automatically.
        """
        for component in AbstractComponent.components:
            if isinstance(component, Robot) and component.default_interface:
                for child in component.children:
                    if child.is_morseable():
                        if not Configuration.has_datastream_configuration(
                                child, component.default_interface):
                            child.add_stream(component.default_interface)
                        if not Configuration.has_service_configuration(
                                child, component.default_interface):
                            child.add_service(component.default_interface)
Ejemplo n.º 7
0
                def renametree(cmpt, fqn):
                    if not cmpt.basename:
                        return
#                        raise SyntaxError("You need to assign the component of type %s to a variable" %
#                                        cmpt)
                    list_name = [cmpt._bpy_object.name for cmpt in AbstractComponent.components if cmpt != component ]
                    fqn.append(cmpt.basename)
                    new_name = '.'.join(fqn)

                    i = 1
                    while new_name in list_name:
                        fqn.pop()
                        fqn.append("%s_%03d" % (cmpt.basename, i))
                        new_name = '.'.join(fqn)
                        i += 1

                    Configuration.update_name(cmpt.name, new_name)
                    cmpt._bpy_object.name = new_name
                    for child in cmpt.children:
                        renametree(child, fqn[:])
Ejemplo n.º 8
0
                def renametree(cmpt, fqn):
                    if not cmpt.basename:
                        return
#                        raise SyntaxError("You need to assign the component of type %s to a variable" %
#                                        cmpt)
                    list_name = [
                        cmpt._bpy_object.name
                        for cmpt in AbstractComponent.components
                        if cmpt != component
                    ]
                    fqn.append(cmpt.basename)
                    new_name = '.'.join(fqn)

                    i = 1
                    while new_name in list_name:
                        fqn.pop()
                        fqn.append("%s_%03d" % (cmpt.basename, i))
                        new_name = '.'.join(fqn)
                        i += 1

                    Configuration.update_name(cmpt.name, new_name)
                    cmpt._bpy_object.name = new_name
                    for child in cmpt.children:
                        renametree(child, fqn[:])
Ejemplo n.º 9
0
    def create(self, name=None):
        """ Generate the scene configuration and insert necessary objects

        Should always be called at the very end of the Builder script. It will
        finalise the building process and write the configuration files.
        """
        # Invoke special methods of component that must take place *after* renaming
        for component in AbstractComponent.components:
            if hasattr(component, "after_renaming"):
                component.after_renaming()

        # Compute node name
        if name is None:
            try:
                self._node_name = os.environ["MORSE_NODE"]
            except KeyError:
                self._node_name = os.uname()[1]
        else:
            self._node_name = name

        # Create a new scene for each camera, with specific render resolution
        # Must be done at the end of the builder script, after renaming
        # and before adding 'Scene_Script_Holder'
        self._cfg_camera_scene()

        # Create a new scene for the MORSE_LOGIC (Scene_Script_Holder, CameraFP)
        scene = bpymorse.set_active_scene('S.MORSE_LOGIC')
        scene.game_settings.physics_engine = 'BULLET'
        scene.game_settings.physics_step_sub = self._physics_step_sub
        # set simulation view resolution (4:3)
        scene.render.resolution_x = 800
        scene.render.resolution_y = 600

        # define 'Scene_Script_Holder' as the blender object of Enrivonment
        if not 'Scene_Script_Holder' in bpymorse.get_objects():
            # Add the necessary objects
            base = Component('props', 'basics')

        # Set Scene_Script_Holder as core Environment object
        self.set_blender_object(bpymorse.get_object('Scene_Script_Holder'))
        # Copy properties (for UTM modifier configuration)
        _properties = bpymorse.get_properties(bpymorse.get_object('MORSE.Properties'))
        self.properties(**_properties)

        # Write the configuration of the datastreams, and node configuration
        if not self.multinode_distribution:
            robot_list = None
        else:
            robot_list = self.multinode_distribution.get(self._node_name, [])
            if not isinstance(robot_list, list):
                robot_list = [robot_list]
        Configuration.write_config(robot_list)
        self._write_multinode(self._node_name)

        # Change the Screen material
        if self._display_camera:
            self._set_scren_mat()

        # Write the name of the 'environment file'
        self.properties(environment_file = str(self._environment_file))

        # Default time management
        if 'time_management' not in self._bpy_object.game.properties.keys():
            self.properties(time_management = TimeStrategies.BestEffort)

        if self.fastmode:
            # SINGLETEXTURE support has been removed between 2.69 and
            # 2.70. Handle properly the case where it is not defined
            # anymore.
            try:
                self.set_material_mode('SINGLETEXTURE')
            except TypeError:
                self.set_material_mode('MULTITEXTURE')
            self.set_viewport("WIREFRAME")
        elif not self.is_material_mode_custom:
            # make sure OpenGL shading language shaders (GLSL) is the
            # material mode to use for rendering
            self.set_material_mode('GLSL')

        # Set the unit system to use for button display (in edit mode) to metric
        bpymorse.get_context_scene().unit_settings.system = 'METRIC'
        # Select the type of Framing to Extend,
        # Show the entire viewport in the display window,
        # viewing more horizontally or vertically.
        bpymorse.get_context_scene().game_settings.frame_type = 'EXTEND'
        # Start player with a visible mouse cursor
        bpymorse.get_context_scene().game_settings.show_mouse = True

        # Set the position of the camera
        camera_fp = bpymorse.get_object('CameraFP')
        camera_fp.location = self._camera_location
        camera_fp.rotation_euler = self._camera_rotation
        camera_fp.game.properties['Speed'].value = self._camera_speed
        camera_fp.data.clip_start = self._camera_clip_start
        camera_fp.data.clip_end   = self._camera_clip_end
        camera_fp.data.lens = 20 # set focal length in mm
        # Make CameraFP the active camera
        bpymorse.deselect_all()
        camera_fp.select = True
        bpymorse.get_context_scene().objects.active = camera_fp
        # Set default camera
        bpymorse.get_context_scene().camera = camera_fp
        # Set viewport to Camera
        bpymorse.set_viewport_perspective()

        hud_text = bpymorse.get_object('Keys_text')
        hud_text.scale.y = 0.027 # to fit the HUD_plane

        self._created = True
        # in case we are in edit mode, do not exit on error with CLI
        sys.excepthook = sys_excepthook # Standard Python excepthook
Ejemplo n.º 10
0
    def create(self, name=None):
        """ Generate the scene configuration and insert necessary objects

        Should always be called at the very end of the Builder script. It will
        finalise the building process and write the configuration files.
        """
        # Invoke special methods of component that must take place *after* renaming
        for component in AbstractComponent.components:
            if hasattr(component, "after_renaming"):
                component.after_renaming()

        # Compute node name
        if name is None:
            try:
                self._node_name = os.environ["MORSE_NODE"]
            except KeyError:
                import socket
                self._node_name = socket.gethostname()
        else:
            self._node_name = name

        # Check time properties
        scene = bpymorse.get_context_scene()
        base_frequency = scene.game_settings.fps
        max_frequency_requested = Configuration.max_frequency()
        time_scale = self.property_value('time_scale')
        if self.auto_tune_time:
            self.use_vsync('OFF')
            # notyet :D
            # self.use_internal_syncer()
            if max_frequency_requested > base_frequency:
                self.simulator_frequency(max_frequency_requested)
        else:
            # Just report bad looking configuration
            if max_frequency_requested > base_frequency:
                logger.warning(
                    "You are requesting a component at %d Hz, but the "
                    "simulator main loop is running only at %d Hz. Try "
                    "to raise the frequency of the simulation using "
                    "env.simulator_frequency(%d)" %
                    (max_frequency_requested, base_frequency,
                     max_frequency_requested))
            if time_scale:
                real_fps_requested = max_frequency_requested * time_scale
                if real_fps_requested > 1000.0:
                    logger.warning(
                        "You are requesting a component at %d Hz, with "
                        " time acceleration factor of %f, leading to a "
                        " real frequency of %d Hz. It will probably hard "
                        " to reach this value with Morse, so consider to "
                        " reduce frequency of component or speed factor " %
                        (max_frequency_requested, time_scale,
                         real_fps_requested))

        # Create a new scene for each camera, with specific render resolution
        # Must be done at the end of the builder script, after renaming
        # and before adding 'Scene_Script_Holder'
        self._cfg_camera_scene()

        # Create a new scene for the MORSE_LOGIC (Scene_Script_Holder, CameraFP)
        scene = bpymorse.set_active_scene('S.MORSE_LOGIC')
        scene.game_settings.physics_engine = 'BULLET'
        scene.game_settings.physics_step_sub = self._physics_step_sub
        # set simulation view resolution (4:3)
        scene.render.resolution_x = 800
        scene.render.resolution_y = 600

        # define 'Scene_Script_Holder' as the blender object of Enrivonment
        if not 'Scene_Script_Holder' in bpymorse.get_objects():
            # Add the necessary objects
            base = Component('props', 'basics')

        # Set Scene_Script_Holder as core Environment object
        self.set_blender_object(bpymorse.get_object('Scene_Script_Holder'))
        # Copy properties (for UTM modifier configuration)
        _properties = bpymorse.get_properties(
            bpymorse.get_object('MORSE.Properties'))
        self.properties(**_properties)

        # Write the configuration of the datastreams, and node configuration
        if not self.multinode_distribution:
            robot_list = None
        else:
            robot_list = self.multinode_distribution.get(self._node_name, [])
            if not isinstance(robot_list, list):
                robot_list = [robot_list]
        Configuration.write_config(robot_list)
        self._write_multinode(self._node_name)

        # Change the Screen material
        if self._display_camera:
            self._set_scren_mat()

        # Write the name of the 'environment file'
        self.properties(environment_file=str(self._environment_file))

        # Default time management
        if 'time_management' not in self._bpy_object.game.properties.keys():
            self.properties(time_management=TimeStrategies.BestEffort)

        if self.fastmode:
            # SINGLETEXTURE support has been removed between 2.69 and
            # 2.70. Handle properly the case where it is not defined
            # anymore.
            try:
                self.set_material_mode('SINGLETEXTURE')
            except TypeError:
                self.set_material_mode('MULTITEXTURE')
            self.set_viewport("WIREFRAME")
        elif not self.is_material_mode_custom:
            # make sure OpenGL shading language shaders (GLSL) is the
            # material mode to use for rendering
            self.set_material_mode('GLSL')

        # Set the unit system to use for button display (in edit mode) to metric
        bpymorse.get_context_scene().unit_settings.system = 'METRIC'
        # Select the type of Framing to Extend,
        # Show the entire viewport in the display window,
        # viewing more horizontally or vertically.
        bpymorse.get_context_scene().game_settings.frame_type = 'EXTEND'
        # Start player with a visible mouse cursor
        bpymorse.get_context_scene().game_settings.show_mouse = True

        # Set the position of the camera
        camera_fp = bpymorse.get_object('CameraFP')
        camera_fp.location = self._camera_location
        camera_fp.rotation_euler = self._camera_rotation
        camera_fp.game.properties['Speed'].value = self._camera_speed
        camera_fp.data.clip_start = self._camera_clip_start
        camera_fp.data.clip_end = self._camera_clip_end
        camera_fp.data.lens = self._focal_length  # set focal length in mm
        # Make CameraFP the active camera
        bpymorse.deselect_all()
        camera_fp.select = True
        bpymorse.get_context_scene().objects.active = camera_fp
        # Set default camera
        bpymorse.get_context_scene().camera = camera_fp
        # Set viewport to Camera
        bpymorse.set_viewport_perspective()

        hud_text = bpymorse.get_object('Keys_text')
        hud_text.scale.y = 0.027  # to fit the HUD_plane

        # Create a cube to compute the dt between two frames
        _dt_name = '__morse_dt_analyser'
        cube = Cube(_dt_name)
        cube.scale = (0.01, 0.01, 0.01)
        cube.location = [0.0, 0.0, -5000.0]
        cube_obj = bpymorse.get_object(_dt_name)
        cube_obj.game.physics_type = 'DYNAMIC'
        cube_obj.hide_render = True
        cube_obj.game.lock_location_z = True

        self._created = True
        # in case we are in edit mode, do not exit on error with CLI
        sys.excepthook = sys.__excepthook__  # Standard Python excepthook
Ejemplo n.º 11
0
    def create(self, name=None):
        """ Generate the scene configuration and insert necessary objects

        Should always be called at the very end of the Builder script. It will
        finalise the building process and write the configuration files.
        """
        # Invoke special methods of component that must take place *after* renaming
        for component in AbstractComponent.components:
            if hasattr(component, "after_renaming"):
                component.after_renaming()

        # Compute node name
        if name is None:
            try:
                self._node_name = os.environ["MORSE_NODE"]
            except KeyError:
                self._node_name = os.uname()[1]
        else:
            self._node_name = name

        # Create a new scene for each camera, with specific render resolution
        # Must be done at the end of the builder script, after renaming
        # and before adding 'Scene_Script_Holder'
        self._cfg_camera_scene()

        # Create a new scene for the MORSE_LOGIC (Scene_Script_Holder, CameraFP)
        scene = bpymorse.set_active_scene('S.MORSE_LOGIC')
        scene.game_settings.physics_engine = 'BULLET'
        scene.game_settings.physics_step_sub = self._physics_step_sub
        # set simulation view resolution (4:3)
        scene.render.resolution_x = 800
        scene.render.resolution_y = 600

        # define 'Scene_Script_Holder' as the blender object of Enrivonment
        if not 'Scene_Script_Holder' in bpymorse.get_objects():
            # Add the necessary objects
            base = Component('props', 'basics')

        # Set Scene_Script_Holder as core Environment object
        self.set_blender_object(bpymorse.get_object('Scene_Script_Holder'))
        # Copy properties (for UTM modifier configuration)
        _properties = bpymorse.get_properties(
            bpymorse.get_object('MORSE.Properties'))
        self.properties(**_properties)

        # Write the configuration of the datastreams, and node configuration
        if not self.multinode_distribution:
            robot_list = None
        else:
            robot_list = self.multinode_distribution.get(self._node_name, [])
            if not isinstance(robot_list, list):
                robot_list = [robot_list]
        Configuration.write_config(robot_list)
        self._write_multinode(self._node_name)

        # Change the Screen material
        if self._display_camera:
            self._set_scren_mat()

        # Write the name of the 'environment file'
        self.properties(environment_file=str(self._environment_file))

        # Default time management
        if 'time_management' not in self._bpy_object.game.properties.keys():
            self.properties(time_management=TimeStrategies.BestEffort)

        if self.fastmode:
            # SINGLETEXTURE support has been removed between 2.69 and
            # 2.70. Handle properly the case where it is not defined
            # anymore.
            try:
                self.set_material_mode('SINGLETEXTURE')
            except TypeError:
                self.set_material_mode('MULTITEXTURE')
            self.set_viewport("WIREFRAME")
        elif not self.is_material_mode_custom:
            # make sure OpenGL shading language shaders (GLSL) is the
            # material mode to use for rendering
            self.set_material_mode('GLSL')

        # Set the unit system to use for button display (in edit mode) to metric
        bpymorse.get_context_scene().unit_settings.system = 'METRIC'
        # Select the type of Framing to Extend,
        # Show the entire viewport in the display window,
        # viewing more horizontally or vertically.
        bpymorse.get_context_scene().game_settings.frame_type = 'EXTEND'
        # Start player with a visible mouse cursor
        bpymorse.get_context_scene().game_settings.show_mouse = True

        # Set the position of the camera
        camera_fp = bpymorse.get_object('CameraFP')
        camera_fp.location = self._camera_location
        camera_fp.rotation_euler = self._camera_rotation
        camera_fp.game.properties['Speed'].value = self._camera_speed
        camera_fp.data.clip_start = self._camera_clip_start
        camera_fp.data.clip_end = self._camera_clip_end
        camera_fp.data.lens = self._focal_length  # set focal length in mm
        # Make CameraFP the active camera
        bpymorse.deselect_all()
        camera_fp.select = True
        bpymorse.get_context_scene().objects.active = camera_fp
        # Set default camera
        bpymorse.get_context_scene().camera = camera_fp
        # Set viewport to Camera
        bpymorse.set_viewport_perspective()

        hud_text = bpymorse.get_object('Keys_text')
        hud_text.scale.y = 0.027  # to fit the HUD_plane

        self._created = True
        # in case we are in edit mode, do not exit on error with CLI
        sys.excepthook = sys.__excepthook__  # Standard Python excepthook
Ejemplo n.º 12
0
    def create(self, name=None):
        """ Generate the scene configuration and insert necessary objects

        Should always be called at the very end of the Builder script. It will
        finalise the building process and write the configuration files.
        """
        # Invoke special methods of component that must take place *after* renaming
        for component in AbstractComponent.components:
            if hasattr(component, "after_renaming"):
                component.after_renaming()

        # Compute node name
        if name is None:
            try:
                self._node_name = os.environ["MORSE_NODE"]
            except KeyError:
                import socket
                self._node_name = socket.gethostname()
        else:
            self._node_name = name

        # Check time properties
        scene = bpymorse.get_context_scene()
        base_frequency = scene.game_settings.fps
        max_frequency_requested = Configuration.max_frequency()
        time_scale = self.property_value('time_scale')
        if self.auto_tune_time:
            self.use_vsync('OFF')
            # notyet :D
            # self.use_internal_syncer()
            if max_frequency_requested > base_frequency:
                self.simulator_frequency(max_frequency_requested)
        else:
            # Just report bad looking configuration
            if max_frequency_requested > base_frequency:
                logger.warning("You are requesting a component at %d Hz, but the "
                               "simulator main loop is running only at %d Hz. Try "
                               "to raise the frequency of the simulation using "
                               "env.simulator_frequency(%d)" %
                               (max_frequency_requested, base_frequency, max_frequency_requested))
            if time_scale:
                real_fps_requested = max_frequency_requested * time_scale
                if real_fps_requested > 1000.0:
                    logger.warning("You are requesting a component at %d Hz, with "
                                   " time acceleration factor of %f, leading to a "
                                   " real frequency of %d Hz. It will probably hard "
                                   " to reach this value with Morse, so consider to "
                                   " reduce frequency of component or speed factor " %
                                   (max_frequency_requested, time_scale, real_fps_requested))

        # Create a new scene for each camera, with specific render resolution
        # Must be done at the end of the builder script, after renaming
        # and before adding 'Scene_Script_Holder'
        self._cfg_camera_scene()

        # Create a new scene for the MORSE_LOGIC (Scene_Script_Holder, CameraFP)
        scene = bpymorse.set_active_scene('S.MORSE_LOGIC')
        scene.game_settings.physics_engine = 'BULLET'
        scene.game_settings.physics_step_sub = self._physics_step_sub
        # set simulation view resolution (4:3)
        scene.render.resolution_x = 800
        scene.render.resolution_y = 600

        # define 'Scene_Script_Holder' as the blender object of Enrivonment
        if not 'Scene_Script_Holder' in bpymorse.get_objects():
            # Add the necessary objects
            base = Component('props', 'basics')

        # Set Scene_Script_Holder as core Environment object
        self.set_blender_object(bpymorse.get_object('Scene_Script_Holder'))
        # Copy properties (for UTM modifier configuration)
        _properties = bpymorse.get_properties(bpymorse.get_object('MORSE.Properties'))
        self.properties(**_properties)

        # Write the configuration of the datastreams, and node configuration
        if not self.multinode_distribution:
            robot_list = None
        else:
            robot_list = self.multinode_distribution.get(self._node_name, [])
            if not isinstance(robot_list, list):
                robot_list = [robot_list]
        Configuration.write_config(robot_list)
        self._write_multinode(self._node_name)

        # Change the Screen material
        if self._display_camera:
            self._set_scren_mat()

        # Write the name of the 'environment file'
        self.properties(environment_file = str(self._environment_file))

        # Default time management
        if 'time_management' not in self._bpy_object.game.properties.keys():
            self.properties(time_management = TimeStrategies.BestEffort)

        if self.fastmode:
            # SINGLETEXTURE support has been removed between 2.69 and
            # 2.70. Handle properly the case where it is not defined
            # anymore.
            try:
                self.set_material_mode('SINGLETEXTURE')
            except TypeError:
                self.set_material_mode('MULTITEXTURE')
            self.set_viewport("WIREFRAME")
        elif not self.is_material_mode_custom:
            # make sure OpenGL shading language shaders (GLSL) is the
            # material mode to use for rendering
            self.set_material_mode('GLSL')

        # Set the unit system to use for button display (in edit mode) to metric
        bpymorse.get_context_scene().unit_settings.system = 'METRIC'
        # Select the type of Framing to Extend,
        # Show the entire viewport in the display window,
        # viewing more horizontally or vertically.
        bpymorse.get_context_scene().game_settings.frame_type = 'EXTEND'
        # Start player with a visible mouse cursor
        bpymorse.get_context_scene().game_settings.show_mouse = True

        # Set the position of the camera
        camera_fp = bpymorse.get_object('CameraFP')
        camera_fp.location = self._camera_location
        camera_fp.rotation_euler = self._camera_rotation
        camera_fp.game.properties['Speed'].value = self._camera_speed
        camera_fp.data.clip_start = self._camera_clip_start
        camera_fp.data.clip_end   = self._camera_clip_end
        camera_fp.data.lens = self._focal_length # set focal length in mm
        # Make CameraFP the active camera
        bpymorse.deselect_all()
        camera_fp.select = True
        bpymorse.get_context_scene().objects.active = camera_fp
        # Set default camera
        bpymorse.get_context_scene().camera = camera_fp
        # Set viewport to Camera
        bpymorse.set_viewport_perspective()

        hud_text = bpymorse.get_object('Keys_text')
        hud_text.scale.y = 0.027 # to fit the HUD_plane

        # Create a cube to compute the dt between two frames
        _dt_name = '__morse_dt_analyser'
        cube = Cube(_dt_name)
        cube.scale = (0.01, 0.01, 0.01)
        cube.location = [0.0, 0.0, -5000.0]
        cube_obj = bpymorse.get_object(_dt_name)
        cube_obj.game.physics_type = 'DYNAMIC'
        cube_obj.hide_render = True
        cube_obj.game.lock_location_z = True

        self._created = True
        # in case we are in edit mode, do not exit on error with CLI
        sys.excepthook = sys.__excepthook__ # Standard Python excepthook