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

fix: resolve ValueError if there is no observed NavSatFix messages #175

Merged
merged 2 commits into from
Dec 9, 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
10 changes: 7 additions & 3 deletions perception_dataset/ros2/oxts_msgs/ins_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,20 @@ def get_odometries(self) -> List[Odometry]:
def get_imus(self) -> List[Imu]:
return self._buffer["imu"]

def lookup_nav_sat_fixes(self, stamp: RosTime) -> NavSatFix:
def lookup_nav_sat_fixes(self, stamp: RosTime) -> Optional[NavSatFix]:
return self.interpolate_nav_sat_fixes(stamp)

def interpolate_nav_sat_fixes(
self, query_stamp: Union[RosTime, List[RosTime]]
) -> Union[NavSatFix | List[NavSatFix]]:
) -> Optional[Union[NavSatFix | List[NavSatFix]]]:
"""Interpolate NavSatFix.

Args:
query_stamp (RosTime | List[RosTime]): Query stamp(s).

Returns:
Union[NavSatFix, List[NavSatFix]]: Interpolated message(s).
Optional[Union[NavSatFix, List[NavSatFix]]]: Interpolated message(s).
Note that it returns `None`, if there is no observed NavSatFix messages.

Warnings:
If the value in `query_stamps` is out of range of the observed timestamps,
Expand All @@ -454,6 +455,9 @@ def interpolate_nav_sat_fixes(
timestamps.append(stamp_to_unix_timestamp(msg.header.stamp))
geo_coordinates.append((msg.latitude, msg.longitude, msg.altitude))

if len(timestamps) == 0:
return None

if min(query_timestamps) < min(timestamps) or max(timestamps) < max(query_timestamps):
warnings.warn(
"The value in `query_timestamps` is out of range of the observed timestamps, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,15 @@ def _generate_ego_pose(self, stamp: builtin_interfaces.msg.Time) -> str:
"ay": ego_state.accel.y,
"az": ego_state.accel.z,
},
geocoordinate={
"latitude": geocoordinate.latitude,
"longitude": geocoordinate.longitude,
"altitude": geocoordinate.altitude,
},
geocoordinate=(
{
"latitude": geocoordinate.latitude,
"longitude": geocoordinate.longitude,
"altitude": geocoordinate.altitude,
}
if geocoordinate is not None
else None
),
)
else:
transform_stamped = self._bag_reader.get_transform_stamped(
Expand Down
Loading