Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ramps and jumps #17

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/hippopt/robot_planning/utilities/terrain_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TerrainDescriptor(abc.ABC):
_height_function: cs.Function | None = dataclasses.field(default=None)
_normal_direction_function: cs.Function | None = dataclasses.field(default=None)
_orientation_function: cs.Function | None = dataclasses.field(default=None)
_transform_function: cs.Function | None = dataclasses.field(default=None)
_point_position_name: str = dataclasses.field(default="point_position")
_name: str = dataclasses.field(default=None)
_options: dict = dataclasses.field(default_factory=dict)
Expand Down Expand Up @@ -78,6 +79,25 @@ def create_orientation_function(self) -> cs.Function:
self._options,
)

def create_transform_function(self) -> cs.Function:
point_position = cs.MX.sym(self.get_point_position_name(), 3)
height = self.height_function()(point_position)
rotation = self.orientation_function()(point_position)

point_on_surface = cs.vertcat(point_position[:2], point_position[2] - height)
top_rows = cs.horzcat(rotation, point_on_surface)
fourth_row = cs.DM.eye(4)[3, :]
transform_matrix = cs.vertcat(top_rows, fourth_row)

return cs.Function(
"terrain_transform",
[point_position],
[transform_matrix],
[self.get_point_position_name()],
["plane_transform"],
self._options,
)

def height_function(self) -> cs.Function:
if not isinstance(self._height_function, cs.Function):
self._height_function = self.create_height_function()
Expand All @@ -96,6 +116,12 @@ def orientation_function(self) -> cs.Function:

return self._orientation_function

def transform_function(self) -> cs.Function:
if not isinstance(self._transform_function, cs.Function):
self._transform_function = self.create_transform_function()

return self._transform_function

def get_point_position_name(self) -> str:
return self._point_position_name

Expand All @@ -109,3 +135,4 @@ def invalidate_functions(self) -> None:
self._height_function = None
self._normal_direction_function = None
self._orientation_function = None
self._transform_function = None
Loading
Loading