无人机航线解析_flight-plan-parser

发布时间:2026/7/23 20:40:35
无人机航线解析_flight-plan-parser 以下为本文档的中文说明Flight Plan Parser 是一个无人机航线解析技能用于将自然语言的飞行命令转换为结构化的航路点数据供无人机模拟器的轨迹规划器使用。它支持四种飞行命令模式起飞Take off to 目标高度 in 秒数、悬停Hover at 目标高度 for 秒数、飞行Fly from 起点坐标 to 终点坐标 in 秒数和降落Land from 目标高度 in 秒数。每条命令对应一个飞行段附带模式标签takeoff、hover、fly、land。输出格式为三个数据结构waypoints 是一个 4 乘 n 的 numpy 数组每行包含 x、y、z、yaw 四个维度waypoint_times 是一个 n 维数组表示到达每个航路点的时间秒modes 是一个长度为 n 减 1 的字符串列表表示相邻航路点之间的飞行模式。该技能的应用场景包括无人机模拟训练系统的命令解释器、无人机自动航线规划、教育用途的无人机编程教学。它的核心价值在于架起了人类自然语言表达与机器可执行指令之间的桥梁——用户不需要了解底层坐标系和路径规划算法只需用直观的语言描述飞行意图系统就能自动转换成精确的航路点数据。这种设计理念降低了无人机编程的门槛。Flight Plan ParserOverviewConverts human-readable flight commands into structured waypoints compatible with the drone simulator’s trajectory planner. Each command maps to one flight segment with a mode tag (takeoff,hover,fly,land).Output Formatwaypoints : (4 x n) numpy array — rows are [x, y, z, yaw] waypoint_times : (n,) numpy array — arrival time for each waypoint [seconds] modes : list of (n-1) strings — one mode per segment between waypointsSupported CommandsCommand patternModeTake off to h m height in t secondstakeoffHover at h m height for t secondshoverFly from (x,y,z) to (x,y,z) in t secondsflyLand from h m height in t secondslandImplementation LogicUse a stateful parser class that accumulates waypoints, times, and modes as it processes each command line:Maintain internal state: current position, current time, list of waypoints, list of arrival times, and list of mode strings.On the first command, auto-insert a starting waypoint at the current position andt0if the list is empty.Each command handler extracts numeric values via regex, advances the time accumulator, updates the current position, appends theendwaypoint, and appends the mode string.After all commands are processed, convert the lists to a(4 × n)numpy array (rows: x, y, z, yaw) and a(n,)time array.Expose a top-levelparse_flight_plan(text)function that instantiates the class, feeds it each line, and returns(waypoints, waypoint_times, modes).Regex StrategyWrite one case-insensitive pattern per command type. Each pattern captures only the numeric fields:Takeoff / Hover / Land: capture height and duration (2 groups).Fly: capture start coordinates(x, y, z)and end coordinates(x, y, z)plus duration (7 groups). Thefrom (...)andto (...)parts must handle optional whitespace around commas.Usere.IGNORECASEso capitalisation does not matter.Key Design RulesAuto-insert a starting waypoint at(0, 0, 0, t0)on the first command if the list is empty.Each handler pushes theendwaypoint and appends its mode string — giving N waypoints and N-1 modes.Always copy the position list when pushing to avoid mutating shared state.Usagefromflight_plan_parserimportparse_flight_plan waypoints,waypoint_times,modesparse_flight_plan(Take off to 1 m height in 3 seconds)# waypoints : [[0,0],[0,0],[0,1],[0,0]] shape (4,2)# waypoint_times : [0, 3]# modes : [takeoff]