Skip to content

Commit

Permalink
Refactor object and robot classes
Browse files Browse the repository at this point in the history
  • Loading branch information
YoruCathy committed Feb 11, 2024
1 parent 88ced89 commit 7000069
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
12 changes: 2 additions & 10 deletions pyrcareworld/pyrcareworld/agents/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ def getJointForces(self):
joint_dynamics_forces = self.env.instance_channel.set_action(
"GetJointInverseDynamicsForce", id=self.id
)
# self.env._step()
robot_info = self.getRobotState()
# print(robot_info.keys())
return (
robot_info["drive_forces"],
robot_info["gravity_forces"],
Expand Down Expand Up @@ -274,7 +272,6 @@ def getJointForceByID(self, joint_id: int):
joint_dynamics_forces = self.env.instance_channel.set_action(
"GetJointInverseDynamicsForce", id=self.id
)
# self.env._step()

robot_info = self.getRobotState()

Expand Down Expand Up @@ -440,7 +437,7 @@ def moveTo(self, targetPose: list, targetRot=None) -> None:
else:
joint_positions = self.ik_controller.calculate_ik_recursive(targetPose)
self.setJointPositions(joint_positions)
# self.env._step()


def directlyMoveTo(self, targetPose: list, targetRot: list = None) -> None:
if targetRot is not None:
Expand All @@ -450,7 +447,6 @@ def directlyMoveTo(self, targetPose: list, targetRot: list = None) -> None:
else:
joint_positions = self.ik_controller.calculate_ik_recursive(targetPose)
self.setJointPositionsDirectly(joint_positions)
# self.env._step()

def SetBioIKTargetOffset(self, IKTargetOffset: list) -> None:
pass
Expand All @@ -463,10 +459,8 @@ def BioIKMove(self, targetPose: list, duration: float, relative: bool) -> None:
duration=duration,
relative=relative,
)
# self.env._step()
while not self.env.instance_channel.data[self.id]["move_done"]:
self.env._step()
pass

def BioIKRotateQua(
self, taregetEuler: list, duration: float, relative: bool
Expand All @@ -478,7 +472,6 @@ def BioIKRotateQua(
duration=duration,
relative=relative,
)
# self.env._step()
while (
not self.env.instance_channel.data[self.id]["move_done"]
or not self.env.instance_channel.data[self.id]["rotate_done"]
Expand All @@ -487,11 +480,10 @@ def BioIKRotateQua(

def GripperOpen(self) -> None:
self.env.instance_channel.set_action("GripperOpen", id=self.gripper_id[0])
# self.env._step()


def GripperClose(self) -> None:
self.env.instance_channel.set_action("GripperClose", id=self.gripper_id[0])
# self.env._step()

def reset(self) -> None:
self.ik_controller.reset()
13 changes: 1 addition & 12 deletions pyrcareworld/pyrcareworld/objects/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def load(self, position=None, rotation=[0,0,0]) -> None:
), "The object is already in the scene, no need to load again."

self.env.asset_channel.set_action("InstanceObject", id=self.id, name=self.name)
self.env._step()
if position is not None:
self.env.instance_channel.set_action(
"SetTransform", id=self.id, position=position, rotation=rotation
Expand All @@ -39,18 +38,15 @@ def load(self, position=None, rotation=[0,0,0]) -> None:
self.env.instance_channel.set_action(
"SetTransform", id=self.id, position=[0, 0, 0], rotation=rotation
)
self.env._step()

self.is_in_scene = True
self.env._step()

def destroy(self):
"""
Destroy the object in the scene.
"""
self.env.instance_channel.set_action("Destroy", id=self.id)
self.is_in_scene = False
self.env._step()

def copy(self, copy_id: int):
"""
Expand Down Expand Up @@ -127,7 +123,6 @@ def setTransform(
self.env.instance_channel.set_action(
"SetTransform", id=self.id, rotation=rotation, is_world=is_world
)
self.env._step()

def getThisObjectState(self):
"""
Expand All @@ -143,7 +138,7 @@ def getPosition(self):
"""
Get the xyz position of this object. It is in world frame, in right hand system.
"""
self.env._step()

info = self.env.instance_channel.data[self.id]
position = info["position"]
return position
Expand Down Expand Up @@ -211,7 +206,6 @@ def setActive(self, active: bool):
Activate or deactivate this object.
"""
self.env.instance_channel.set_action("SetActive", id=self.id, active=active)
self.env._step()

def setParent(self, parent):
"""
Expand All @@ -224,7 +218,6 @@ def setParent(self, parent):
self.env.instance_channel.set_action(
"SetParent", id=self.id, parent_id=parent_id, parent_name=parent_name
)
self.env._step()

def setParentByID(self, parent_id):
"""
Expand All @@ -233,7 +226,6 @@ def setParentByID(self, parent_id):
self.env.instance_channel.set_action(
"SetParent", id=self.id, parent_id=parent_id, parent_name="Parent"
)
self.env._step()

def unsetParent(self):
"""
Expand All @@ -242,11 +234,9 @@ def unsetParent(self):
self.env.instance_channel.set_action(
"SetParent", id=self.id, parent_id=-1, parent_name=""
)
self.env._step()

def setLayer(self, layer: int):
self.env.instance_channel.set_action("SetLayer", id=self.id, layer=layer)
self.env._step()

def setRotationQuaternion(self, quaternion, is_world: bool = True) -> None:
self.env.instance_channel.set_action(
Expand All @@ -255,4 +245,3 @@ def setRotationQuaternion(self, quaternion, is_world: bool = True) -> None:
quaternion=quaternion,
is_world=is_world,
)
self.env._step()
5 changes: 0 additions & 5 deletions pyrcareworld/pyrcareworld/objects/rigid_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ def __init__(self, env, id: int, name: str, is_in_scene: bool = False):
super().__init__(env=env, id=id, name=name, is_in_scene=is_in_scene)

def getVelocity(self):
self.env._step()
vel = self.env.instance_channel.data[self.id]
return vel

def getAngularVel(self):
self.env._step()
ang_vel = self.env.instance_channel.data[self.id]
return ang_vel

def applyConstantForce(self, force: list):
self.env.instance_channel.set_action("AddForce", id=self.id, force=force)
self.env._step()

def setVelocity(self, vel: list):
self.env.instance_channel.set_action("SetVelocity", id=self.id, velocity=vel)
self.env._step()

def GenerateVHACDCollider(self):
self.env.instance_channel.set_action("GenerateVHACDColider", id=self.id)
self.env._step()
11 changes: 0 additions & 11 deletions pyrcareworld/pyrcareworld/sensors/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def initializeRGBWithIntrinsic(self):
self.env.instance_channel.set_action(
"GetRGB", id=self.id, intrinsic_matrix=self.intrinsic_matrix
)
self.env._step()
self.is_initialized.append("rgb_intrinsic")

def initializeRGB(self):
Expand All @@ -67,7 +66,6 @@ def initializeRGB(self):
"GetRGB", id=self.id, width=self.width, height=self.height
)
self.is_initialized.append("rgb_wh")
self.env._step()

def getRGB(self):
"""
Expand All @@ -87,7 +85,6 @@ def initializeDepthEXRWithIntrinsic(self):
id=self.id,
intrinsic_matrix=self.intrinsic_matrix,
)
self.env._step()
self.is_initialized.append("depth_intrinsic")

def initializeDepthEXR(self):
Expand All @@ -108,7 +105,6 @@ def initializeDepthEXR(self):
"GetDepthEXR", id=self.id, width=self.width, height=self.height
)
self.is_initialized.append("depth_wh")
self.env._step()

def getDepthEXR(self):
"""
Expand All @@ -124,7 +120,6 @@ def initializeNormalWithIntrinsic(self):
self.env.instance_channel.set_action(
"GetNormal", id=self.id, intrinsic_matrix=self.intrinsic_matrix
)
self.env._step()
self.is_initialized.append("normal_intrinsic")

def initializeNormal(self):
Expand All @@ -145,7 +140,6 @@ def initializeNormal(self):
"GetNormal", id=self.id, width=self.width, height=self.height
)
self.is_initialized.append("normal_wh")
self.env._step()

def getNormal(self):
"""
Expand All @@ -161,7 +155,6 @@ def initializeInstanceMaskWithIntrinsic(self):
self.env.instance_channel.set_action(
"GetID", id=self.id, intrinsic_matrix=self.intrinsic_matrix
)
self.env._step()
self.is_initialized.append("instance_intrinsic")

def initializeInstanceMask(self, w, h, fov=None):
Expand All @@ -178,7 +171,6 @@ def initializeInstanceMask(self, w, h, fov=None):
"GetID", id=self.id, width=self.width, height=self.height
)
self.is_initialized.append("instance_wh")
self.env._step()

def getInstanceMask(self):
"""
Expand All @@ -196,7 +188,6 @@ def initializeAmodalMaskWithIntrinsic(self):
self.env.instance_channel.set_action(
"GetAmodalMask", id=self.id, intrinsic_matrix=self.intrinsic_matrix
)
self.env._step()
self.is_initialized.append("amodal_intrinsic")

def initializeAmodalMask(self, w, h, fov=None):
Expand All @@ -217,7 +208,6 @@ def initializeAmodalMask(self, w, h, fov=None):
"GetAmodalMask", id=self.id, width=self.width, height=self.height
)
self.is_initialized.append("amodal_wh")
self.env._step()

def getAmodalMask(self):
"""
Expand All @@ -239,7 +229,6 @@ def initializeActiveDepthWithIntrinsic(self, ir_intrinsic_matrix):
main_intrinsic_matrix=self.intrinsic_matrix,
ir_intrinsic_matrix=ir_intrinsic_matrix,
)
self.env._step()
self.is_initialized.append("active_intrinsic")

def getActiveDepth(self):
Expand Down

0 comments on commit 7000069

Please sign in to comment.