ara-api-web 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ara_api_web-1.1.0/.gitignore +24 -0
- ara_api_web-1.1.0/LICENSE +21 -0
- ara_api_web-1.1.0/PKG-INFO +37 -0
- ara_api_web-1.1.0/README.md +5 -0
- ara_api_web-1.1.0/ara_api_web/__init__.py +5 -0
- ara_api_web-1.1.0/ara_api_web/__main__.py +26 -0
- ara_api_web-1.1.0/ara_api_web/_core/__init__.py +6 -0
- ara_api_web-1.1.0/ara_api_web/_core/app.py +34 -0
- ara_api_web-1.1.0/ara_api_web/_core/dependencies.py +0 -0
- ara_api_web-1.1.0/ara_api_web/_core/models/__init__.py +45 -0
- ara_api_web-1.1.0/ara_api_web/_core/models/requests.py +29 -0
- ara_api_web-1.1.0/ara_api_web/_core/models/responses.py +108 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/__init__.py +1 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/api/__init__.py +0 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/api/msp.py +175 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/api/navigation.py +113 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/api/vision.py +52 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/health.py +12 -0
- ara_api_web-1.1.0/ara_api_web/_core/routers/status.py +0 -0
- ara_api_web-1.1.0/ara_api_web/_core/server.py +63 -0
- ara_api_web-1.1.0/ara_api_web/_utils/__init__.py +76 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/__init__.py +90 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/gRPCSync.py +237 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/base_msg_pb2.py +44 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/base_msg_pb2_grpc.py +24 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/msp_msg_pb2.py +57 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/msp_msg_pb2_grpc.py +24 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/nav_msg_pb2.py +34 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/nav_msg_pb2_grpc.py +24 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/vision_msg_pb2.py +51 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/messages/vision_msg_pb2_grpc.py +24 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/msp_pb2.py +38 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/msp_pb2_grpc.py +539 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/navigation_pb2.py +38 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/navigation_pb2_grpc.py +275 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/vision_pb2.py +38 -0
- ara_api_web-1.1.0/ara_api_web/_utils/communication/grpc/vision_pb2_grpc.py +275 -0
- ara_api_web-1.1.0/ara_api_web/_utils/config.py +51 -0
- ara_api_web-1.1.0/ara_api_web/_utils/decorators.py +53 -0
- ara_api_web-1.1.0/ara_api_web/_utils/logger.py +191 -0
- ara_api_web-1.1.0/ara_api_web/_utils/rest_helpers.py +52 -0
- ara_api_web-1.1.0/ara_api_web/_utils/ui.py +119 -0
- ara_api_web-1.1.0/pyproject.toml +49 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
|
|
15
|
+
# Editor directories and files
|
|
16
|
+
.vscode/*
|
|
17
|
+
!.vscode/extensions.json
|
|
18
|
+
.idea
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.suo
|
|
21
|
+
*.ntvs*
|
|
22
|
+
*.njsproj
|
|
23
|
+
*.sln
|
|
24
|
+
*.sw?
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alexander Kleimenov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ara-api-web
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Web interface for ARA API
|
|
5
|
+
Author-email: Alexander Kleimenov <nequamy@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: API,ARA,drones,robotics
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: Unix
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Software Development
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Requires-Dist: fastapi<0.122.0,>=0.100.0; python_version < '3.9'
|
|
25
|
+
Requires-Dist: fastapi<0.122.0,>=0.121.1; python_version >= '3.9'
|
|
26
|
+
Requires-Dist: grpcio-tools==1.66.2
|
|
27
|
+
Requires-Dist: grpcio==1.69.0
|
|
28
|
+
Requires-Dist: rich>=14.2.0
|
|
29
|
+
Requires-Dist: uvicorn<0.28.0,>=0.20.0; python_version == '3.8'
|
|
30
|
+
Requires-Dist: uvicorn<0.40.0,>=0.30.0; python_version >= '3.9'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# Vue 3 + TypeScript + Vite
|
|
34
|
+
|
|
35
|
+
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
|
36
|
+
|
|
37
|
+
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Vue 3 + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
|
4
|
+
|
|
5
|
+
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from email.policy import default
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from ara_api_web._core.server import run_server
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@click.command
|
|
9
|
+
@click.option(
|
|
10
|
+
"--host",
|
|
11
|
+
default="0.0.0.0",
|
|
12
|
+
help="Адрес хоста для сервера",
|
|
13
|
+
show_default=True,
|
|
14
|
+
)
|
|
15
|
+
@click.option(
|
|
16
|
+
"--port",
|
|
17
|
+
default=8080,
|
|
18
|
+
help="Порт для сервера",
|
|
19
|
+
show_default=True,
|
|
20
|
+
)
|
|
21
|
+
def main(host: str, port: int):
|
|
22
|
+
run_server(host=host, port=port)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from fastapi import FastAPI
|
|
2
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
3
|
+
from fastapi.staticfiles import StaticFiles
|
|
4
|
+
|
|
5
|
+
from ara_api_web._core.routers import health
|
|
6
|
+
from ara_api_web._core.routers.api import msp, navigation, vision
|
|
7
|
+
from ara_api_web._utils.config import STATIC_DIR
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def create_app() -> FastAPI:
|
|
11
|
+
app = FastAPI(
|
|
12
|
+
title="ARA API Web Interface",
|
|
13
|
+
description="REST API wrapper for ARA drone control system",
|
|
14
|
+
version="1.1.0", # ! HARD VERSION
|
|
15
|
+
docs_url=None,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
app.add_middleware(
|
|
19
|
+
CORSMiddleware,
|
|
20
|
+
allow_origins=["*"],
|
|
21
|
+
allow_credentials=True,
|
|
22
|
+
allow_methods=["*"],
|
|
23
|
+
allow_headers=["*"],
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
app.include_router(router=health.router)
|
|
27
|
+
app.include_router(router=msp.router)
|
|
28
|
+
app.include_router(router=navigation.router)
|
|
29
|
+
app.include_router(router=vision.router)
|
|
30
|
+
|
|
31
|
+
if STATIC_DIR.exists():
|
|
32
|
+
app.mount("/", StaticFiles(directory=str(STATIC_DIR), html=True), name="static")
|
|
33
|
+
|
|
34
|
+
return app
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from ara_api_web._core.models.requests import (
|
|
2
|
+
LandRequest,
|
|
3
|
+
MoveRequest,
|
|
4
|
+
TakeoffRequest,
|
|
5
|
+
VelocityRequest,
|
|
6
|
+
)
|
|
7
|
+
from ara_api_web._core.models.responses import (
|
|
8
|
+
AltitudeResponse,
|
|
9
|
+
ArucoResponse,
|
|
10
|
+
AttitudeResponse,
|
|
11
|
+
BatteryResponse,
|
|
12
|
+
BlobResponse,
|
|
13
|
+
ImageResponse,
|
|
14
|
+
IMUResponse,
|
|
15
|
+
MotorResponse,
|
|
16
|
+
OpticalFlowResponse,
|
|
17
|
+
PositionResponse,
|
|
18
|
+
QRResponse,
|
|
19
|
+
SonarResponse,
|
|
20
|
+
StatusResponse,
|
|
21
|
+
VelocityResponse,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
# Requests
|
|
26
|
+
"TakeoffRequest",
|
|
27
|
+
"LandRequest",
|
|
28
|
+
"MoveRequest",
|
|
29
|
+
"VelocityRequest",
|
|
30
|
+
# Responses
|
|
31
|
+
"StatusResponse",
|
|
32
|
+
"IMUResponse",
|
|
33
|
+
"MotorResponse",
|
|
34
|
+
"AttitudeResponse",
|
|
35
|
+
"AltitudeResponse",
|
|
36
|
+
"SonarResponse",
|
|
37
|
+
"OpticalFlowResponse",
|
|
38
|
+
"PositionResponse",
|
|
39
|
+
"VelocityResponse",
|
|
40
|
+
"BatteryResponse",
|
|
41
|
+
"ImageResponse",
|
|
42
|
+
"ArucoResponse",
|
|
43
|
+
"BlobResponse",
|
|
44
|
+
"QRResponse",
|
|
45
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# =====================================================================
|
|
7
|
+
# NAVIGATION REST SERVICE MODELS
|
|
8
|
+
# =====================================================================
|
|
9
|
+
class TakeoffRequest(BaseModel):
|
|
10
|
+
altitude: float = Field(..., gt=0, description="Takeoff altitude in meters")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LandRequest(BaseModel):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MoveRequest(BaseModel):
|
|
18
|
+
x: float = Field(..., description="X coordinate in meters")
|
|
19
|
+
y: float = Field(..., description="Y coordinate in meters")
|
|
20
|
+
z: float = Field(..., description="Z coordinate in meters")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class VelocityRequest(BaseModel):
|
|
24
|
+
vx: float = Field(..., description="X velocity in m/s")
|
|
25
|
+
vy: float = Field(..., description="Y velocity in m/s")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AltitudeRequest(BaseModel):
|
|
29
|
+
altitude: float = Field(..., gt=0, description="Target altitude in meters")
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class StatusResponse(BaseModel):
|
|
7
|
+
status: str
|
|
8
|
+
details: Optional[str] = None
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# =====================================================================
|
|
12
|
+
# MSP REST SERVICE MODELS
|
|
13
|
+
# =====================================================================
|
|
14
|
+
class IMUResponse(BaseModel):
|
|
15
|
+
gyro_x: Optional[float] = None
|
|
16
|
+
gyro_y: Optional[float] = None
|
|
17
|
+
gyro_z: Optional[float] = None
|
|
18
|
+
acc_x: Optional[float] = None
|
|
19
|
+
acc_y: Optional[float] = None
|
|
20
|
+
acc_z: Optional[float] = None
|
|
21
|
+
error: Optional[str] = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MotorResponse(BaseModel):
|
|
25
|
+
data: Optional[list] = None
|
|
26
|
+
error: Optional[str] = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AttitudeResponse(BaseModel):
|
|
30
|
+
roll: Optional[float] = None
|
|
31
|
+
pitch: Optional[float] = None
|
|
32
|
+
yaw: Optional[float] = None
|
|
33
|
+
error: Optional[str] = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AltitudeResponse(BaseModel):
|
|
37
|
+
altitude: Optional[float] = None
|
|
38
|
+
error: Optional[str] = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class SonarResponse(BaseModel):
|
|
42
|
+
data: Optional[float] = None
|
|
43
|
+
error: Optional[str] = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class OpticalFlowResponse(BaseModel):
|
|
47
|
+
quitity: Optional[int] = None
|
|
48
|
+
flow_rate_x: Optional[float] = None
|
|
49
|
+
flow_rate_y: Optional[float] = None
|
|
50
|
+
body_rate_x: Optional[float] = None
|
|
51
|
+
body_rate_y: Optional[float] = None
|
|
52
|
+
error: Optional[str] = None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class PositionResponse(BaseModel):
|
|
56
|
+
x: Optional[float] = None
|
|
57
|
+
y: Optional[float] = None
|
|
58
|
+
z: Optional[float] = None
|
|
59
|
+
error: Optional[str] = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class VelocityResponse(BaseModel):
|
|
63
|
+
x: Optional[float] = None
|
|
64
|
+
y: Optional[float] = None
|
|
65
|
+
z: Optional[float] = None
|
|
66
|
+
error: Optional[str] = None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class BatteryResponse(BaseModel):
|
|
70
|
+
voltage: Optional[float] = None
|
|
71
|
+
cell_count: Optional[int] = None
|
|
72
|
+
capacity: Optional[int] = None
|
|
73
|
+
error: Optional[str] = None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# =====================================================================
|
|
77
|
+
# MSP REST SERVICE MODELS
|
|
78
|
+
# =====================================================================
|
|
79
|
+
class ImageResponse(BaseModel):
|
|
80
|
+
height: Optional[int] = None
|
|
81
|
+
weight: Optional[int] = None
|
|
82
|
+
data: Optional[bytes] = None
|
|
83
|
+
noise: Optional[float] = None
|
|
84
|
+
error: Optional[str] = None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ArucoResponse(BaseModel):
|
|
88
|
+
id: Optional[int] = None
|
|
89
|
+
pos_x: Optional[float] = None
|
|
90
|
+
pos_y: Optional[float] = None
|
|
91
|
+
pos_z: Optional[float] = None
|
|
92
|
+
orient_x: Optional[float] = None
|
|
93
|
+
orient_y: Optional[float] = None
|
|
94
|
+
orient_z: Optional[float] = None
|
|
95
|
+
error: Optional[str] = None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class BlobResponse(BaseModel):
|
|
99
|
+
id: Optional[int] = None
|
|
100
|
+
pos_x: Optional[float] = None
|
|
101
|
+
pos_y: Optional[float] = None
|
|
102
|
+
size: Optional[float] = None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class QRResponse(BaseModel):
|
|
106
|
+
data: Optional[int] = None
|
|
107
|
+
pos_x: Optional[float] = None
|
|
108
|
+
pos_y: Optional[float] = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends
|
|
2
|
+
|
|
3
|
+
from ara_api_web._core.models import (
|
|
4
|
+
AltitudeResponse,
|
|
5
|
+
AttitudeResponse,
|
|
6
|
+
BatteryResponse,
|
|
7
|
+
IMUResponse,
|
|
8
|
+
MotorResponse,
|
|
9
|
+
OpticalFlowResponse,
|
|
10
|
+
PositionResponse,
|
|
11
|
+
SonarResponse,
|
|
12
|
+
VelocityResponse,
|
|
13
|
+
)
|
|
14
|
+
from ara_api_web._utils import (
|
|
15
|
+
get_grpc_client,
|
|
16
|
+
get_logger,
|
|
17
|
+
handle_grpc_errors,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
router: APIRouter = APIRouter(prefix="/api/msp", tags=["MSP"])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@router.get("/imu", response_model=IMUResponse)
|
|
24
|
+
@handle_grpc_errors
|
|
25
|
+
async def get_imu(
|
|
26
|
+
grpc_client=Depends(get_grpc_client),
|
|
27
|
+
logger=Depends(get_logger),
|
|
28
|
+
) -> IMUResponse:
|
|
29
|
+
imu_data = grpc_client.msp_get_raw_imu()
|
|
30
|
+
|
|
31
|
+
if imu_data is None:
|
|
32
|
+
return IMUResponse(error="Failed to retrieve IMU data")
|
|
33
|
+
|
|
34
|
+
return IMUResponse(
|
|
35
|
+
gyro_x=imu_data.gyro.x,
|
|
36
|
+
gyro_y=imu_data.gyro.y,
|
|
37
|
+
gyro_z=imu_data.gyro.z,
|
|
38
|
+
acc_x=imu_data.acc.x,
|
|
39
|
+
acc_y=imu_data.acc.y,
|
|
40
|
+
acc_z=imu_data.acc.z,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@router.get("/altitude", response_model=AltitudeResponse)
|
|
45
|
+
@handle_grpc_errors
|
|
46
|
+
async def get_altitude(
|
|
47
|
+
grpc_client=Depends(get_grpc_client),
|
|
48
|
+
logger=Depends(get_logger),
|
|
49
|
+
) -> AltitudeResponse:
|
|
50
|
+
altitude_data = grpc_client.msp_get_altitude()
|
|
51
|
+
|
|
52
|
+
if altitude_data is None:
|
|
53
|
+
return AltitudeResponse(error="Failed to retrieve altitude")
|
|
54
|
+
|
|
55
|
+
return AltitudeResponse(altitude=altitude_data.data)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@router.get("/position", response_model=PositionResponse)
|
|
59
|
+
@handle_grpc_errors
|
|
60
|
+
async def get_position(
|
|
61
|
+
grpc_client=Depends(get_grpc_client),
|
|
62
|
+
logger=Depends(get_logger),
|
|
63
|
+
) -> PositionResponse:
|
|
64
|
+
position_data = grpc_client.msp_get_position()
|
|
65
|
+
|
|
66
|
+
if position_data is None:
|
|
67
|
+
return PositionResponse(error="Failed to retrieve position")
|
|
68
|
+
|
|
69
|
+
return PositionResponse(
|
|
70
|
+
x=position_data.data.x,
|
|
71
|
+
y=position_data.data.y,
|
|
72
|
+
z=position_data.data.z,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@router.get("/attitude", response_model=AttitudeResponse)
|
|
77
|
+
@handle_grpc_errors
|
|
78
|
+
async def get_attitude(
|
|
79
|
+
grpc_client=Depends(get_grpc_client),
|
|
80
|
+
logger=Depends(get_logger),
|
|
81
|
+
) -> AttitudeResponse:
|
|
82
|
+
attitude_data = grpc_client.msp_get_attitude()
|
|
83
|
+
|
|
84
|
+
if attitude_data is None:
|
|
85
|
+
return AttitudeResponse(error="Failed to retrieve attitude")
|
|
86
|
+
|
|
87
|
+
return AttitudeResponse(
|
|
88
|
+
roll=attitude_data.data.x,
|
|
89
|
+
pitch=attitude_data.data.y,
|
|
90
|
+
yaw=attitude_data.data.z,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@router.get("/analog", response_model=BatteryResponse)
|
|
95
|
+
@handle_grpc_errors
|
|
96
|
+
async def get_analog(
|
|
97
|
+
grpc_client=Depends(get_grpc_client),
|
|
98
|
+
logger=Depends(get_logger),
|
|
99
|
+
) -> BatteryResponse:
|
|
100
|
+
analog_data = grpc_client.msp_get_analog()
|
|
101
|
+
|
|
102
|
+
if analog_data is None:
|
|
103
|
+
return BatteryResponse(error="Failed to retrieve analog data")
|
|
104
|
+
|
|
105
|
+
return BatteryResponse(
|
|
106
|
+
voltage=analog_data.voltage,
|
|
107
|
+
cell_count=None,
|
|
108
|
+
capacity=analog_data.mAhdrawn,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@router.get("/motor", response_model=MotorResponse)
|
|
113
|
+
@handle_grpc_errors
|
|
114
|
+
async def get_motor(
|
|
115
|
+
grpc_client=Depends(get_grpc_client),
|
|
116
|
+
logger=Depends(get_logger),
|
|
117
|
+
) -> MotorResponse:
|
|
118
|
+
motor_data = grpc_client.msp_get_motor()
|
|
119
|
+
|
|
120
|
+
if motor_data is None:
|
|
121
|
+
return MotorResponse(error="Failed to retrieve motor data")
|
|
122
|
+
|
|
123
|
+
return MotorResponse(data=motor_data.data)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@router.get("/optical_flow", response_model=OpticalFlowResponse)
|
|
127
|
+
@handle_grpc_errors
|
|
128
|
+
async def get_optical_flow(
|
|
129
|
+
grpc_client=Depends(get_grpc_client),
|
|
130
|
+
logger=Depends(get_logger),
|
|
131
|
+
) -> OpticalFlowResponse:
|
|
132
|
+
flow_data = grpc_client.msp_get_optical_flow()
|
|
133
|
+
|
|
134
|
+
if flow_data is None:
|
|
135
|
+
return OpticalFlowResponse(error="Failed to retrieve optical flow")
|
|
136
|
+
|
|
137
|
+
return OpticalFlowResponse(
|
|
138
|
+
quitity=flow_data.quality,
|
|
139
|
+
flow_rate_x=flow_data.flow_rate.x,
|
|
140
|
+
flow_rate_y=flow_data.flow_rate.y,
|
|
141
|
+
body_rate_x=flow_data.body_rate.x,
|
|
142
|
+
body_rate_y=flow_data.body_rate.y,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@router.get("/sonar", response_model=SonarResponse)
|
|
147
|
+
@handle_grpc_errors
|
|
148
|
+
async def get_sonar(
|
|
149
|
+
grpc_client=Depends(get_grpc_client),
|
|
150
|
+
logger=Depends(get_logger),
|
|
151
|
+
) -> SonarResponse:
|
|
152
|
+
sonar_data = grpc_client.msp_get_sonar()
|
|
153
|
+
|
|
154
|
+
if sonar_data is None:
|
|
155
|
+
return SonarResponse(error="Failed to retrieve sonar data")
|
|
156
|
+
|
|
157
|
+
return SonarResponse(data=sonar_data.data)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@router.get("/velocity", response_model=VelocityResponse)
|
|
161
|
+
@handle_grpc_errors
|
|
162
|
+
async def get_velocity(
|
|
163
|
+
grpc_client=Depends(get_grpc_client),
|
|
164
|
+
logger=Depends(get_logger),
|
|
165
|
+
) -> VelocityResponse:
|
|
166
|
+
position_data = grpc_client.msp_get_position()
|
|
167
|
+
|
|
168
|
+
if position_data is None:
|
|
169
|
+
return VelocityResponse(error="Failed to retrieve velocity")
|
|
170
|
+
|
|
171
|
+
return VelocityResponse(
|
|
172
|
+
x=position_data.data.x,
|
|
173
|
+
y=position_data.data.x,
|
|
174
|
+
z=position_data.data.x,
|
|
175
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends
|
|
2
|
+
|
|
3
|
+
from ara_api_web._core.models import (
|
|
4
|
+
LandRequest,
|
|
5
|
+
MoveRequest,
|
|
6
|
+
StatusResponse,
|
|
7
|
+
TakeoffRequest,
|
|
8
|
+
VelocityRequest,
|
|
9
|
+
)
|
|
10
|
+
from ara_api_web._utils import (
|
|
11
|
+
altitude_data,
|
|
12
|
+
get_grpc_client,
|
|
13
|
+
get_logger,
|
|
14
|
+
get_request,
|
|
15
|
+
handle_grpc_errors,
|
|
16
|
+
vector2,
|
|
17
|
+
vector3,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
router: APIRouter = APIRouter(prefix="/api/navigation", tags=["Navigation"])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@router.post("/takeoff", response_model=StatusResponse)
|
|
24
|
+
@handle_grpc_errors
|
|
25
|
+
async def takeoff(
|
|
26
|
+
request: TakeoffRequest,
|
|
27
|
+
grpc_client=Depends(get_grpc_client),
|
|
28
|
+
logger=Depends(get_logger),
|
|
29
|
+
) -> StatusResponse:
|
|
30
|
+
logger.debug(f"Takeoff command received: altitude={request.altitude}")
|
|
31
|
+
|
|
32
|
+
altitude_msg = altitude_data(data=request.altitude)
|
|
33
|
+
grpc_client.nav_cmd_takeoff(
|
|
34
|
+
altitude_msg,
|
|
35
|
+
[
|
|
36
|
+
("client-id", "grpc-sync|REST"),
|
|
37
|
+
],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return StatusResponse(
|
|
41
|
+
status="success",
|
|
42
|
+
details=f"Takeoff to {request.altitude}m initiated",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@router.post("/land", response_model=StatusResponse)
|
|
47
|
+
@handle_grpc_errors
|
|
48
|
+
async def land(
|
|
49
|
+
request: LandRequest,
|
|
50
|
+
grpc_client=Depends(get_grpc_client),
|
|
51
|
+
logger=Depends(get_logger),
|
|
52
|
+
) -> StatusResponse:
|
|
53
|
+
logger.debug("Landing command was called")
|
|
54
|
+
|
|
55
|
+
grpc_client.nav_cmd_land(
|
|
56
|
+
get_request(req="REST"),
|
|
57
|
+
[
|
|
58
|
+
("client-id", "grpc-sync|REST"),
|
|
59
|
+
],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return StatusResponse(
|
|
63
|
+
status="success",
|
|
64
|
+
details="Landing initiated",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@router.post("/move", response_model=StatusResponse)
|
|
69
|
+
@handle_grpc_errors
|
|
70
|
+
async def move(
|
|
71
|
+
request: MoveRequest,
|
|
72
|
+
grpc_client=Depends(get_grpc_client),
|
|
73
|
+
logger=Depends(get_logger),
|
|
74
|
+
) -> StatusResponse:
|
|
75
|
+
logger.info(f"Move command received: x={request.x}, y={request.y}, z={request.z}")
|
|
76
|
+
|
|
77
|
+
position_msg = vector3(x=request.x, y=request.y, z=request.z)
|
|
78
|
+
grpc_client.nav_cmd_move(
|
|
79
|
+
position_msg,
|
|
80
|
+
[
|
|
81
|
+
("client-id", "grpc-sync|REST"),
|
|
82
|
+
],
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
coords = f"({request.x}, {request.y})"
|
|
86
|
+
return StatusResponse(
|
|
87
|
+
status="success",
|
|
88
|
+
details=f"Move to {coords} initiated",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@router.post("/speed", response_model=StatusResponse)
|
|
93
|
+
@handle_grpc_errors
|
|
94
|
+
async def speed(
|
|
95
|
+
request: VelocityRequest,
|
|
96
|
+
grpc_client=Depends(get_grpc_client),
|
|
97
|
+
logger=Depends(get_logger),
|
|
98
|
+
) -> StatusResponse:
|
|
99
|
+
logger.debug(f"Speed command: vx={request.vx}, vy={request.vy}")
|
|
100
|
+
|
|
101
|
+
speed_msg = vector2(x=request.vx, y=request.vy)
|
|
102
|
+
grpc_client.nav_cmd_velocity(
|
|
103
|
+
speed_msg,
|
|
104
|
+
[
|
|
105
|
+
("client-id", "grpc-sync|REST"),
|
|
106
|
+
],
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
spd_str = f"({request.vx}, {request.vy})"
|
|
110
|
+
return StatusResponse(
|
|
111
|
+
status="success",
|
|
112
|
+
details=f"Velocity {spd_str} initiated",
|
|
113
|
+
)
|