Skip to content

Commit

Permalink
Fixed Bugs in types.py
Browse files Browse the repository at this point in the history
Lidar Class Fix, implemented to_msgpack for array packing, fixed ImageResponse
  • Loading branch information
JulianDev24 authored Aug 17, 2024
1 parent 9f6d872 commit 9c79e38
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions PythonClient/airsim/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ def __repr__(self):
return "<" + type(self).__name__ + "> " + pformat(vars(self), indent=4, width=1)

def to_msgpack(self, *args, **kwargs):
return self.__dict__
encoded = []
for attr_name, attr_type in self.attribute_order:
value = getattr(self, attr_name)
if isinstance(value, list) and value and isinstance(value[0], MsgpackMixin):
encoded.append([v.to_msgpack() for v in value])
elif isinstance(value, MsgpackMixin):
encoded.append(value.to_msgpack())
else:
encoded.append(value)
return encoded

@classmethod
def from_msgpack(cls, encoded):
Expand Down Expand Up @@ -435,8 +444,9 @@ def __init__(self, camera_name, image_type, pixels_as_float=False, compress=True


class ImageResponse(MsgpackMixin):
image_data_uint8 = np.uint8(0)
image_data_float = 0.0
image_data_uint8 = np.array([], dtype=np.uint8)
image_data_float = np.array([], dtype=float)
camera_name = ''
camera_position = Vector3r()
camera_orientation = Quaternionr()
time_stamp = np.uint64(0)
Expand All @@ -449,8 +459,9 @@ class ImageResponse(MsgpackMixin):

attribute_order = [
('image_data_uint8', np.ndarray),
('image_data_float', float),
('image_data_float', np.ndarray),
('camera_position', Vector3r),
('camera_name', str),
('camera_orientation', Quaternionr),
('time_stamp', np.uint64),
('message', str),
Expand Down Expand Up @@ -614,14 +625,14 @@ class CameraInfo(MsgpackMixin):


class LidarData(MsgpackMixin):
point_cloud = 0.0
time_stamp = np.uint64(0)
point_cloud = 0.0
pose = Pose()
segmentation = 0

attribute_order = [
('point_cloud', float),
('time_stamp', np.uint64),
('point_cloud', float),
('pose', Pose),
('segmentation', int)
]
Expand Down

0 comments on commit 9c79e38

Please sign in to comment.