def createDescription(self):
     # =======Params=========
     self.addParam("Pose", Element("skiros:TransformationPose"),
                   ParamTypes.Required)
     self.addParam("Pose2", Element("skiros:TransformationPose"),
                   ParamTypes.Required)
     self.addParam("Axis", float, ParamTypes.Required)
Пример #2
0
    def createDescription(self):
        #=======Params=========
        self.addParam("PlacingLocation", Element("skiros:Location"),
                      ParamTypes.Required)
        self.addParam("Object", Element("skiros:Product"), ParamTypes.Required)
        self.addParam("Arm", Element("rparts:ArmDevice"), ParamTypes.Required)
        self.addParam("Gripper", Element("rparts:GripperEffector"),
                      ParamTypes.Required)
        #=======PreConditions=========

        self.addPreCondition(
            self.getRelationCond("RobotAt", "skiros:at", "Robot",
                                 "PlacingLocation", True))
        self.addPreCondition(
            self.getRelationCond("Holding", "skiros:contain", "Gripper",
                                 "Object", True))
        #self.addPreCondition(self.getPropCond("LocationEmpty", ":ContainerState", "PlacingLocation", "=", "Empty", True));
        #=======PostConditions=========
        self.addPostCondition(
            self.getRelationCond("NotHolding", "skiros:contain", "Gripper",
                                 "Object", False))
        #self.addPostCondition(self.getPropCond("LocationEmpty", ":ContainerState", "PlacingLocation", "=", "Empty", False));
        self.addPostCondition(
            self.getPropCond("EmptyHanded", "skiros:ContainerState", "Gripper",
                             "=", "Empty", True))
        self.addPostCondition(
            self.getRelationCond("InPlace", "skiros:contain",
                                 "PlacingLocation", "Object", True))
Пример #3
0
 def createDescription(self):
     #=======Params=========
     #self.addParam("Container", Element(":Location"), ParamTypes.World)
     #self.addParam("Object", Element(":Product"), ParamTypes.Optional)
     self.addParam("Pose", Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
     self.addParam("Pose2", Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
Пример #4
0
 def createDescription(self):
     #=======Params=========
     self.addParam("Pose", Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
     self.addParam("Pose2", Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
     self.addParam("Pose3", Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
Пример #5
0
 def createDescription(self):
     #=======Params=========
     self.addParam("Turtle", Element("cora:Robot"), ParamTypes.Required)
     self.addParam("Target", Element("sumo:Object"), ParamTypes.Required)
     self.addParam("Linear", float, ParamTypes.Optional)
     self.addParam("Angular", float, ParamTypes.Optional)
     self.addParam("MinVel", float, ParamTypes.Optional)
     self.addParam("MinDist", float, ParamTypes.Optional)
Пример #6
0
 def createDescription(self):
     #=======Params=========
     self.addParam("StartLocation", Element("skiros:Location"), ParamTypes.Inferred)
     self.addParam("TargetLocation", Element("skiros:Location"), ParamTypes.Required)
     #=======PreConditions=========
     self.addPreCondition(self.getRelationCond("RobotAt", "skiros:at", "Robot", "StartLocation", True))
     #=======PostConditions=========
     self.addPostCondition(self.getRelationCond("NoRobotAt", "skiros:at", "Robot", "StartLocation", False))
     self.addPostCondition(self.getRelationCond("RobotAt", "skiros:at", "Robot", "TargetLocation", True))
Пример #7
0
 def createDescription(self):
     #=======Params=========
     self.addParam("WorldModelObject", Element("skiros:TransformationPose"),
                   ParamTypes.Required)
     self.addParam("WorldModelOptional",
                   Element("skiros:TransformationPose"),
                   ParamTypes.Optional)
     self.addParam("DictionaryOptional", dict, ParamTypes.Optional)
     self.addParam("Boolean", False, ParamTypes.Required)
     self.addParam("Number", 0.0, ParamTypes.Required)
Пример #8
0
 def createDescription(self):
     #=======Params=========
     self.addParam("Container", Element("skiros:Location"), ParamTypes.Required)
     self.addParam("Object", Element("skiros:Product"), ParamTypes.Optional)
     self.addParam("Camera", Element("skiros:DepthCamera"), ParamTypes.Required, [ParamOptions.Lock])
     #=======PreConditions=========
     self.addPreCondition(self.getRelationCond("RobotAt", "skiros:at", "Robot", "Container", True))
     self.addPreCondition(self.getAbstractRelationCond("ContainerForObject", "skiros:partReference", "Container", "Object", True))
     #=======PostConditions=========
     self.addPostCondition(self.getRelationCond("InContainer", "skiros:contain", "Container", "Object", True))
     self.addPostCondition(self.getHasPropCond("HasPosition", "skiros:Position", "Object", True))
Пример #9
0
 def createDescription(self):
     # =======Params=========
     self.addParam("StartLocation", Element("sumo:Object"),
                   ParamTypes.Inferred)
     self.addParam("TargetLocation", Element("sumo:Object"),
                   ParamTypes.Optional)
     self.addParam("Object", Element("sumo:Object"), ParamTypes.Required)
     self.addParam("Relation", "skiros:contain", ParamTypes.Required)
     # =======PreConditions=========
     self.addPreCondition(
         self.getRelationCond("StartContainObj", "skiros:spatiallyRelated",
                              "StartLocation", "Object", True))
Пример #10
0
    def test_setProperty(self):
        e = Element()
        e.setProperty("Integer", 1)
        self.assertEqual([1], e.getProperty("Integer").values)

        msg = """
        setProperty should convert when setting the property if 
        force_convertion is true"""
        e.setProperty("Integer", "2", force_convertion=True)
        self.assertEqual([2], e.getProperty("Integer").values, msg)

        msg = """
        setProperty should convert when setting the property if 
        value is a list and if force_convertion is true"""
        e.setProperty("Integer", ["1", "2"], force_convertion=True)
        self.assertEqual([1, 2], e.getProperty("Integer").values, msg)

        msg = """
        setProperty should convert unicode values to str before
        creating new property"""
        e.setProperty("strKey", u"a")
        self.assertEqual(str, type(e.getProperty("strKey").value), msg)

        msg = """
        setProperty should convert unicode values to str when setting
        the property"""
        e.setProperty("strKey", u"b")
        self.assertEqual(["b"], e.getProperty("strKey").values, msg)
Пример #11
0
 def _register_agent(self, agent_name):
     res = self._wmi.resolve_element(Element("cora:Robot", agent_name))
     if res:
         log.info("[{}]".format(self.__class__.__name__),
                  "Found robot {}, skipping registration.".format(res))
         self._robot = res
         for r in self._robot.getRelations("-1", "skiros:hasSkill"):
             self._wmi.remove_element(self._wmi.get_element(r['dst']))
         self._robot = self._wmi.get_element(self._robot.id)
     else:
         self._robot = self._wmi.instanciate(agent_name, True)
         startLocUri = self._wmi.get_template_element(
             agent_name).getRelations(pred="skiros:hasStartLocation")
         if startLocUri:
             start_location = self._wmi.instanciate(startLocUri[0]["dst"],
                                                    False, [])
             self._wmi.set_relation(self._robot._id, "skiros:at",
                                    start_location._id)
             self._robot = self._wmi.get_element(self._robot.id)
     log.info("[{}]".format(self.__class__.__name__),
              "Registered robot {}".format(self._robot))
     self._robot.setProperty(
         "skiros:SkillMgr",
         self._agent_name[self._agent_name.rfind(":") + 1:])
     self._wmi.update_element(self._robot)
Пример #12
0
 def generateDefParams(self):
     """
     @brief Some default params are added automatically
     """
     if not self._params.hasParam('Robot'):
         self._params.addParam("Robot", Element("sumo:Agent"),
                               params.ParamTypes.Inferred)
Пример #13
0
 def createDescription(self):
     #=======Params=========
     self.addParam("Name", str, ParamTypes.Required)
     self.addParam("X", 0.0, ParamTypes.Required)
     self.addParam("Y", 0.0, ParamTypes.Required)
     self.addParam("Rotation", 0.0, ParamTypes.Required)
     self.addParam("Turtle", Element("cora:Robot"), ParamTypes.Optional)
Пример #14
0
 def _autoParametrizeBB(self, skill):
     """
     @brief ground undefined parameters with parameters in the Black Board
     """
     to_resolve = [
         key for key, param in skill._params.getParamMap().iteritems()
         if param.paramType != params.ParamTypes.Optional and
         param.dataTypeIs(Element) and param.getValue().getIdNumber() < 0
     ]
     if not to_resolve:
         return True
     log.assertInfo(self._verbose, "[Autoparametrize]",
                    "Resolving {}:{}".format(skill.type, to_resolve))
     #self._importParentsConditions(skill, to_resolve)
     remap = {}
     cp = params.ParamHandler()
     cp.reset(skill._params.getCopy())
     for c in skill._pre_conditions:
         c.setDesiredState(cp)
     for key in to_resolve:
         remap[key] = []
         for k, p in self._params._params.iteritems():
             if p.dataTypeIs(Element()):
                 if p.getValue().isInstance(cp.getParamValue(key),
                                            self._wm):
                     remap[key].append(k)
                 else:
                     pass  # log.info("Not instance", "{} Model: {} Match: {}".format(key, cp.getParamValue(key).printState(True), p.getValue().printState(True)))
     return self._autoParametrizeWm(skill, to_resolve, cp)
 def createDescription(self):
     # =======Params=========
     self.addParam("Pose", Element("skiros:TransformationPose"),
                   ParamTypes.Required)
     self.addParam("Direction",
                   0,
                   ParamTypes.Required,
                   description="x: 0, y: 1, z: 2")
Пример #16
0
 def test_hasProperty(self):
     e = Element()
     e.setProperty("Integer", "2", "xsd:int")
     self.assertEqual(False, e.hasProperty("NonExistingKey"))
     self.assertEqual(False, e.hasProperty("Integer", 1))
     self.assertEqual(True, e.hasProperty("Integer", 2))
     self.assertEqual(True, e.hasProperty("Integer"))
     e.setProperty("Type", int)
     self.assertEqual(False, e.hasProperty("Type", not_none=True))
Пример #17
0
def test_remove_element(skiros_bot):
    "test that an element can be removed from wm through the gui"
    element = Element(":testType")
    element_inst = skiros_bot.add_object(element)
    #test that element is there
    assert skiros_bot.gui_has_element(element_inst)
    skiros_bot.remove_object(element_inst)
    #test that it was removed
    assert not skiros_bot.gui_has_element(element_inst)
Пример #18
0
 def printParams(self, params):
     to_ret = "\n"
     for _, p in params.getParamMap().iteritems():
         if isinstance(Element(), p.dataType()):
             to_ret += p._key + ": "
             for e in p.getValues():
                 to_ret += e.printState() + "\n"
         else:
             to_ret += p.printState() + "\n"
     return to_ret
Пример #19
0
    def test_element(self):
        e = Element()
        e.setProperty("Hello", float)
        e.setProperty("Hello", 0.0)
        self.assertEqual(e.getProperty("Hello").value, 0.0)

        e.getProperty("Hello").values = 1.0
        self.assertEqual(e.getProperty("Hello").values, [1.0])

        e.getProperty("Hello").value = 2.0
        self.assertEqual(e.getProperty("Hello").values, [2.0])
Пример #20
0
 def inferUnvalidParams(self, skill):
     #print '{}: {} '.format(skill._label, self.printParams(skill._params))
     unvalid_params = skill.checkPreCond(self._verbose)
     if unvalid_params:
         log.info("[{}] Reset unvalid params {}".format(skill._label, unvalid_params))
         for k in unvalid_params:
             skill._params.setDefault(k)
             p = skill._params.getParam(k)
             if p.dataTypeIs(Element()) and p.getValue().getIdNumber() >= 0:
                 skill._params.specify(k, self._wm.get_element(p.getValue()._id))
         return self._autoParametrizeBB(skill)
     return True
Пример #21
0
 def reset(self, add_root=True, scene_name="skiros:blank_scene"):
     """
     @brief Initialize the scene
     """
     IndividualsDataset.reset(self)
     self._id_gen.clear()
     if add_root:
         if self.has_individual(scene_name):
             root = self.get_individual(scene_name)
         else:
             root = Element("skiros:Scene", scene_name)
         self.add_element(root, self.__class__.__name__)
Пример #22
0
def test_save_and_load_scene(skiros_bot):
    "Test saving a scene and loading it back"
    #setup a scene and save it
    scene_name = "test_scene.turtle"
    element = Element(":testType")
    element_inst = skiros_bot.add_object(element)
    skiros_bot.save_scene(scene_name)
    #reset the scene to clear the changes
    skiros_bot.reset_scene()
    assert not skiros_bot.gui_has_element(element_inst)
    #load the changes back in
    skiros_bot.load_scene(scene_name)
    assert skiros_bot.gui_has_element(element_inst)
Пример #23
0
 def toElement(self):
     to_ret = Element(self._type)
     to_ret._label = self._label
     for _, p in self.params.items():
         if p.dataTypeIs(Element):
             to_ret.addRelation(self, "skiros:hasParam", p.toElement())
     for c in self._pre_conditions:
         to_ret.addRelation(self, "skiros:hasPreCondition", c.toElement())
     for c in self._hold_conditions:
         to_ret.addRelation(self, "skiros:hasHoldCondition", c.toElement())
     for c in self._post_conditions:
         to_ret.addRelation(self, "skiros:hasPostCondition", c.toElement())
     return to_ret
Пример #24
0
 def _updateRoutine(self, time):
     """
     @brief Sync the modified parameters elements with wm
     @time The time to evaluate if a parameter was changed
     """
     for k, p in self.params.iteritems():
         if p.dataTypeIs(Element()) and p.hasChanges(time):
             vs = p.values
             for i, e in enumerate(vs):
                 if not e.isAbstract():
                     self._wmi.update_element(e)
                 else:
                     vs[i] = self._wmi.add_element(e)
Пример #25
0
 def toElement(self):
     to_ret = Element("skiros:Parameter", self._key)
     to_ret.setProperty("rdfs:comment", self._description)
     to_ret.setProperty("skiros:ParameterType", self._param_type.value - 1)
     if (not self.dataTypeIs(Element)):
         to_ret.setProperty("skiros:DataType", self._data_type)
         if self.hasSpecifiedDefault():
             to_ret.setProperty("skiros:Default", self._default)
         if self.isSpecified():
             to_ret.setProperty("skiros:Value", self._values)
     else:
         to_ret.setProperty("skiros:DataType", self._default[0]._type)
         if self.isSpecified():
             for v in self._values:
                 if v._id != "":
                     to_ret.addRelation("-1", "skiros:hasValue", v._id)
     return to_ret
Пример #26
0
 def generateDefConditions(self):
     """
     @brief Some default preconditions are added automatically
     """
     #self.addPreCondition(self.getRelationCond("HasSkill", "hasSkill", "Robot", "Skill", True))
     # for key, param in self._params.getParamMapFiltered(params.ParamTypes.Hardware).iteritems():
     #    self.addPreCondition(self.getPropCond("DeviceIdle", "deviceState", key, "Idle", True))
     for key, param in self._params.getParamMapFiltered(
             params.ParamTypes.Optional).items():
         if isinstance(Element(), param.dataType()):
             c1 = self.getGenerateCond("Has" + key, key, True)
             dont_add = False
             for c2 in self._post_conditions:
                 if c1.isEqual(c2) or c1.hasConflict(c2):
                     dont_add = True
             if not dont_add:
                 self._post_conditions = [c1] + self._post_conditions
     return True
Пример #27
0
    def get_individual(self, name, context_id=""):
        """
        @brief Builds an element from an individual

        @param context_id if defined look for the individual only in the context
        """
        subject = self.lightstring2uri(name)
        if not self.uri_exists(subject, context_id):
            raise Exception(
                "Element {} doesn't exist in ontology. Uri: {}. Context: {}.".
                format(name, subject, context_id))
        e = Element()
        for predicate, obj in self.ontology(context_id).predicate_objects(
                subject):
            if OWL.DatatypeProperty in self.ontology().objects(
                    predicate, RDF.type) or predicate == RDFS.comment:
                e.setProperty(self.uri2lightstring(predicate),
                              obj.value,
                              self.uri2lightstring(obj.datatype),
                              force_convertion=True)
            elif OWL.ObjectProperty in self.ontology().objects(
                    predicate, RDF.type):
                e.addRelation("-1", self.uri2lightstring(predicate),
                              self.uri2lightstring(obj))
            elif predicate == RDF.type and obj != OWL.NamedIndividual:
                e._type = self.uri2lightstring(str(obj))
            elif obj == OWL.NamedIndividual:
                pass
            elif predicate == RDFS.label:
                e._label = obj.value
            else:
                log.error(
                    "[get_individual]",
                    "Ignoring {}-{}-{}. Predicate is not defined in the ontology."
                    .format(name, self.uri2lightstring(predicate),
                            self.uri2lightstring(obj)))
        for subj, predicate in self.ontology(context_id).subject_predicates(
                subject):
            if (self.uri2lightstring(predicate) != "skiros:hasTemplate"):
                e.addRelation(self.uri2lightstring(subj),
                              self.uri2lightstring(predicate), "-1")
        self._add_reasoners_prop(e)
        return e
Пример #28
0
    def addParam(self, key, value, param_type, options=[], description=""):
        """
        @brief Adds a parameter

        key: a unique string identifier
        value: the default value or type
        param_type: the type of parameter (see ParamTypes)
        options: see ParamOptions
        description: an optional verbose description
        """
        self._params.addParam(key, value, param_type, description)
        if isinstance(value, type(Element())):
            for o in options:
                if o == ParamOptions.Consume:
                    self._post_conditions += [
                        self.getGenerateCond("Consume" + key, key, False)
                    ]
                elif o == ParamOptions.Unspecify:
                    self._post_conditions += [
                        self.getIsSpecifiedCond("Unset" + key, key, False)
                    ]
                elif o == ParamOptions.Lock:
                    self._pre_conditions += [
                        self.getPropCond(key + 'Idle', "skiros:StateProperty",
                                         key, "=", "Idle", True)
                    ]
                    self._hold_conditions += [
                        self.getPropCond(key + 'Busy', "skiros:StateProperty",
                                         key, "=", "Idle", False)
                    ]
                    self._post_conditions += [
                        self.getPropCond(key + 'Idle', "skiros:StateProperty",
                                         key, "=", "Idle", True)
                    ]
                elif o == ParamOptions.RespectType:
                    self._pre_conditions.append(
                        self.getOnTypeCond(key + 'OfType', key,
                                           self.params[key].default.type))
Пример #29
0
 def createDescription(self):
     self.addParam("Turtle", Element("cora:Robot"), ParamTypes.Required)
     self.addParam("Linear", float, ParamTypes.Required, "Linear velocity")
     self.addParam("Angular", float, ParamTypes.Required,
                   "Angular velocity in degrees")
Пример #30
0
 def createDescription(self):
     #=======Params=========
     self.addParam("Turtle", Element("cora:Robot"), ParamTypes.Required)