Skip to content

Latest commit

 

History

History
183 lines (130 loc) · 6.79 KB

output_data.md

File metadata and controls

183 lines (130 loc) · 6.79 KB
MagnebotController

Output Data

For more information regarding TDW output data, read this.

For more information regarding TDW image output data, read this.

MagnebotController includes output data for the world state and for the Magnebot agent. This data is further divided into static data that isn't expected to change per-frame (such as object IDs) and dynamic data that can change per-frame (such as Magnebot joint angles).

Object data

Object data is stored in self.objects, which is an ObjectManager add-on.

Static object data

Static object data is stored in self.objects.objects_static:

from tdw.tdw_utils import TDWUtils
from magnebot import MagnebotController


class MyController(MagnebotController):
    def init_scene(self):
        scene = [{"$type": "load_scene",
                  "scene_name": "ProcGenScene"},
                 TDWUtils.create_empty_room(12, 12)]
        objects = self.get_add_physics_object(model_name="cabinet_36_wood_beach_honey",
                                              position={"x": 0.04, "y": 0, "z": 1.081},
                                              kinematic=True,
                                              object_id=self.get_unique_id())
        self._init_scene(scene=scene,
                         objects=objects,
                         position={"x": 1, "y": 0, "z": -3},
                         rotation={"x": 0, "y": 46, "z": 0})


if __name__ == "__main__":
    c = MyController()
    c.init_scene()
    for object_id in c.objects.objects_static:
        name = c.objects.objects_static[object_id].name
        segmentation_color = c.objects.objects_static[object_id].segmentation_color
        print(object_id, name, segmentation_color)

Dynamic object data

Dynamic output data is stored in self.objects.transforms:

from tdw.tdw_utils import TDWUtils
from magnebot import MagnebotController

class MyController(MagnebotController):
    def init_scene(self):
        scene = [{"$type": "load_scene",
                  "scene_name": "ProcGenScene"},
                 TDWUtils.create_empty_room(12, 12)]
        objects = self.get_add_physics_object(model_name="cabinet_36_wood_beach_honey",
                                              position={"x": 0.04, "y": 0, "z": 1.081},
                                              kinematic=True,
                                              object_id=self.get_unique_id())
        self._init_scene(scene=scene,
                         objects=objects,
                         position={"x": 1, "y": 0, "z": -3},
                         rotation={"x": 0, "y": 46, "z": 0})


if __name__ == "__main__":
    c = MyController()
    c.init_scene()
    for object_id in c.objects.transforms:
        position = c.objects.transforms[object_id].position
        print(object_id, position)

By default, self.objects.bounds is always empty and self.objects.rigidbodies is always empty (in order to make the simulation run faster).


Magnebot data

Static Magnebot data

Static Magnebot data is stored in self.magnebot.static. This is a MagnebotStatic object.

For convenience's sake, joint IDs are sorted into dictionaries:

  • self.magnebot.static.arm_joints is a dictionary where key = ArmJoint and value = a joint ID.
  • self.magnebot.static.wheels is a dictionary where key = Wheel and value = a joint ID.
  • self.magnebot_static.magnets is a dictionary where key = Arm and value = a joint ID.
  • self.magnebot.static.joints is a dictionary key = a Joint ID and value = JointStatic.

This example will add a Magnebot to the scene and print the joint ID and segmentation of each arm joint, wheel, and magnet:

from magnebot import MagnebotController

c = MagnebotController()
c.init_scene()

print("Arm joints:")
for arm_joint in c.magnebot.static.arm_joints:
    joint_id = c.magnebot.static.arm_joints[arm_joint]
    segmentation_color = c.magnebot.static.joints[joint_id].segmentation_color
    print(arm_joint, joint_id, segmentation_color)

print("")
print("Wheels:")
for wheel in c.magnebot.static.wheels:
    joint_id = c.magnebot.static.wheels[wheel]
    segmentation_color = c.magnebot.static.joints[joint_id].segmentation_color
    print(wheel, joint_id, segmentation_color)

print("")
print("Magnets:")
for magnet in c.magnebot.static.magnets:
    joint_id = c.magnebot.static.magnets[magnet]
    segmentation_color = c.magnebot.static.joints[joint_id].segmentation_color
    print(magnet, joint_id, segmentation_color)

c.end()

Dynamic Magnebot data

Dynamic Magnebot data is stored in self.magnebot.dynamic. This is a MagnebotDynamic object. It is updated at the end of every action.

This will print the position of each joint:

from magnebot import MagnebotController

c = MagnebotController()
c.init_scene()
for arm_joint in c.magnebot.static.arm_joints:
    joint_id = c.magnebot.static.arm_joints[arm_joint]
    position = c.magnebot.dynamic.joints[joint_id].position
    print(arm_joint, position)
c.end()

This will print each object held in each magnet:

from magnebot import MagnebotController

c = MagnebotController()
c.init_scene()
for arm in c.magnebot.static.magnets:
    print(arm, c.magnebot.dynamic.held[arm])
c.end()

Images

Raw image data is stored in self.magnebot.dynamic.images, a dictionary where key = pass mask (_img, _id, or _depth) and value = raw numpy image array.

Call these functions after a c.communicate(commands) call.

  • To save the images to disk, call c.magnebot.dynamic.save_images(path).
  • To get PIL images, call c.magnebot.dynamic.get_pil_images()
  • To get depth values, call c.magnebot.dynamic.get_depth_values()
  • To get a point cloud, call c.magnebot.dynamic.get_point_cloud()
  • To get a list of objects that are currently visible to the Magnebot, call c.magnebot.get_visible_objects()

Next: Actions

Return to the README


Example controllers:

  • output_data.py Print static object data, static Magnebot data, dynamic object data, and dynamic Magnebot data.