Добавлен stop в mcp
This commit is contained in:
@@ -3,7 +3,7 @@ from contextlib import asynccontextmanager
|
||||
|
||||
import rclpy
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, APIRouter
|
||||
from fastmcp import FastMCP
|
||||
from sensor_msgs.msg import JointState
|
||||
from std_srvs.srv import Trigger
|
||||
@@ -13,6 +13,34 @@ from .ros_node import CobotWebNode, get_bridge, set_bridge
|
||||
from . import runner, trajectory, positions
|
||||
|
||||
|
||||
stop_router = APIRouter(tags=["stop"])
|
||||
|
||||
@stop_router.post("/stop", summary="Остановить всё: runner, траекторию и планировщик")
|
||||
def stop_all():
|
||||
runner.stop_if_running()
|
||||
trajectory.send_stop_trajectory()
|
||||
|
||||
try:
|
||||
result = get_bridge().call_service(
|
||||
Trigger,
|
||||
"cobot/stop",
|
||||
Trigger.Request()
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "stopped",
|
||||
"success": result.success,
|
||||
"message": result.message,
|
||||
}
|
||||
|
||||
except RuntimeError:
|
||||
return {
|
||||
"status": "stopped",
|
||||
"success": True,
|
||||
"message": "Планировщик не запущен",
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
node = CobotWebNode()
|
||||
@@ -31,9 +59,10 @@ def main():
|
||||
_schema_app.include_router(runner.router)
|
||||
_schema_app.include_router(trajectory.router)
|
||||
_schema_app.include_router(positions.router)
|
||||
_schema_app.include_router(stop_router)
|
||||
|
||||
mcp = FastMCP.from_fastapi(app=_schema_app)
|
||||
mcp_http = mcp.http_app(path='/mcp')
|
||||
mcp_http = mcp.http_app(path='/')
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
@@ -46,18 +75,9 @@ def main():
|
||||
app.include_router(runner.router)
|
||||
app.include_router(trajectory.router)
|
||||
app.include_router(positions.router)
|
||||
app.include_router(stop_router)
|
||||
app.mount("/mcp", mcp_http)
|
||||
|
||||
@app.post("/stop", tags=["stop"], summary="Остановить всё: runner, траекторию и планировщик")
|
||||
def stop_all():
|
||||
runner.stop_if_running()
|
||||
trajectory.send_stop_trajectory()
|
||||
try:
|
||||
result = get_bridge().call_service(Trigger, "cobot/stop", Trigger.Request())
|
||||
return {"status": "stopped", "success": result.success, "message": result.message}
|
||||
except RuntimeError:
|
||||
return {"status": "stopped", "success": True, "message": "Планировщик не запущен"}
|
||||
|
||||
uvicorn.run(app, host=host, port=port)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user