def __init__ (self):
        self.time = time.time()
        self._incr = 1.0 / blenderapi.getfrequency()

        self._stat_jitter = Stats()
        self._last_time = 0.0

        logger.info('Morse configured in Fixed Simulation Step Mode with '
                    'time step of %f sec ( 1.0 /  %d)' %
                    (self._incr, blenderapi.getfrequency()))
Beispiel #2
0
    def __init__(self, relative_time):
        if relative_time:
            self.time = 0.0
            self._real_time_offset = time.time()
        else:
            self.time = time.time()
            self._real_time_offset = 0.0
        self._time_offset = copy.copy(self.time)
        self._incr = 1.0 / blenderapi.getfrequency()

        self._stat_jitter = Stats()
        self._last_time = 0.0

        logger.info('Morse configured in Fixed Simulation Step Mode with '
                    'time step of %f sec ( 1.0 /  %d)' %
                    (self._incr, blenderapi.getfrequency()))
Beispiel #3
0
    def synchronize(self):
        if not self.node_stream:
            logger.debug("not self.node_stream")
            return
        if not self.node_stream.connected:
            logger.debug("not self.node_stream.connected")
            return

        # Get the coordinates of local robots
        for obj in blenderapi.persistantstorage().robotDict.keys():
            #self.out_data[obj.name] = [obj.worldPosition.to_tuple()]
            euler_rotation = obj.worldOrientation.to_euler()
            self.out_data[obj.name] = [obj.worldPosition.to_tuple(), \
                [euler_rotation.x, euler_rotation.y, euler_rotation.z]]
        self.out_data['__time'] = [self.simulation_time.time, 1.0/ blenderapi.getfrequency(), self.simulation_time.real_time]
        # Send the encoded dictionary through a socket
        #  and receive a reply with any changes in the other nodes
        in_data = self._exchange_data(self.out_data)
        logger.debug("Received: %s" % in_data)

        if not in_data:
            return

        try:
            self.update_scene(in_data, blenderapi.scene())
        except Exception as e:
            logger.warning("error while processing incoming data: " + str(e))
Beispiel #4
0
    def synchronize(self):
        if not self.node_stream:
            logger.debug("not self.node_stream")
            return
        if not self.node_stream.connected:
            logger.debug("not self.node_stream.connected")
            return

        # Get the coordinates of local robots
        for obj in blenderapi.persistantstorage().robotDict.keys():
            #self.out_data[obj.name] = [obj.worldPosition.to_tuple()]
            euler_rotation = obj.worldOrientation.to_euler()
            self.out_data[obj.name] = [obj.worldPosition.to_tuple(), \
                [euler_rotation.x, euler_rotation.y, euler_rotation.z]]
        self.out_data['__time'] = [
            self.simulation_time.time, 1.0 / blenderapi.getfrequency(),
            self.simulation_time.real_time
        ]
        # Send the encoded dictionary through a socket
        #  and receive a reply with any changes in the other nodes
        in_data = self._exchange_data(self.out_data)
        logger.debug("Received: %s" % in_data)

        if not in_data:
            return

        try:
            self.update_scene(in_data, blenderapi.scene())
        except Exception as e:
            logger.warning("error while processing incoming data: " + str(e))
Beispiel #5
0
    def __init__ (self, relative_time):
        if relative_time:
            self.time = 0.0
            self._real_time_offset = time.time()
        else:
            self.time = time.time()
            self._real_time_offset = 0.0
        self._time_offset = copy.copy(self.time)
        self._incr = 1.0 / blenderapi.getfrequency()

        self._stat_jitter = Stats()
        self._last_time = 0.0

        logger.info('Morse configured in Fixed Simulation Step Mode with '
                    'time step of %f sec ( 1.0 /  %d)' %
                    (self._incr, blenderapi.getfrequency()))
Beispiel #6
0
    def __init__(self, args, kwargs):
        """ Initialize the socket connections """
        # Call the constructor of the parent class
        DatastreamManager.__init__(self, args, kwargs)
        self._time_initialized = False

        try:
            fom = kwargs["fom"]
            node_name = kwargs["name"]
            federation = kwargs["federation"]
            sync_point = kwargs.get("sync_point", None)
            sync_register = kwargs.get("sync_register", False)
            self.time_sync = kwargs.get("time_sync", False)
            timestep = kwargs.get("timestep", 1.0 / blenderapi.getfrequency())
            lookahead = kwargs.get("lookahead", timestep)
            self.stop_time = kwargs.get("stop_time", float("inf"))

            self.node = HLABaseNode(
                MorseBaseAmbassador,
                fom,
                node_name,
                federation,
                sync_point,
                sync_register,
                self.time_sync,
                timestep,
                lookahead,
            )
        except KeyError as error:
            logger.error(
                "One of [fom, name, federation] attribute is not configured: " "Cannot create HLADatastreamManager"
            )
            raise
Beispiel #7
0
    def __init__(self, args, kwargs):
        """ Initialize the socket connections """
        # Call the constructor of the parent class
        DatastreamManager.__init__(self, args, kwargs)
        self._time_initialized = False

        try:
            fom = kwargs["fom"]
            node_name = kwargs["name"]
            federation = kwargs["federation"]
            sync_point = kwargs.get("sync_point", None)
            sync_register = kwargs.get("sync_register", False)
            self.time_sync = kwargs.get("time_sync", False)
            timestep = kwargs.get("timestep", 1.0 / blenderapi.getfrequency())
            lookahead = kwargs.get("lookahead", timestep)
            self.stop_time = kwargs.get("stop_time", float("inf"))

            self.node = HLABaseNode(MorseBaseAmbassador, fom, node_name,
                                    federation, sync_point, sync_register,
                                    self.time_sync, timestep, lookahead)
        except KeyError as error:
            logger.error(
                "One of [fom, name, federation] attribute is not configured: "
                "Cannot create HLADatastreamManager")
            raise
Beispiel #8
0
    def __init__ (self, obj, parent=None):

        AbstractObject.__init__(self)

        # Fill in the data sent as parameters
        self.bge_object = obj
        self.robot_parent = parent

        self.level = self.bge_object.get("abstraction_level", "default")

        # Variable to indicate the activation status of the component
        self._active = True

        self.check_level()

        # Define the position of sensors with respect
        #  to their robot parent
        # TODO: implement this using morse.helpers.transformation
        if parent:
            self.relative_position = obj.getVectTo(parent.bge_object)

        # Create an instance of the 3d transformation class
        self.position_3d = morse.helpers.transformation.Transformation3d(obj)

        self.initialize_local_data()
        self.update_properties()

        # The actual frequency at which the action is called
        # The frequency of the game sensor specifies how many times
        # the action is skipped when the logic brick is executed.
        # e.g. game sensor frequency = 0 -> sensor runs at full logic rate
        sensors = blenderapi.getalwayssensors(obj)
        self._frequency = blenderapi.getfrequency()
        # New MORSE_LOGIC sensor, see AbstractComponent.morseable()
        morselogic = [s for s in sensors if s.name.startswith('MORSE_LOGIC')]
        if len(morselogic) == 1:
            if blenderapi.version() >= (2, 74, 5):
                self._frequency /= morselogic[0].skippedTicks + 1
            else:
                self._frequency /= morselogic[0].frequency + 1
        # Backward compatible (some actuators got special logic)
        elif len(sensors) == 1:
            if blenderapi.version() >= (2, 74, 5):
                self._frequency /= sensors[0].skippedTicks + 1
            else:
                self._frequency /= sensors[0].frequency + 1
        elif len(sensors) == 0:
            logger.warning("Can't get frequency for " + self.name() + \
                           " as the Game Logic sensor calling the action can't be found.")
        else:
            logger.warning(self.name() + " has too many Game Logic sensors to get " + \
                    "an unambiguous frequency for the action.")
Beispiel #9
0
    def __init__(self, obj, parent=None):

        AbstractObject.__init__(self)

        # Fill in the data sent as parameters
        self.bge_object = obj
        self.robot_parent = parent

        self.level = self.bge_object.get("abstraction_level", "default")

        # Variable to indicate the activation status of the component
        self._active = True

        self.check_level()

        # Define the position of sensors with respect
        #  to their robot parent
        # TODO: implement this using morse.helpers.transformation
        if parent:
            self.relative_position = obj.getVectTo(parent.bge_object)

        # Create an instance of the 3d transformation class
        self.position_3d = morse.helpers.transformation.Transformation3d(obj)

        self.initialize_local_data()
        self.update_properties()

        # The actual frequency at which the action is called
        # The frequency of the game sensor specifies how many times
        # the action is skipped when the logic brick is executed.
        # e.g. game sensor frequency = 0 -> sensor runs at full logic rate
        sensors = blenderapi.getalwayssensors(obj)
        self._frequency = blenderapi.getfrequency()
        # New MORSE_LOGIC sensor, see AbstractComponent.morseable()
        morselogic = [s for s in sensors if s.name.startswith('MORSE_LOGIC')]
        if len(morselogic) == 1:
            if blenderapi.version() >= (2, 74, 5):
                self._frequency /= morselogic[0].skippedTicks + 1
            else:
                self._frequency /= morselogic[0].frequency + 1
        # Backward compatible (some actuators got special logic)
        elif len(sensors) == 1:
            if blenderapi.version() >= (2, 74, 5):
                self._frequency /= sensors[0].skippedTicks + 1
            else:
                self._frequency /= sensors[0].frequency + 1
        elif len(sensors) == 0:
            logger.warning("Can't get frequency for " + self.name() + \
                           " as the Game Logic sensor calling the action can't be found.")
        else:
            logger.warning(self.name() + " has too many Game Logic sensors to get " + \
                    "an unambiguous frequency for the action.")
Beispiel #10
0
    def __init__ (self, obj, parent=None):

        AbstractObject.__init__(self)

        # Fill in the data sent as parameters
        self.bge_object = obj
        self.robot_parent = parent

        self.level = self.bge_object.get("abstraction_level", "default")

        # Variable to indicate the activation status of the component
        self._active = True

        self.check_level()

        # Define the position of sensors with respect
        #  to their robot parent
        # TODO: implement this using morse.helpers.transformation
        if parent:
            self.relative_position = obj.getVectTo(parent.bge_object)

        # Create an instance of the 3d transformation class
        self.position_3d = morse.helpers.transformation.Transformation3d(obj)

        self.initialize_local_data()
        self.update_properties()

        # The actual frequency at which the action is called
        # The frequency of the game sensor specifies how many times
        # the action is skipped when the logic brick is executed.
        # e.g. game sensor frequency = 0 -> sensor runs at full logic rate
        sensors = blenderapi.getalwayssensors(obj)
        self._frequency = blenderapi.getfrequency()

        if 'frequency' in self.bge_object:
            self._frequency = self.bge_object['frequency']
            self._last_call = None
            self._component_period = 1.0 / self._frequency
            self.__time = blenderapi.persistantstorage().time
Beispiel #11
0
    def __init__ (self, obj, parent=None):

        super(MorseObjectClass, self).__init__()

        # Fill in the data sent as parameters
        self.blender_obj = obj
        self.robot_parent = parent

        # Variable to indicate the activation status of the component
        self._active = True

        # Define the position of sensors with respect
        #  to their robot parent
        # TODO: implement this using morse.helpers.transformation
        if parent:
            self.relative_position = obj.getVectTo(parent.blender_obj)

        # Create an instance of the 3d transformation class
        self.position_3d = morse.helpers.transformation.Transformation3d(obj)

        self.initialize_local_data()
        self.update_properties()

        # The actual frequency at which the action is called
        # The frequency of the game sensor specifies how many times
        # the action is skipped when the logic brick is executed.
        # e.g. game sensor frequency = 0 -> sensor runs at full logic rate
        sensors = blenderapi.getalwayssensors(obj)
        self._frequency = blenderapi.getfrequency()
        if len(sensors) == 1:
            self._frequency /= sensors[0].frequency + 1
        elif len(sensors) == 0:
            logger.warning("Can't get frequency for " + self.name() + \
                           " as the Game Logic sensor calling the action can't be found.")
        else:
            logger.warning(self.name() + " has too many Game Logic sensors to get " + \
                    "an unambiguous frequency for the action.")
Beispiel #12
0
 def initialize(self):
     ROSPublisher.initialize(self)
     self._sim_time = 0.0
     # LogicTicRate default value: 60 Hz
     self._sim_step = 1.0 / blenderapi.getfrequency()
Beispiel #13
0
 def __init__(self):
     AbstractObject.__init__(self)
     self.time = blenderapi.persistantstorage().time
     self.ref_fps = blenderapi.getfrequency()
     self._alarm_time = None
Beispiel #14
0
 def initialize(self):
     ROSPublisher.initialize(self)
     self._sim_time = 0.0
     # LogicTicRate default value: 60 Hz
     self._sim_step = 1.0 / blenderapi.getfrequency()
Beispiel #15
0
def move(contr):
    """ Read the keys for specific combinations
        that will make the camera move in 3D space. """
    # get the object this script is attached to
    camera = contr.owner

    scene = blenderapi.scene()
    if not scene:
        # not ready, main reload(blenderapi)
        return

    # Do not move the camera if the current view is using another camera
    if camera != scene.active_camera:
        return

    # Do not move the camera if another object has set move_cameraFP
    for obj in keyboard_ctrl_objects:
        if not obj['move_cameraFP']:
            return

    # set camera position increment from the movement speed
    pos_inc = camera['Speed'] / blenderapi.getfrequency()

    # Get Blender keyboard sensor
    keyboard = contr.sensors['All_Keys']

    # Default movement
    move_translation = [0.0, 0.0, 0.0]

    keylist = keyboard.events
    for key in keylist:
        if key[1] == blenderapi.input_active():
            # Also add the corresponding key for an AZERTY keyboard
            if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY:
                move_translation[2] = -pos_inc
            elif key[0] == blenderapi.SKEY:
                move_translation[2] = pos_inc
            # Also add the corresponding key for an AZERTY keyboard
            elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY:
                move_translation[0] = -pos_inc
            elif key[0] == blenderapi.DKEY:
                move_translation[0] = pos_inc
            elif key[0] == blenderapi.RKEY:
                move_translation[1] = pos_inc
            elif key[0] == blenderapi.FKEY:
                move_translation[1] = -pos_inc
            else:
                move_translation[0] = 0
                move_translation[1] = 0
                move_translation[2] = 0

            # The second parameter of 'applyMovement' determines
            #  a movement with respect to the object's local
            #  coordinate system
            camera.applyMovement( move_translation, True )

        elif key[1] == blenderapi.input_just_activated():
            # Other actions activated with the keyboard
            # Reset camera to center
            if key[0] == blenderapi.F8KEY and keyboard.positive:
                reset_position(contr)
Beispiel #16
0
def move(contr):
    """ Read the keys for specific combinations
        that will make the camera move in 3D space. """
    # get the object this script is attached to
    camera = contr.owner

    scene = blenderapi.scene()
    if not scene:
        # not ready, main reload(blenderapi)
        return

    # Do not move the camera if the current view is using another camera
    if camera != scene.active_camera:
        return

    # Do not move the camera if another object has set move_cameraFP
    for obj in keyboard_ctrl_objects:
        if not obj['move_cameraFP']:
            return

    # set camera position increment from the movement speed
    pos_inc = camera['Speed'] / blenderapi.getfrequency()

    # Get Blender keyboard sensor
    keyboard = contr.sensors['All_Keys']

    # Default movement
    move_translation = [0.0, 0.0, 0.0]

    keylist = keyboard.events
    for key in keylist:
        if key[1] == blenderapi.input_active():
            # Also add the corresponding key for an AZERTY keyboard
            if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY:
                move_translation[2] = -pos_inc
            elif key[0] == blenderapi.SKEY:
                move_translation[2] = pos_inc
            # Also add the corresponding key for an AZERTY keyboard
            elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY:
                move_translation[0] = -pos_inc
            elif key[0] == blenderapi.DKEY:
                move_translation[0] = pos_inc
            elif key[0] == blenderapi.RKEY:
                move_translation[1] = pos_inc
            elif key[0] == blenderapi.FKEY:
                move_translation[1] = -pos_inc
            else:
                move_translation[0] = 0
                move_translation[1] = 0
                move_translation[2] = 0

            # The second parameter of 'applyMovement' determines
            #  a movement with respect to the object's local
            #  coordinate system
            camera.applyMovement(move_translation, True)

        elif key[1] == blenderapi.input_just_activated():
            # Other actions activated with the keyboard
            # Reset camera to center
            if key[0] == blenderapi.F8KEY and keyboard.positive:
                reset_position(contr)
Beispiel #17
0
 def __init__(self):
     AbstractObject.__init__(self)
     self.time = blenderapi.persistantstorage().time
     self.ref_fps = blenderapi.getfrequency()
     self._alarm_time = None