meta-control / mc_mros_reasoner

library for metacontrol-based self-adaptation using ontological reasoning, with wrappers for robotic systems based on ROS1 and ROS2
Apache License 2.0
7 stars 10 forks source link

Measured QAs are not saved unless there is a FG to attach it to #156

Open Rezenders opened 1 year ago

Rezenders commented 1 year ago

Measured QAs are only saved if there is a FG to attach it to. Measured QAs are important even when there is no FG, see https://github.com/kas-lab/pipeline_inspection/issues/35. In addition, the measured QAs are being saved attached to the first FG that is being found, unless in the diagnostic msg it is explicitly written what function it should be attached to. The user should not need to add this info to the diagnostics msg, the Fgs to attach it to should be inferred given the type of the QAs.

In tomasys.py

def update_qa_value(fg, qa_type, value, tbox, abox):
    qas = fg.hasQAvalue

    if qas == []:  # for the first qa value received
        qav = tbox.QAvalue(
            "obs_{}".format(
                qa_type.name),
            namespace=abox,
            isQAtype=qa_type,
            hasValue=value)
        fg.hasQAvalue.append(qav)
    else:
        for qa in qas:
            if qa.isQAtype == qa_type:
                qa.hasValue = value
                return
        # case it is a new QA type value
        qav = tbox.QAvalue(
            "obs_{}".format(
                qa_type.name),
            isQAtype=qa_type,
            namespace=abox,
            hasValue=value)
        fg.hasQAvalue.append(qav)

In reasoner.py

# update QA value based on incoming diagnostic
    def update_qa(self, diagnostic_status):
        # Find the FG with the same name that the one in the QA message (in
        # diagnostic_status.name)
        fg = next((fg for fg in self.tomasys.FunctionGrounding.instances()
                  if fg.name == diagnostic_status.name), None)
        if fg is None:
            fg = self.tomasys.FunctionGrounding.instances()[0]
            return_value = -1

        qa_type = self.get_qa_type(diagnostic_status.values[0].key)
        if qa_type is not None:
            value = float(diagnostic_status.values[0].value)
            with self.ontology_lock:
                update_qa_value(fg, qa_type, value, self.tomasys, self.onto)
            return_value = 1
        else:
            return_value = 0
        return return_value
Rezenders commented 1 year ago

Measured QAs are only saved if there is a FG to attach it to.

This is not true, they are saved with the prefix obs_. Like: obs_mockiness.

In addition, the measured QAs are being saved attached to the first FG that is being found, unless in the diagnostic msg it is explicitly written what function it should be attached to. The user should not need to add this info to the diagnostics msg, the Fgs to attach it to should be inferred given the type of the QAs.

However, this is true. This part is wrong.

def update_qa(self, diagnostic_status):
        # Find the FG with the same name that the one in the QA message (in
        # diagnostic_status.name)
        fg = next((fg for fg in self.tomasys.FunctionGrounding.instances()
                  if fg.name == diagnostic_status.name), None)
        if fg is None:
            fg = self.tomasys.FunctionGrounding.instances()[0]
            return_value = -1
Rezenders commented 1 year ago

Measured QAs are only saved if there is a FG to attach it to. This is not true, they are saved with the prefix obs_. Like: obs_mockiness.

Actually, this seems to be true.

Rezenders commented 1 year ago

Fixed at 1f36457 Measured qas are saved regardless of a FG existing or not. Then, the measured QA is associated to all FGs that need it.

chcorbato commented 1 year ago

We need to define a consistent model for QA values, both in tomasys and the implement a corresponding logic in the reasoner.

I am reopening the issue for that reason @Rezenders , also the link to this discussion would be useful when addressing it. But if you prefer to close this one and one a new Issue, that is ok with me.