ara-api-web 1.1.0__py3-none-any.whl
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/__init__.py +5 -0
- ara_api_web/__main__.py +26 -0
- ara_api_web/_core/__init__.py +6 -0
- ara_api_web/_core/app.py +34 -0
- ara_api_web/_core/dependencies.py +0 -0
- ara_api_web/_core/models/__init__.py +45 -0
- ara_api_web/_core/models/requests.py +29 -0
- ara_api_web/_core/models/responses.py +108 -0
- ara_api_web/_core/routers/__init__.py +1 -0
- ara_api_web/_core/routers/api/__init__.py +0 -0
- ara_api_web/_core/routers/api/msp.py +175 -0
- ara_api_web/_core/routers/api/navigation.py +113 -0
- ara_api_web/_core/routers/api/vision.py +52 -0
- ara_api_web/_core/routers/health.py +12 -0
- ara_api_web/_core/routers/status.py +0 -0
- ara_api_web/_core/server.py +63 -0
- ara_api_web/_utils/__init__.py +76 -0
- ara_api_web/_utils/communication/__init__.py +90 -0
- ara_api_web/_utils/communication/gRPCSync.py +237 -0
- ara_api_web/_utils/communication/grpc/messages/base_msg_pb2.py +44 -0
- ara_api_web/_utils/communication/grpc/messages/base_msg_pb2_grpc.py +24 -0
- ara_api_web/_utils/communication/grpc/messages/msp_msg_pb2.py +57 -0
- ara_api_web/_utils/communication/grpc/messages/msp_msg_pb2_grpc.py +24 -0
- ara_api_web/_utils/communication/grpc/messages/nav_msg_pb2.py +34 -0
- ara_api_web/_utils/communication/grpc/messages/nav_msg_pb2_grpc.py +24 -0
- ara_api_web/_utils/communication/grpc/messages/vision_msg_pb2.py +51 -0
- ara_api_web/_utils/communication/grpc/messages/vision_msg_pb2_grpc.py +24 -0
- ara_api_web/_utils/communication/grpc/msp_pb2.py +38 -0
- ara_api_web/_utils/communication/grpc/msp_pb2_grpc.py +539 -0
- ara_api_web/_utils/communication/grpc/navigation_pb2.py +38 -0
- ara_api_web/_utils/communication/grpc/navigation_pb2_grpc.py +275 -0
- ara_api_web/_utils/communication/grpc/vision_pb2.py +38 -0
- ara_api_web/_utils/communication/grpc/vision_pb2_grpc.py +275 -0
- ara_api_web/_utils/config.py +51 -0
- ara_api_web/_utils/decorators.py +53 -0
- ara_api_web/_utils/logger.py +191 -0
- ara_api_web/_utils/rest_helpers.py +52 -0
- ara_api_web/_utils/ui.py +119 -0
- ara_api_web-1.1.0.dist-info/METADATA +37 -0
- ara_api_web-1.1.0.dist-info/RECORD +43 -0
- ara_api_web-1.1.0.dist-info/WHEEL +4 -0
- ara_api_web-1.1.0.dist-info/entry_points.txt +2 -0
- ara_api_web-1.1.0.dist-info/licenses/LICENSE +21 -0
ara_api_web/__init__.py
ADDED
ara_api_web/__main__.py
ADDED
|
@@ -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()
|
ara_api_web/_core/app.py
ADDED
|
@@ -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
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends
|
|
2
|
+
|
|
3
|
+
from ara_api_web._utils import (
|
|
4
|
+
get_grpc_client,
|
|
5
|
+
get_logger,
|
|
6
|
+
handle_grpc_errors,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
router = APIRouter(prefix="/api/vision", tags=["Vision"])
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@router.get("/image")
|
|
13
|
+
@handle_grpc_errors
|
|
14
|
+
async def get_image(
|
|
15
|
+
grpc_client=Depends(get_grpc_client),
|
|
16
|
+
logger=Depends(get_logger),
|
|
17
|
+
):
|
|
18
|
+
logger.debug("Image request received")
|
|
19
|
+
return {"status": "not_implemented", "message": "Image API coming soon"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@router.get("/aruco")
|
|
23
|
+
@handle_grpc_errors
|
|
24
|
+
async def get_aruco(
|
|
25
|
+
grpc_client=Depends(get_grpc_client),
|
|
26
|
+
logger=Depends(get_logger),
|
|
27
|
+
):
|
|
28
|
+
logger.debug("Aruco request received")
|
|
29
|
+
return {"status": "not_implemented", "message": "Aruco API coming soon"}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.get("/qr")
|
|
33
|
+
@handle_grpc_errors
|
|
34
|
+
async def get_qr(
|
|
35
|
+
grpc_client=Depends(get_grpc_client),
|
|
36
|
+
logger=Depends(get_logger),
|
|
37
|
+
):
|
|
38
|
+
logger.debug("QR code request received")
|
|
39
|
+
return {
|
|
40
|
+
"status": "not_implemented",
|
|
41
|
+
"message": "QR code API coming soon",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@router.get("/blob")
|
|
46
|
+
@handle_grpc_errors
|
|
47
|
+
async def get_blob(
|
|
48
|
+
grpc_client=Depends(get_grpc_client),
|
|
49
|
+
logger=Depends(get_logger),
|
|
50
|
+
):
|
|
51
|
+
logger.debug("Blob request received")
|
|
52
|
+
return {"status": "not_implemented", "message": "Blob API coming soon"}
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import signal
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import uvicorn
|
|
6
|
+
|
|
7
|
+
from ara_api_web._core.app import create_app
|
|
8
|
+
from ara_api_web._utils import Logger, gRPCSync, init_dependencies
|
|
9
|
+
from ara_api_web._utils.config import LOGGER_CONFIG, REST_CONFIG
|
|
10
|
+
from ara_api_web._utils.ui import UI
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run_server(host: Optional[str] = None, port: Optional[int] = None):
|
|
14
|
+
host = host or REST_CONFIG.HOST
|
|
15
|
+
port = port or REST_CONFIG.PORT
|
|
16
|
+
|
|
17
|
+
logger = Logger(
|
|
18
|
+
log_level=LOGGER_CONFIG.LOG_LEVEL,
|
|
19
|
+
log_to_file=LOGGER_CONFIG.LOG_TO_FILE,
|
|
20
|
+
log_to_terminal=LOGGER_CONFIG.LOG_TO_TERMINAL,
|
|
21
|
+
log_dir=LOGGER_CONFIG.LOG_DIR,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
logger.debug(f"Starting REST API server on {host}:{port}")
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
grpc = gRPCSync()
|
|
28
|
+
except Exception as e:
|
|
29
|
+
logger.error(f"Failed to initialize gRPC client: {e}")
|
|
30
|
+
sys.exit(-1)
|
|
31
|
+
|
|
32
|
+
init_dependencies(grpc=grpc, logger=logger)
|
|
33
|
+
|
|
34
|
+
app = create_app()
|
|
35
|
+
|
|
36
|
+
grpc_address = "50051, 50052, 50053"
|
|
37
|
+
ui = UI()
|
|
38
|
+
ui.display_startup_banner(host=host, port=port, grpc_address=grpc_address)
|
|
39
|
+
|
|
40
|
+
def signal_handler(sig, frame):
|
|
41
|
+
logger.debug(f"Received signal {sig}, shutting down gracefully")
|
|
42
|
+
sys.exit(0)
|
|
43
|
+
|
|
44
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
45
|
+
signal.signal(signal.SIGTERM, signal_handler)
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
uvicorn.run(
|
|
49
|
+
app,
|
|
50
|
+
host=host,
|
|
51
|
+
port=port,
|
|
52
|
+
log_level="error",
|
|
53
|
+
access_log=True,
|
|
54
|
+
)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
logger.error(f"Server error: {e}")
|
|
57
|
+
raise
|
|
58
|
+
finally:
|
|
59
|
+
logger.warning("REST API server stopped")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
run_server()
|