def handle_vision_message(self,data):
        #print "handle_visiion_message"
        #TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name
            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            if old_block_handle.is_undefined():
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
            else:
                old_block_type_node = get_predicate(self._atomspace, "material",
                                                    Atom(old_block_handle, self._atomspace), 1)
                old_block_type = self._atomspace.get_name(old_block_type_node.h)
                if old_block_type == block_material:
                    continue
                elif block.blockid == 0:
                    blocknode, updated_eval_links = Atom(Handle(-1), self._atomspace), []
                else:
                    blocknode, updated_eval_links = self._build_block_nodes(block,
                                                                            map_handle)

                
                #TODO: not sure if we should add disappeared predicate here,
                #It looks reasonable but make the code more messy..
                disappeared_link = add_predicate(self._atomspace, "disappeared", Atom(old_block_handle, self._atomspace))
                updated_eval_links.append(disappeared_link)
            self._space_server.add_map_info(blocknode.h, map_handle, False, False,
                                            block.ROStimestamp,
                                            block.x, block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h,block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link.h,block.MCtimestamp, "MC")
            #print blocknode
            #print updated_eval_links

        #TODO: The code below stores the number of blocks of each type seen in the current field of view into the atomspace.  It is commented out as it should probably not store this until the code to erase old values is also added otherwise this data just piles up as new links from the same root node and it becomes a jumbled mess.
        #print "\nBlock material summary:  saw %s kinds of blocks" % len(material_dict)
        """
示例#2
0
 def handle_vision_message(self, data):
     print "handle_visiion_message"
     #TODO: In Minecraft the up/down direction is y coord
     # but we should swap y and z in ros node, not here..
     for block in data.blocks:
         swap_y_and_z(block)
     map_handle, cur_map = self._get_map()
     for block in data.blocks:
         old_block_handle = cur_map.get_block((block.x, block.y, block.z))
         updated_eval_links = []
         if old_block_handle.is_undefined():
             blocknode, updated_eval_links = self._build_block_nodes(
                 block, map_handle)
         else:
             old_block_type_node = get_predicate(
                 self._atomspace, "material",
                 Atom(old_block_handle, self._atomspace), 1)
             old_block_type = self._atomspace.get_name(
                 old_block_type_node.h)
             if old_block_type == str(block.blockid):
                 continue
             elif block.blockid == 0:
                 blocknode, updated_eval_links = Atom(
                     Handle(-1), self._atomspace), []
             else:
                 blocknode, updated_eval_links = self._build_block_nodes(
                     block, map_handle)
             #TODO: not sure if we should add disappeared predicate here,
             #It looks reasonable but make the code more messy..
             disappeared_link = add_predicate(
                 self._atomspace, "disappeared",
                 Atom(old_block_handle, self._atomspace))
             updated_eval_links.append(disappeared_link)
         self._space_server.add_map_info(blocknode.h, map_handle, False,
                                         False, block.ROStimestamp, block.x,
                                         block.y, block.z)
         if old_block_handle.is_undefined():
             self._time_server.add_time_info(blocknode.h,
                                             block.ROStimestamp, "ROS")
             self._time_server.add_time_info(blocknode.h, block.MCtimestamp,
                                             "MC")
         for link in updated_eval_links:
             self._time_server.add_time_info(link.h, block.ROStimestamp,
                                             "ROS")
             self._time_server.add_time_info(link.h, block.MCtimestamp,
                                             "MC")
         #print blocknode
         #print updated_eval_links
     print "handle_vision_message end"
 def handle_vision_message(self,data):
     print "handle_visiion_message"
     #TODO: In Minecraft the up/down direction is y coord
     # but we should swap y and z in ros node, not here..
     for block in data.blocks:
         swap_y_and_z(block)
     map_handle, cur_map = self._get_map()
     for block in data.blocks:
         old_block_handle = cur_map.get_block((block.x, block.y, block.z))
         updated_eval_links = []
         if old_block_handle.is_undefined():
             blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
         else:
             old_block_type_node = get_predicate(self._atomspace, "material",
                                                 Atom(old_block_handle, self._atomspace), 1)
             old_block_type = self._atomspace.get_name(old_block_type_node.h)
             if old_block_type == str(block.blockid):
                 continue
             elif block.blockid == 0:
                 blocknode, updated_eval_links = Atom(Handle(-1), self._atomspace), []
             else:
                 blocknode, updated_eval_links = self._build_block_nodes(block,
                                                                         map_handle)
             #TODO: not sure if we should add disappeared predicate here,
             #It looks reasonable but make the code more messy..
             disappeared_link = add_predicate(self._atomspace, "disappeared", Atom(old_block_handle, self._atomspace))
             updated_eval_links.append(disappeared_link)
         self._space_server.add_map_info(blocknode.h, map_handle, False, False,
                                         block.ROStimestamp,
                                         block.x, block.y, block.z)
         if old_block_handle.is_undefined():
             self._time_server.add_time_info(blocknode.h, block.ROStimestamp, "ROS")
             self._time_server.add_time_info(blocknode.h, block.MCtimestamp, "MC")
         for link in updated_eval_links:
             self._time_server.add_time_info(link.h,block.ROStimestamp, "ROS")
             self._time_server.add_time_info(link.h,block.MCtimestamp, "MC")
         #print blocknode
         #print updated_eval_links
     print "handle_vision_message end"
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle == None:
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.

                blocknode.av["sti"] = 200
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace, "material", old_block_handle, 1)
                old_block_type = old_block_type_node.name
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = old_block_handle.av["sti"]
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    old_block_handle.av["sti"] = cur_sti
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)

                disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(
                blocknode, map_handle, False, False, block.ROStimestamp, block.x, block.y, block.z
            )
            if old_block_handle == None:
                self._time_server.add_time_info(blocknode, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link, block.MCtimestamp, "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """
示例#5
0
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid,
                                              block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle.is_undefined():
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(
                    block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.
                self._atomspace.set_av(blocknode.h, 200)
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace,
                                                    "material",
                                                    old_block_handle, 1)
                old_block_type = self._atomspace.get_name(
                    old_block_type_node.h)
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = self._atomspace.get_av(old_block_handle)['sti']
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    self._atomspace.set_av(old_block_handle, cur_sti)
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace,
                                                     "disappeared",
                                                     old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(
                        block, map_handle)

                disappeared_link = add_predicate(self._atomspace,
                                                 "disappeared",
                                                 old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(blocknode.h, map_handle, False,
                                            False, block.ROStimestamp, block.x,
                                            block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h,
                                                block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp,
                                                "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h, block.ROStimestamp,
                                                "ROS")
                self._time_server.add_time_info(link.h, block.MCtimestamp,
                                                "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """