Source code for rb_sdk.amr_sdk.amr_status
from typing import Any
from rb_flat_buffers.IPC.Request_Get_Core_Data import Request_Get_Core_DataT
from rb_flat_buffers.IPC.Response_Get_Core_Data import Response_Get_Core_DataT
from rb_flat_buffers.SLAMNAV.LidarData import LidarDataT
from rb_flat_buffers.SLAMNAV.MoveStatus import MoveStatusT
from rb_flat_buffers.SLAMNAV.Path import PathT
from rb_flat_buffers.SLAMNAV.ResponseGetInfoCategory import ResponseGetInfoCategoryT
from rb_flat_buffers.SLAMNAV.Status import StatusT
from rb_schemas.sdk import FlowManagerArgs
from rb_sdk.base import RBBaseSDK
[docs]
class RBAmrStatusSDK(RBBaseSDK):
"""Rainbow Robotics AMR Status SDK"""
[docs]
def get_variable(self, robot_model: str, name: str) -> float | list[float] | str | None:
"""
[변수 조회 함수]
Args:
robot_model: 로봇 모델명
name: 변수 이름
"""
try:
req = Request_Get_Core_DataT()
req.option = 0
req.name = f"{robot_model}:{name}"
res = self.zenoh_client.query_one(
f"amr/{robot_model}/get_core_data",
flatbuffer_req_obj=req,
flatbuffer_res_T_class=Response_Get_Core_DataT,
flatbuffer_buf_size=256,
timeout=10,
)
obj_res = res["obj_payload"]
if obj_res is None or obj_res.valid == 0:
return None
if obj_res.type == 0:
return obj_res.payloadNum
elif obj_res.type == 1:
return obj_res.payloadArr
elif obj_res.type == 2:
return obj_res.payloadStr
return None
except Exception as e:
print(f"Error : {e}")
raise e
[docs]
async def get_status(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> dict[str, Any]:
"""
[상태 조회]
- robot_model: 로봇 모델명
- flow_manager_args: flow manager 인자
- ResponseStatusT 객체 반환
"""
res = await self.zenoh_client.receive_one(
f"amr/{robot_model}/status",
flatbuffer_obj_t=StatusT
)
obj = res["dict_payload"]
if obj is None:
raise RuntimeError("Call Get Status failed: obj_payload is None")
if flow_manager_args is not None:
flow_manager_args.done()
return obj
[docs]
async def get_move_status(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> dict[str, Any]:
"""
[이동 상태 조회]
- robot_model: 로봇 모델명
- flow_manager_args: flow manager 인자
- ResponseMoveStatusT 객체 반환
"""
res = await self.zenoh_client.receive_one(
f"amr/{robot_model}/moveStatus",
flatbuffer_obj_t=MoveStatusT
)
obj = res["dict_payload"]
if obj is None:
raise RuntimeError("Call Get Move Status failed: obj_payload is None")
if flow_manager_args is not None:
flow_manager_args.done()
return obj
[docs]
def get_info_category(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> ResponseGetInfoCategoryT:
result = self.zenoh_client.query_one(
f"amr/{robot_model}/info/category",
flatbuffer_res_T_class=ResponseGetInfoCategoryT,
flatbuffer_buf_size=2048,
timeout=10,
)
# 3) 결과 처리 및 반환
if result.get("err") is not None and result.get("err") != "":
raise RuntimeError(f"Query Err : {result.get("err")}")
if result.get("obj_payload") is None:
raise RuntimeError("Call Info Category failed: obj_payload is None")
if flow_manager_args is not None:
if result.get("dict_payload").get("result") == "accept" or result.get("dict_payload").get("result") == "success":
flow_manager_args.done()
else:
raise RuntimeError(result.get("dict_payload").get("message"))
return result["obj_payload"]
[docs]
async def get_lidar2d(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> dict[str, Any]:
"""
[라이다 2D 조회]
- robot_model: 로봇 모델명
- flow_manager_args: flow manager 인자
- ResponseLidar2D 객체 반환
"""
res = await self.zenoh_client.receive_one(
f"amr/{robot_model}/socket/lidar2d",
flatbuffer_obj_t=LidarDataT
)
obj = res["dict_payload"]
if obj is None:
raise RuntimeError("Call Get Lidar2D failed: obj_payload is None")
if flow_manager_args is not None:
flow_manager_args.done()
return obj
[docs]
async def get_global_path(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> dict[str, Any]:
"""
[전역 경로 조회]
- robot_model: 로봇 모델명
- flow_manager_args: flow manager 인자
- ResponseGlobalPath 객체 반환
"""
res = await self.zenoh_client.receive_one(
f"amr/{robot_model}/socket/globalPath",
flatbuffer_obj_t=PathT
)
obj = res["dict_payload"]
if obj is None:
raise RuntimeError("Call Get Global Path failed: obj_payload is None")
if flow_manager_args is not None:
flow_manager_args.done()
return obj
[docs]
async def get_local_path(self, robot_model: str, flow_manager_args: FlowManagerArgs | None = None) -> dict[str, Any]:
"""
[지역 경로 조회]
- robot_model: 로봇 모델명
- flow_manager_args: flow manager 인자
- ResponseLocalPath 객체 반환
"""
res = await self.zenoh_client.receive_one(
f"amr/{robot_model}/socket/localPath",
flatbuffer_obj_t=PathT
)
obj = res["dict_payload"]
if obj is None:
raise RuntimeError("Call Get Local Path failed: obj_payload is None")
if flow_manager_args is not None:
flow_manager_args.done()
return obj