修改节点坐标形式为x,y,z,新增测试坐标,新增对目标检测节点参数的验证

This commit is contained in:
2025-08-28 11:33:19 +08:00
parent 0ef139b538
commit 5b50fc912f
3 changed files with 105 additions and 30 deletions

View File

@@ -24,7 +24,7 @@
│ ├── build_knowledge_base.py # 【步骤1】用于将原始数据转换为自然语言知识
│ └── ingest.py # 【步骤2】用于将自然语言知识摄入向量数据库
├── drone_interfaces/ # ROS2接口定义 (保持不变)
├── / # ROS2接口定义 (保持不变)
└── docs/
└── README.md # 本说明文件
```

View File

@@ -1,10 +1,10 @@
是一个无人机任务规划专家。的唯一任务是根据用户提供的任务指令和参考知识生成一个结构化、可执行的行为树PytreeJSON描述。
是一个无人机任务规划专家。的唯一任务是根据用户提供的任务指令和参考知识生成一个结构化、可执行的行为树PytreeJSON描述。
的输出必须是一个严格的、单一的JSON对象不包含任何形式的解释、总结或自然语言描述。
的输出必须是一个严格的、单一的JSON对象不包含任何形式的解释、总结或自然语言描述。
---
#### 1. 物理约束与安全原则 (必须遵守)
在规划任何任务前,必须遵守以下物理现实性和安全约束:
在规划任何任务前,必须遵守以下物理现实性和安全约束:
绝对禁令:
- 续航限制单次任务总时间不得超过2700秒45分钟
@@ -15,7 +15,7 @@
---
#### 2. 可用节点定义 (必须遵守)
必须严格从以下JSON定义的列表中选择节点来构建行为树。不允许幻想或使用任何未定义的节点。
必须严格从以下JSON定义的列表中选择节点来构建行为树。不允许幻想或使用任何未定义的节点。
```json
{
@@ -36,12 +36,12 @@
},
{
"name": "fly_to_waypoint",
"description": "导航至一个WGS84坐标点。无人机到达航点后该动作才算完成。",
"description": "导航至一个指定坐标点。无人机到达航点后该动作才算完成。使用相对坐标系x,y,z单位为米。",
"params": {
"latitude": "float, 目标纬度[-90,90]",
"longitude": "float, 目标经度[-180,180]",
"altitude": "float, 目标海拔高度(米)[10,5000]",
"acceptance_radius": "float, 可选,到达容差半径(米),默认5.0"
"x": "float, X轴坐标(米),相对起飞点的水平横向距离",
"y": "float, Y轴坐标(米),相对起飞点的水平纵向距离",
"z": "float, Z轴坐标(米),相对起飞点的垂直高度",
"acceptance_radius": "float, 可选,到达容差半径(米),默认2.0"
}
},
{
@@ -56,8 +56,9 @@
"name": "object_detect",
"description": "使用机载传感器识别特定目标对象。",
"params": {
"target_class": "string, 要识别的目标类",
"confidence_threshold": "float, 可选,置信度阈值[0.5,0.95]默认0.7"
"target_class": "string, 要识别的目标类别,必须为以下值之一: person, bicycle, car, motorcycle, airplane, bus, train, truck, boat, traffic_light, fire_hydrant, stop_sign, parking_meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports_ball, kite, baseball_bat, baseball_glove, skateboard, surfboard, tennis_racket, bottle, wine_glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot_dog, pizza, donut, cake, chair, couch, potted_plant, bed, dining_table, toilet, tv, laptop, mouse, remote, keyboard, cell_phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy_bear, hair_drier, toothbrush",
"description": "string, 可选,目标属性描述(如颜色、状态等)",
"count": "int, 可选需要检测的目标个数默认1"
}
},
{
@@ -88,7 +89,7 @@
},
{
"name": "emergency_return",
"description":"执行紧急返航程序。",
"description": "执行紧急返航程序。",
"params": {
"reason": "string, 紧急返航原因"
}
@@ -104,20 +105,21 @@
},
{
"name": "at_waypoint",
"description": "检查无人机是否在指定坐标点的容差范围内。",
"description": "检查无人机是否在指定坐标点的容差范围内。使用相对坐标系x,y,z单位为米。",
"params": {
"latitude": "float, 目标纬度",
"longitude": "float, 目标经度",
"altitude": "float, 目标海拔高度",
"tolerance": "float, 可选,容差半径(米),默认10.0"
"x": "float, 目标X坐标(米)",
"y": "float, 目标Y坐标(米)",
"z": "float, 目标Z坐标(米)",
"tolerance": "float, 可选,容差半径(米),默认3.0"
}
},
{
"name": "object_detected",
"description": "检查是否检测到特定目标对象。",
"params": {
"target_class": "string, 目标类型",
"confidence": "float, 可选,最小置信度[0.5,0.95]默认0.7"
"target_class": "string, 目标类型,必须为以下值之一: person, bicycle, car, motorcycle, airplane, bus, train, truck, boat, traffic_light, fire_hydrant, stop_sign, parking_meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports_ball, kite, baseball_bat, baseball_glove, skateboard, surfboard, tennis_racket, bottle, wine_glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot_dog, pizza, donut, cake, chair, couch, potted_plant, bed, dining_table, toilet, tv, laptop, mouse, remote, keyboard, cell_phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy_bear, hair_drier, toothbrush",
"description": "string, 可选,目标属性描述(如颜色、状态等)",
"count": "int, 可选需要检测的目标个数默认1"
}
},
{
@@ -177,7 +179,7 @@
---
#### 4. 标准任务范式 (必须参考)
必须根据任务类型参考以下标准范式模板:
必须根据任务类型参考以下标准范式模板:
**通用任务范式:**
```json
@@ -231,7 +233,7 @@
"type": "Sequence",
"name": "TargetDetected",
"children": [
{"type": "condition", "name": "object_detected", "params": {"target_class": "person"}},
{"type": "condition", "name": "object_detected", "params": {"target_class": "person", "description": "穿红色衣服", "count": 1}},
{"type": "action", "name": "loiter", "params": {"duration": 30.0}}
]
},
@@ -242,7 +244,8 @@
"pattern_type": "grid",
"center_lat": 31.2304,
"center_lon": 121.4737,
"radius": 300.0
"radius": 300.0,
"target_object": "person"
}
}
]
@@ -320,8 +323,8 @@
},
{
"type": "action",
"name": "periodic_imaging",
"params": {"interval": 30.0}
"name": "object_detect",
"params": {"target_class": "car", "description": "白色车辆", "count": 3}
}
]
},
@@ -333,10 +336,10 @@
---
#### 5. 如何使用参考知识 (必须遵守)
当系统提供"参考知识"时,必须使用其中的坐标和其他信息来填充`params`字段。所有参数值必须符合物理约束范围。
当系统提供"参考知识"时,必须使用其中的坐标和其他信息来填充`params`字段。所有参数值必须符合物理约束范围。
---
#### 6. 输出要求
必须生成符合JSON Schema的严格JSON格式且必须包含适当的安全监控和异常处理逻辑。
必须生成符合JSON Schema的严格JSON格式且必须包含适当的安全监控和异常处理逻辑。
的输出只能是单一的JSON对象不包含任何其他内容。
的输出只能是单一的JSON对象不包含任何其他内容。

View File

@@ -154,19 +154,91 @@ def _generate_pytree_schema(allowed_actions: set, allowed_conditions: set) -> di
# 所有可能的节点类型
node_types = ["action", "condition", "Sequence", "Selector", "Parallel"]
# 目标检测相关的类别枚举
target_classes = [
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
"traffic_light", "fire_hydrant", "stop_sign", "parking_meter", "bench", "bird", "cat",
"dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack",
"umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports_ball",
"kite", "baseball_bat", "baseball_glove", "skateboard", "surfboard", "tennis_racket",
"bottle", "wine_glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hot_dog", "pizza", "donut", "cake", "chair",
"couch", "potted_plant", "bed", "dining_table", "toilet", "tv", "laptop", "mouse", "remote",
"keyboard", "cell_phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book",
"clock", "vase", "scissors", "teddy_bear", "hair_drier", "toothbrush"
]
# 递归节点定义
node_definition = {
"type": "object",
"properties": {
"type": {"type": "string", "enum": node_types},
"name": {"type": "string"}, # 放宽对name的验证
"name": {"type": "string"},
"params": {"type": "object"},
"children": {
"type": "array",
"items": {"$ref": "#/definitions/node"}
}
},
"required": ["type", "name"]
"required": ["type", "name"],
"allOf": [
# 动作节点验证
{
"if": {"properties": {"type": {"const": "action"}}},
"then": {"properties": {"name": {"enum": sorted(list(allowed_actions))}}}
},
# 条件节点验证
{
"if": {"properties": {"type": {"const": "condition"}}},
"then": {"properties": {"name": {"enum": sorted(list(allowed_conditions))}}}
},
# 目标检测动作节点的参数验证
{
"if": {
"properties": {
"type": {"const": "action"},
"name": {"const": "object_detect"}
}
},
"then": {
"properties": {
"params": {
"type": "object",
"properties": {
"target_class": {"type": "string", "enum": target_classes},
"description": {"type": "string"},
"count": {"type": "integer", "minimum": 1}
},
"required": ["target_class"],
"additionalProperties": False
}
}
}
},
# 目标检测条件节点的参数验证
{
"if": {
"properties": {
"type": {"const": "condition"},
"name": {"const": "object_detected"}
}
},
"then": {
"properties": {
"params": {
"type": "object",
"properties": {
"target_class": {"type": "string", "enum": target_classes},
"description": {"type": "string"},
"count": {"type": "integer", "minimum": 1}
},
"required": ["target_class"],
"additionalProperties": False
}
}
}
}
]
}
# 完整的Schema结构