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

Mode_indicator of GNS instead of the gps_qual from GGA sentence #150

Merged
merged 3 commits into from
Aug 14, 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
2 changes: 1 addition & 1 deletion field_friend/automations/automation_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def stop(self, reason: str) -> None:
def try_resume(self) -> None:
# Set conditions to True by default, which means they don't block the process if the watch is not active
bumper_condition = not bool(self.field_friend.bumper.active_bumpers) if self.bumper_watch_active else True
gnss_condition = (self.gnss.current is not None and self.gnss.current.gps_qual == 4) \
gnss_condition = (self.gnss.current is not None and ('R' in self.gnss.current.mode or self.gnss.current.mode == "SSSS")) \
if self.gnss_watch_active else True

# Enable automator only if all relevant conditions are True
Expand Down
6 changes: 3 additions & 3 deletions field_friend/automations/field_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def add_field_point(self, field: Field, point: Optional[GeoPoint] = None,
if positioning is None or positioning.lat == 0 or positioning.long == 0:
rosys.notify("No GNSS position.")
return
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":
rosys.notify("GNSS position is not accurate enough.")
return
new_point = positioning
Expand All @@ -172,7 +172,7 @@ def add_obstacle_point(self, field: Field, obstacle: FieldObstacle, point: Optio
if positioning is None or positioning.lat == 0 or positioning.long == 0:
rosys.notify("No GNSS position.")
return
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":
rosys.notify("GNSS position is not accurate enough.")
return
new_point = positioning
Expand Down Expand Up @@ -201,7 +201,7 @@ def add_row_point(self, field: Field, row: Row, point: Optional[GeoPoint] = None
if positioning is None or positioning.lat == 0 or positioning.long == 0:
rosys.notify("No GNSS position.")
return
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":
rosys.notify("GNSS position is not accurate enough.")
return
new_point = positioning
Expand Down
7 changes: 4 additions & 3 deletions field_friend/interface/components/field_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def find_first_row(self) -> None:

def get_infos(self) -> None:
assert self.gnss.current is not None
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":
with self.content:
ui.label('No RTK fix available.').classes('text-red')
self.first_row_start = self.gnss.current.location
Expand Down Expand Up @@ -103,7 +103,7 @@ def find_row_ending(self) -> None:

def drive_to_last_row(self) -> None:
assert self.gnss.current is not None
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":
with self.content:
ui.label('No RTK fix available.').classes('text-red')
self.first_row_end = self.gnss.current.location
Expand All @@ -119,7 +119,8 @@ def drive_to_last_row(self) -> None:

def confirm_geometry(self) -> None:
assert self.gnss.current is not None
if self.gnss.current.gps_qual != 4:
if "R" in self.gnss.current.mode or self.gnss.current.mode == "SSSS":

with self.content:
ui.label('No RTK fix available.').classes('text-red')
self.last_row_end = self.gnss.current.location
Expand Down
4 changes: 2 additions & 2 deletions field_friend/localization/gnss.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def check_gnss(self) -> None:
self.log.warning('new GNSS record is None')
self.GNSS_CONNECTION_LOST.emit()
return
if previous.gps_qual == 4 and self.current.gps_qual != 4:
if ("R" in previous.mode or previous.mode == "SSSS") and ("R" not in self.current.mode and self.current.mode != "SSSS"):
self.log.warning('GNSS RTK fix lost')
self.ROBOT_GNSS_POSITION_CHANGED.emit(self.current.location)
self.RTK_FIX_LOST.emit()
Expand All @@ -85,7 +85,7 @@ async def check_gnss(self) -> None:
try:
# TODO also do antenna_offset correction for this event
self.ROBOT_GNSS_POSITION_CHANGED.emit(self.current.location)
if self.current.gps_qual == 4: # 4 = RTK fixed (cm accuracy), 5 = RTK float (dm accuracy)
if "R" in self.current.mode or self.current.mode == "SSSS":
self._on_rtk_fix()
except Exception:
self.log.exception('gnss record could not be applied')
Expand Down
2 changes: 2 additions & 0 deletions field_friend/localization/gnss_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, odometer: rosys.driving.Odometer, wheels: rosys.hardware.Whee
self.wheels = wheels
self.allow_connection = True
self.gps_quality = 4
self.mode = 'SSSS'

async def try_connection(self) -> None:
if self.allow_connection:
Expand All @@ -28,6 +29,7 @@ async def _create_new_record(self) -> Optional[GNSSRecord]:
record = GNSSRecord(timestamp=pose.time, location=new_position)
record.mode = "simulation" # TODO check for possible values and replace "simulation"
record.gps_qual = self.gps_quality
record.mode = self.mode
await rosys.sleep(0.1) # NOTE simulation does not be so fast and only eats a lot of cpu time
return record

Expand Down
16 changes: 12 additions & 4 deletions tests/test_gnss.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,31 @@ async def test_driving(gnss_driving: System):

async def test_connection_lost(gnss_driving: System, gnss: GnssSimulation):
await forward(x=2.0)
gnss.gps_quality = 0
gnss.mode = 'NNNN'
await forward(3)
# robot should have stopped driving
assert_point(gnss_driving.odometer.prediction.point, rosys.geometry.Point(x=2.0, y=0))
gnss.gps_quality = 4
gnss.mode = "RRRR"
await forward(5)
# robot should continue driving
assert gnss_driving.odometer.prediction.point.x > 2.5


async def test_simulated_rtk(gnss_driving: System, gnss: GnssSimulation):
await forward(x=2.0)
gnss.mode = 'SSSS'
assert_point(gnss_driving.odometer.prediction.point, rosys.geometry.Point(x=2.0, y=0))
await forward(5)
assert gnss_driving.odometer.prediction.point.x > 2.5


async def test_rtk_lost(gnss_driving: System, gnss: GnssSimulation):
await forward(x=2.0)
gnss.gps_quality = 5
gnss.mode = 'FFFF'
await forward(3)
# robot should have stopped driving
assert_point(gnss_driving.odometer.prediction.point, rosys.geometry.Point(x=2.0, y=0))
gnss.gps_quality = 4
gnss.mode = "RFFF"
await forward(5)
# robot should continue driving
assert gnss_driving.odometer.prediction.point.x > 2.5
Expand Down
Loading