Skip to content

Commit

Permalink
Merge pull request #223 from tomsch420/dev
Browse files Browse the repository at this point in the history
Added better ontology interface.
  • Loading branch information
Tigul authored Nov 28, 2024
2 parents e75a355 + d94547a commit 164a0ea
Show file tree
Hide file tree
Showing 69 changed files with 866 additions and 2,682 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/notebook-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ jobs:
run: |
source /opt/ros/overlay_ws/devel/setup.bash
roscd pycram/examples/tmp
treon --thread 1 -v --exclude=migrate_neems.ipynb
treon --thread 1 -v --exclude=migrate_neems.ipynb --exclude=improving_actions.ipynb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ resources/cached/

# Example checkpoints
examples/.ipynb_checkpoints/
*/tmp/*
9 changes: 5 additions & 4 deletions examples/action_designator.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType, WorldMode
from pycram.datastructures.pose import Pose
import pycrap

world = BulletWorld(WorldMode.GUI)
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf", pose=Pose([1, 2, 0]))
apartmet = Object("apartment", ObjectType.ENVIRONMENT, "apartment.urdf")
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([2.3, 2, 1.1]))
world = BulletWorld(WorldMode.DIRECT)
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf", pose=Pose([1, 2, 0]))
apartmet = Object("apartment", pycrap.Apartment, "apartment.urdf")
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([2.3, 2, 1.1]))
```

To move the robot we need to create a description and resolve it to an actual Designator. The description of navigation
Expand Down
9 changes: 5 additions & 4 deletions examples/bullet_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ First we need to import and create a BulletWorld.
from pycram.worlds.bullet_world import BulletWorld
from pycram.datastructures.pose import Pose
from pycram.datastructures.enums import ObjectType, WorldMode
import pycrap

world = BulletWorld(mode=WorldMode.GUI)
world = BulletWorld(mode=WorldMode.DIRECT)
```

This new window is the BulletWorld, PyCRAMs internal physics simulation. You can use the mouse to move the camera
Expand All @@ -41,7 +42,7 @@ To spawn new things in the BulletWorld we need to import the Object class and cr
```python
from pycram.world_concepts.world_object import Object

milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([0, 0, 1]))
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([0, 0, 1]))
```

<!-- #region -->
Expand Down Expand Up @@ -91,7 +92,7 @@ parameter. Since attachments are bi-directional it doesn't matter on which Objec
First we need another Object

```python
cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1, 0, 1]))
cereal = Object("cereal", pycrap.Cereal, "breakfast_cereal.stl", pose=Pose([1, 0, 1]))
```

```python
Expand Down Expand Up @@ -119,7 +120,7 @@ which contain every link or joint as key and a unique id, used by PyBullet, as v
We will see this at the example of the PR2:

```python
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
print(pr2.links)
```

Expand Down
16 changes: 8 additions & 8 deletions examples/cram_plan_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ from pycram.world_concepts.world_object import Object
import anytree
import pycram.failures
import numpy as np
import pycrap

np.random.seed(4)

world = BulletWorld()
robot = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
robot = Object("pr2", pycrap.Robot, "pr2.urdf")
robot_desig = ObjectDesignatorDescription(names=['pr2']).resolve()
apartment = Object("apartment", "environment", "apartment.urdf", pose=Pose([-1.5, -2.5, 0]))
apartment = Object("apartment", pycrap.Apartment, "apartment.urdf", pose=Pose([-1.5, -2.5, 0]))
apartment_desig = ObjectDesignatorDescription(names=['apartment']).resolve()
table_top = apartment.get_link_position("cooktop")
# milk = Object("milk", "milk", "milk.stl", position=[table_top[0]-0.15, table_top[1], table_top[2]])
Expand Down Expand Up @@ -98,6 +99,7 @@ def get_n_random_positions(pose_list, n=4, dist=0.5, random=True):
```

```python
import pycrap
from pycram.costmaps import SemanticCostmap
from pycram.pose_generator_and_validator import PoseGenerator

Expand All @@ -106,17 +108,15 @@ poses_list = list(PoseGenerator(scm, number_of_samples=-1))
poses_list.sort(reverse=True, key=lambda x: np.linalg.norm(x.position_as_list()))
object_poses = get_n_random_positions(poses_list)
object_names = ["bowl", "breakfast_cereal", "spoon"]
object_types = [pycrap.Bowl, pycrap.Cereal, pycrap.Spoon]
objects = {}
object_desig = {}
for obj_name, obj_pose in zip(object_names, object_poses):
print(obj_name)
print(obj_pose)
objects[obj_name] = Object(obj_name, obj_name, obj_name + ".stl",
for obj_name, obj_type, obj_pose in zip(object_names, object_types, object_poses):
objects[obj_name] = Object(obj_name, obj_type, obj_name + ".stl",
pose=Pose([obj_pose.position.x, obj_pose.position.y, table_top.z]))
objects[obj_name].move_base_to_origin_pose()
objects[obj_name].original_pose = objects[obj_name].pose
object_desig[obj_name] = ObjectDesignatorDescription(names=[obj_name], types=[obj_name]).resolve()
print(object_poses)
object_desig[obj_name] = ObjectDesignatorDescription(names=[obj_name], types=[obj_type]).resolve()
```

If You want to visualize all apartment frames
Expand Down
19 changes: 10 additions & 9 deletions examples/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ It is possible to spawn objects and robots into the BulletWorld, these objects c
A BulletWorld can be created by simply creating an object of the BulletWorld class.

```python
import pycrap
from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType, WorldMode
from pycram.datastructures.pose import Pose

world = BulletWorld(mode=WorldMode.GUI)
world = BulletWorld(mode=WorldMode.DIRECT)

milk = Object("Milk", ObjectType.MILK, "milk.stl")
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.4, 1, 0.95]))
milk = Object("milk", pycrap.Milk, "milk.stl")
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
cereal = Object("cereal", pycrap.Cereal, "breakfast_cereal.stl", pose=Pose([1.4, 1, 0.95]))
```

The BulletWorld allows to render images from arbitrary positions. In the following example we render images with the
Expand Down Expand Up @@ -90,7 +91,7 @@ Since everything inside the BulletWorld is an Object, even a complex environment
in the same way as the milk.

```python
kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
kitchen = Object("kitchen", pycrap.Kitchen, "kitchen.urdf")
```

## Costmaps
Expand Down Expand Up @@ -270,7 +271,7 @@ Designators are used, for example, by the PickUpAction to know which object shou
```python
from pycram.designators.object_designator import *

milk_desig = BelieveObject(names=["Milk"])
milk_desig = BelieveObject(names=["milk"])
milk_desig.resolve()
```

Expand All @@ -281,7 +282,7 @@ Location Designator can create a position in cartisian space from a symbolic des
```python
from pycram.designators.object_designator import *

milk_desig = BelieveObject(names=["Milk"])
milk_desig = BelieveObject(names=["milk"])
milk_desig.resolve()
```

Expand All @@ -293,8 +294,8 @@ Location Designators can create a position in cartesian space from a symbolic de
from pycram.designators.location_designator import *
from pycram.designators.object_designator import *

robot_desig = BelieveObject(types=[ObjectType.ROBOT]).resolve()
milk_desig = BelieveObject(names=["Milk"]).resolve()
robot_desig = BelieveObject(types=[pycrap.Robot]).resolve()
milk_desig = BelieveObject(names=["milk"]).resolve()
location_desig = CostmapLocation(target=milk_desig, visible_for=robot_desig)

print(f"Resolved: {location_desig.resolve()}")
Expand Down
3 changes: 2 additions & 1 deletion examples/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ plan.
If you are performing a plan with a simulated robot, you need a BulletWorld.

```python
import pycrap
from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType

world = BulletWorld()
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
```

```python
Expand Down
9 changes: 5 additions & 4 deletions examples/local_transformer.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from pycram.world_concepts.world_object import Object
from pycram.datastructures.pose import Transform, Pose
from pycram.local_transformer import LocalTransformer
from pycram.datastructures.enums import WorldMode
import pycrap
```

## Initializing the World
Expand All @@ -41,7 +42,7 @@ world first.

```python
# Create an instance of the BulletWorld
world = BulletWorld(WorldMode.GUI)
world = BulletWorld(WorldMode.DIRECT)
```

## Adding Objects to the World
Expand All @@ -55,9 +56,9 @@ These objects will be used in subsequent tasks, to provide the frames to which w
from pycram.worlds.bullet_world import Object
from pycram.datastructures.enums import ObjectType

kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([0.9, 1, 0.95]))
bowl = Object("bowl", ObjectType.BOWL, "bowl.stl", pose=Pose([1.6, 1, 0.90]))
kitchen = Object("kitchen", pycrap.Kitchen, "kitchen.urdf")
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([0.9, 1, 0.95]))
bowl = Object("bowl", pycrap.Bowl, "bowl.stl", pose=Pose([1.6, 1, 0.90]))
```

## Creating a Local Transfomer
Expand Down
11 changes: 6 additions & 5 deletions examples/location_designator.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType, WorldMode
from pycram.datastructures.pose import Pose
import pycrap

world = BulletWorld(WorldMode.GUI)
apartment = Object("apartment", ObjectType.ENVIRONMENT, "apartment.urdf")
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
world = BulletWorld(WorldMode.DIRECT)
apartment = Object("apartment", pycrap.Apartment, "apartment.urdf")
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
```

Next up we will create the location designator description, the {meth}`~pycram.designators.location_designator.CostmapLocation` that we will be using needs a
Expand Down Expand Up @@ -78,7 +79,7 @@ PR2 will be set to 0.2 since otherwise the arms of the robot will be too low to

```python
pr2.set_joint_position("torso_lift_joint", 0.2)
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([1.3, 1, 0.9]))

```

Expand Down Expand Up @@ -181,7 +182,7 @@ from pycram.datastructures.enums import ObjectType

apartment_desig = BelieveObject(names=["apartment"])
handle_desig = ObjectPart(names=["handle_cab10_t"], part_of=apartment_desig.resolve())
robot_desig = BelieveObject(types=[ObjectType.ROBOT])
robot_desig = BelieveObject(types=[pycrap.Robot])

access_location = AccessingLocation(handle_desig.resolve(), robot_desig.resolve()).resolve()
print(access_location.pose)
Expand Down
9 changes: 5 additions & 4 deletions examples/migrate_neems.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ from pycram.tasktree import with_tree
from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.designators.object_designator import *
import pycrap


class ExamplePlans:
def __init__(self):
self.world = BulletWorld("DIRECT")
self.pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
self.kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
self.milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
self.cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
self.pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
self.kitchen = Object("kitchen", pycrap.Kitchen, "kitchen.urdf")
self.milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([1.3, 1, 0.9]))
self.cereal = Object("cereal", pycrap.Cereal, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
self.milk_desig = ObjectDesignatorDescription(names=["milk"])
self.cereal_desig = ObjectDesignatorDescription(names=["cereal"])
self.robot_desig = ObjectDesignatorDescription(names=["pr2"]).resolve()
Expand Down
9 changes: 5 additions & 4 deletions examples/minimal_task_tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ from pycram.datastructures.pose import Pose
from pycram.datastructures.enums import ObjectType, WorldMode
import anytree
import pycram.failures
import pycrap
```

Next we will create a bullet world with a PR2 in a kitchen containing milk and cereal.

```python
world = BulletWorld(WorldMode.DIRECT)
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
kitchen = Object("kitchen", pycrap.Kitchen, "kitchen.urdf")
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cereal = Object("cereal", pycrap.Cereal, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
milk_desig = ObjectDesignatorDescription(names=["milk"])
cereal_desig = ObjectDesignatorDescription(names=["cereal"])
robot_desig = ObjectDesignatorDescription(names=["pr2"]).resolve()
Expand Down
11 changes: 6 additions & 5 deletions examples/motion_designator.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType, WorldMode
from pycram.datastructures.pose import Pose
import pycrap

world = BulletWorld(WorldMode.GUI)
pr2 = Object("pr2", ObjectType.ROBOT, "pr2.urdf")
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.5, 0, 1]))
world = BulletWorld(WorldMode.DIRECT)
pr2 = Object("pr2", pycrap.Robot, "pr2.urdf")
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([1.5, 0, 1]))
```

## Move
Expand Down Expand Up @@ -115,7 +116,7 @@ from pycram.process_module import simulated_robot
with simulated_robot:
LookingMotion(target=Pose([1.5, 0, 1], [0, 0, 0, 1])).perform()

motion_description = DetectingMotion(object_type=ObjectType.MILK)
motion_description = DetectingMotion(object_type=pycrap.Milk)

obj = motion_description.perform()

Expand Down Expand Up @@ -150,7 +151,7 @@ from pycram.designators.motion_designator import WorldStateDetectingMotion
from pycram.process_module import simulated_robot

with simulated_robot:
motion_description = WorldStateDetectingMotion(object_type=ObjectType.MILK)
motion_description = WorldStateDetectingMotion(object_type=pycrap.Milk)

obj = motion_description.perform()

Expand Down
18 changes: 10 additions & 8 deletions examples/object_designator.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ from pycram.worlds.bullet_world import BulletWorld
from pycram.world_concepts.world_object import Object
from pycram.datastructures.enums import ObjectType, WorldMode
from pycram.datastructures.pose import Pose

world = BulletWorld(WorldMode.GUI)
import pycrap
world = BulletWorld(WorldMode.DIRECT)
```

## Believe Object
Expand All @@ -49,10 +49,12 @@ description which will be used to describe objects in the real world.
Since {meth}`~pycram.designators.object_designator.BelieveObject` describes Objects in the BulletWorld we create a few.

```python
kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cereal = Object("froot_loops", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.3, 0.9, 0.95]))
spoon = Object("spoon", ObjectType.SPOON, "spoon.stl", pose=Pose([1.3, 1.1, 0.87]))
import pycrap

kitchen = Object("kitchen", pycrap.Kitchen, "kitchen.urdf")
milk = Object("milk", pycrap.Milk, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cereal = Object("froot_loops", pycrap.Cereal, "breakfast_cereal.stl", pose=Pose([1.3, 0.9, 0.95]))
spoon = Object("spoon", pycrap.Spoon, "spoon.stl", pose=Pose([1.3, 1.1, 0.87]))
```

Now that we have objects we can create an object designator to describe them. For the start we want an object designator
Expand All @@ -73,7 +75,7 @@ the world.
```python
from pycram.designators.object_designator import BelieveObject

object_description = BelieveObject(types=[ObjectType.MILK, ObjectType.BREAKFAST_CEREAL])
object_description = BelieveObject(types=[pycrap.Milk, pycrap.Cereal])

print(object_description.resolve())
```
Expand Down Expand Up @@ -107,7 +109,7 @@ For this we need some objects, so if you didn't already spawn them you can use t
```python
from pycram.designators.object_designator import BelieveObject

object_description = BelieveObject(types=[ObjectType.MILK, ObjectType.BREAKFAST_CEREAL])
object_description = BelieveObject(types=[pycrap.Milk, pycrap.Cereal])

for obj in object_description:
print(obj, "\n")
Expand Down
Loading

0 comments on commit 164a0ea

Please sign in to comment.