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

State estimation filter client example #144

Merged
merged 2 commits into from
Sep 28, 2023
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
13 changes: 0 additions & 13 deletions py/examples/camera_client/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions py/examples/filter_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Amiga State Estimation Filter example

URL: https://amiga.farm-ng.com/docs/examples/filter_client/
66 changes: 66 additions & 0 deletions py/examples/filter_client/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Example of a state estimation filter service client."""
# Copyright (c) farm-ng, inc.
#
# Licensed under the Amiga Development Kit License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/farm-ng/amiga-dev-kit/blob/main/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import argparse
import asyncio
from pathlib import Path

from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig
from farm_ng.core.events_file_reader import proto_from_json_file
from farm_ng.core.stamp import get_stamp_by_semantics_and_clock_type
from farm_ng.core.stamp import StampSemantics
from farm_ng_core_pybind import Pose3F64


async def main(service_config_path: Path) -> None:
"""Run the filter service client.

Args:
service_config_path (Path): The path to the filter service config.
"""
# create a client to the filter service
config: EventServiceConfig = proto_from_json_file(service_config_path, EventServiceConfig())

async for event, message in EventClient(config).subscribe(config.subscriptions[0], decode=True):
# Find the monotonic driver receive timestamp, or the first timestamp if not available.
stamp = (
get_stamp_by_semantics_and_clock_type(event, StampSemantics.DRIVER_RECEIVE, "monotonic")
or event.timestamps[0].stamp
)

# Unpack the filter state message
pose: Pose3F64 = Pose3F64.from_proto(message.pose)
orientation: float = message.heading
uncertainties: list[float] = [message.uncertainty_diagonal.data[i] for i in range(3)]

# Print some key details about the filter state
print("\n###################")
print(f"Timestamp: {stamp}")
print("Filter state received with pose:")
print(f"x: {pose.translation[0]:.3f} m, y: {pose.translation[1]:.3f} m, orientation: {orientation:.3f} rad")
print(f"Parent frame: {pose.frame_a} -> Child frame: {pose.frame_b}")
print(f"Filter has converged: {message.has_converged}")
print("And pose uncertainties:")
print(f"x: {uncertainties[0]:.3f} m, y: {uncertainties[1]:.3f} m, orientation: {uncertainties[2]:.3f} rad")


if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="amiga-filter-stream")
parser.add_argument("--service-config", type=Path, required=True, help="The filter service config.")
args = parser.parse_args()

asyncio.run(main(args.service_config))
1 change: 1 addition & 0 deletions py/examples/filter_client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
farm-ng-amiga
15 changes: 15 additions & 0 deletions py/examples/filter_client/service_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "filter",
"port": 20001,
"host": "localhost",
"log_level": "INFO",
"subscriptions": [
{
"uri": {
"path": "/state",
"query": "service_name=filter"
},
"every_n": 1
}
]
}