Skip to content

Commit

Permalink
Improved patterns on variables
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Jan 19, 2024
1 parent 12480c5 commit 57e4b49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
22 changes: 9 additions & 13 deletions src/hippopt/robot_planning/variables/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ class ContactPointState(OptimizationObject):
)

def __post_init__(self, input_descriptor: ContactPointDescriptor) -> None:
if self.p is None:
self.p = np.zeros(3)

if self.f is None:
self.f = np.zeros(3)

self.p = np.zeros(3) if self.p is None else self.p
self.f = np.zeros(3) if self.f is None else self.f
if input_descriptor is not None:
self.descriptor = input_descriptor

Expand All @@ -94,11 +90,8 @@ class ContactPointStateDerivative(OptimizationObject):
f_dot: StorageType = default_storage_field(OverridableVariable)

def __post_init__(self) -> None:
if self.v is None:
self.v = np.zeros(3)

if self.f_dot is None:
self.f_dot = np.zeros(3)
self.v = np.zeros(3) if self.v is None else self.v
self.f_dot = np.zeros(3) if self.f_dot is None else self.f_dot


TFootContactState = TypeVar("TFootContactState", bound="FootContactState")
Expand Down Expand Up @@ -154,10 +147,13 @@ class FootContactPhaseDescriptor:
deactivation_time: float | None = dataclasses.field(default=None)

def __post_init__(self) -> None:
if self.transform is None:
self.transform = liecasadi.SE3.from_translation_and_rotation(
self.transform = (
liecasadi.SE3.from_translation_and_rotation(
cs.DM.zeros(3), liecasadi.SO3.Identity()
)
if self.transform is None
else self.transform
)
if self.force is None:
self.force = np.zeros(3)
self.force[2] = 100
Expand Down
17 changes: 10 additions & 7 deletions src/hippopt/robot_planning/variables/floating_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class FreeFloatingObjectState(OptimizationObject):
quaternion_xyzw: StorageType = default_storage_field(OverridableVariable)

def __post_init__(self):
if self.position is None:
self.position = np.zeros(3)
self.position = np.zeros(3) if self.position is None else self.position
if self.quaternion_xyzw is None:
self.quaternion_xyzw = np.zeros(4)
self.quaternion_xyzw[3] = 1.0
Expand All @@ -32,11 +31,15 @@ class FreeFloatingObjectStateDerivative(OptimizationObject):
quaternion_velocity_xyzw: StorageType = default_storage_field(OverridableVariable)

def __post_init__(self):
if self.linear_velocity is None:
self.linear_velocity = np.zeros(3)
self.linear_velocity = (
np.zeros(3) if self.linear_velocity is None else self.linear_velocity
)

if self.quaternion_velocity_xyzw is None:
self.quaternion_velocity_xyzw = np.zeros(4)
self.quaternion_velocity_xyzw = (
np.zeros(4)
if self.quaternion_velocity_xyzw is None
else self.quaternion_velocity_xyzw
)


@dataclasses.dataclass
Expand All @@ -53,7 +56,7 @@ class KinematicTreeState(OptimizationObject):
number_of_joints_state: dataclasses.InitVar[int] = dataclasses.field(default=0)

def __post_init__(self, number_of_joints_state: int):
if number_of_joints_state is not None:
if number_of_joints_state is not None and self.positions is None:
self.positions = np.zeros(number_of_joints_state)


Expand Down
3 changes: 1 addition & 2 deletions src/hippopt/robot_planning/variables/humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ def __post_init__(
self.kinematics = FloatingBaseSystemState(
number_of_joints_state=number_of_joints
)
if self.com is None:
self.com = np.zeros(3)
self.com = np.zeros(3) if self.com is None else self.com

0 comments on commit 57e4b49

Please sign in to comment.