Skip to content

Commit

Permalink
[knowledge] some tests and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigul committed Nov 27, 2024
1 parent a7c6211 commit 39e64f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/pycram/designators/action_designator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,7 @@ def __init__(self, object_designator_description: ObjectPart, arms: List[Arms] =
super().__init__(ontology_concept_holders)
self.object_designator_description: ObjectPart = object_designator_description
self.arms: List[Arms] = arms
self.knowledge_condition = ReachableProperty(
self.object_designator_description.resolve().pose) & GripperIsFreeProperty(self.arms[0])
self.knowledge_condition = GripperIsFreeProperty(self.arms)

if self.soma:
self.init_ontology_concepts({"opening": self.soma.Opening})
Expand Down Expand Up @@ -1180,8 +1179,7 @@ def __init__(self, object_designator_description: ObjectPart, arms: List[Arms] =
super().__init__(ontology_concept_holders)
self.object_designator_description: ObjectPart = object_designator_description
self.arms: List[Arms] = arms
self.knowledge_condition = ReachableProperty(
self.object_designator_description.resolve().pose) & GripperIsFreeProperty(self.arms[0])
self.knowledge_condition = GripperIsFreeProperty(self.arms)

if self.soma:
self.init_ontology_concepts({"closing": self.soma.Closing})
Expand Down
1 change: 1 addition & 0 deletions src/pycram/knowledge/knowledge_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __iter__(self) -> ActionDesignatorDescription.Action:
raise ReasoningError(f"The parameters {not_reasoned} could not be inferred from the knowledge sources. Therefore, a complete designator can not be generated. ")

for key, value in self.partial_designator.kwargs.items():
# This line means the parameter of the designator description will be preferred over the reasoned parameter
if value is None:
self.partial_designator.kwargs[key] = matched_parameter[key]

Expand Down
21 changes: 18 additions & 3 deletions test/test_knowledge.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from bullet_world_testcase import BulletWorldTestCase
from knowledge_testcase import KnowledgeSourceTestCase, TestProperty, KnowledgeBulletTestCase
from pycram.datastructures.enums import Arms, Grasp
from pycram.datastructures.enums import Arms, Grasp, ObjectType
from pycram.datastructures.partial_designator import PartialDesignator
from pycram.datastructures.pose import Pose
from pycram.designators.action_designator import PickUpAction, PickUpActionPerformable
from pycram.designators.object_designator import BelieveObject
from pycram.designators.action_designator import PickUpAction, PickUpActionPerformable, OpenAction
from pycram.designators.object_designator import BelieveObject, ObjectPart
from pycram.knowledge.knowledge_engine import KnowledgeEngine
from pycram.process_modules.pr2_process_modules import Pr2MoveArmJoints

Expand Down Expand Up @@ -141,6 +141,21 @@ def test_pickup_arm(self):
desig = partial_desig.resolve()
self.assertEqual(desig.grasp, Grasp.FRONT)

def test_pickup_grasp(self):
test_object = BelieveObject(names=["milk"])
partial_desig = PickUpAction(test_object, [Arms.RIGHT])
desig = partial_desig.resolve()
self.assertEqual(desig.grasp, Grasp.FRONT)

def test_open_gripper(self):
self.robot.set_pose(Pose([-0.192, 1.999, 0], [0, 0, 0.8999, -0.437]))
self.robot.set_joint_position("torso_lift_joint", 0.3)
env_object = BelieveObject(names=["kitchen"]).resolve()
handle_desig = ObjectPart(["kitchen_island_middle_upper_drawer_handle"], env_object)
partial_desig = OpenAction(handle_desig, [Arms.RIGHT])
desig = partial_desig.resolve()
self.assertEqual(desig.arm, Arms.RIGHT)


class TestReasoningInstance(KnowledgeSourceTestCase):
pass

0 comments on commit 39e64f7

Please sign in to comment.