SIM001 › For developers › Flying by plan
Sending plans
An agent plan tells the plane what to do for the next few seconds. It has a primitive, a target or a point, a plan id and a time to live. The ground sends it as a MAVLink COMMAND_INT with the command 31010 (MAV_CMD_USER_1). param1 is the primitive, param2 the target, param3 the plan id and param4 the time to live in seconds.
x and y are the latitude and the longitude of the point, in 1e-7 degrees. z holds two numbers: the altitude above home, to 0.25 m, and the radius, to 1 m. Encode z as round((altitude + 512) × 4) × 1024 + round(radius). The altitude can be from -512 m to 511.75 m, and the radius from 0 m to 1023 m. The encoder clamps a value outside its range. In Rust, cognition_plan::WirePlan::to_command does this.
In the console of the runner, type plan PRIMITIVE NORTH EAST ALT RADIUS TTL [TARGET]: the primitive, the point in metres north and east of home, the altitude and the radius in metres, the time to live in seconds, and the id of the target aircraft, if the primitive needs one.
The plane answers each plan with a COMMAND_ACK. If the plane refuses the plan, the reason is in result_param2: 1 if the plane is not in AGENT mode, 2 if the plan is malformed, 3 if the plane has no home yet, and 4 if the plane has no executor.
In AGENT mode, the plane sends its agent status, four NAMED_VALUE_INT messages, once a second. AG_PLAN is the id of its plan. AG_PRIM is the primitive of that plan. AG_ENV counts the steps where the safety envelope changed what the plan asked for. AG_FALL tells you if the plane stopped the plan, and why.
Replacing and ending a plan tells you what the plane does when a new plan comes, or when no plan comes.
AGENT mode takes a go-to plan
If the flight mode of the plane is AGENT, type plan goto 80 10 40 0 600 in the console. This plan tells the plane to fly to the point 80 m north and 10 m east of home, at 40 m. The plane replies with COMMAND_ACK, result 0 (ACCEPTED). The console shows ack with result=0. AG_PLAN goes up by 1, to the id of the new plan (plan= in the console). AG_PRIM is 3, go to (prim=3). The plan is good for 600 s.
See it in Watching a game of tag by plan, Sending your first plan, Letting a plan run out.
A plan is refused outside AGENT mode
The plane takes plans only in AGENT mode. In FBWA, or in any other mode, the pilot or ArduPilot flies the plane. Switch to AGENT first. Then send the plan.
If the flight mode of the plane is FBWA, type plan goto 80 10 40 0 600 in the console. This plan tells the plane to fly to the point 80 m north and 10 m east of home, at 40 m. The plane replies with COMMAND_ACK, result 2 (DENIED) and the reason 1. The console shows ack with result=2 reason=1. AG_PLAN does not change.
See it in Sending your first plan.
A malformed plan is refused with a reason
The plane checks each field of the plan. A primitive that does not exist, a number that is not finite or a point off the globe makes the plan malformed. The plane keeps the plan that it flies.
If the flight mode of the plane is AGENT, type plan 9 80 10 40 0 600 in the console. There is no primitive 9. The plane replies with COMMAND_ACK, result 2 (DENIED) and the reason 2. The console shows ack with result=2 reason=2. AG_PLAN does not change.
See it in Sending your first plan.
AGENT mode starts with no plan
In AGENT mode, the plane forgets the old plan and the old count of AG_ENV. It flies wings level and holds its height until a plan comes.
If the flight mode of the plane is FBWA, switch the plane to AGENT: type mode AGENT in the console. AG_PLAN is 0, and the console shows plan=0. AG_PRIM is 0 (prim=0).
See it in Sending your first plan.
The plane reports its plan once a second
The plane sends AG_PLAN, AG_PRIM, AG_ENV and AG_FALL once a second while it is in AGENT mode. Count the AG_PLAN messages to see that the plane is alive.
If the flight mode of the plane is AGENT, type watch 10 in the console. The console counts the AG_PLAN messages in the next 10 s of simulated time. The console shows reports 10, or 9 or 11: the status comes once a second.
See it in Watching a game of tag by plan.