Skip to content

Commit 24c42ed

Browse files
committed
(feature) Adds method to get robot height from geometry
1 parent dc94c42 commit 24c42ed

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/kompass_core/models.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ class ParamsLength(Enum):
730730
BOX = 3 # (x, y, z) Axis-aligned box with given side lengths
731731
CYLINDER = 2 # (rad, lz) Cylinder with given radius and height along z-axis
732732
SPHERE = 1 # (rad) Sphere with given radius
733-
ELLIPSOID = 3 # (x, y, z) Axis-aligned ellipsoid with given radis
733+
ELLIPSOID = 3 # (x, y, z) Axis-aligned ellipsoid with given radius
734734
CAPSULE = 2 # (rad, lz) Capsule with given radius and height along z-axis
735735
CONE = 2 # (rad, lz) Cone with given radius and height along z-axis
736736

@@ -805,6 +805,36 @@ def get_radius(cls, geometry_type: Type, parameters: np.ndarray) -> float:
805805
else:
806806
return np.sqrt(parameters[1] + parameters[0]) / 2
807807

808+
@classmethod
809+
def get_height(cls, geometry_type: Type, parameters: np.ndarray) -> float:
810+
"""
811+
Gets the robot height from the geometry
812+
813+
:param geometry_type: Robot Geometry Type
814+
:type geometry_type: Type
815+
:param parameters: Robot Geometry Parameters
816+
:type parameters: np.ndarray
817+
818+
:return: Robot height if the parameters are valid, else None
819+
:rtype: Optional[float]
820+
"""
821+
if not cls.is_valid_parameters(geometry_type, parameters):
822+
raise ValueError("Invalid parameters for the robot geometry")
823+
if geometry_type in [
824+
cls.Type.CONE,
825+
cls.Type.CYLINDER,
826+
cls.Type.CAPSULE,
827+
cls.Type.ELLIPSOID,
828+
]:
829+
# Last parameter is the height
830+
return parameters[-1]
831+
elif geometry_type == cls.Type.SPHERE:
832+
# Return sphere height
833+
return parameters[0] * 2.0
834+
else:
835+
# return BOX height
836+
return parameters[0]
837+
808838
@classmethod
809839
def get_length(cls, geometry_type: Type, parameters: np.ndarray) -> Optional[float]:
810840
"""
@@ -1290,6 +1320,16 @@ def radius(self) -> float:
12901320
"""
12911321
return RobotGeometry.get_radius(self.geometry_type, self.geometry_params)
12921322

1323+
@property
1324+
def height(self) -> float:
1325+
"""
1326+
Gets the robot height
1327+
1328+
:return: Height (meters)
1329+
:rtype: float
1330+
"""
1331+
return RobotGeometry.get_height(self.geometry_type, self.geometry_params)
1332+
12931333
@property
12941334
def wheelbase(self) -> float:
12951335
"""

0 commit comments

Comments
 (0)