How to add a new flight mode in px4 and use MAV link to control the aircraft in this mode

I want to add something to the px4 code that allows me to control the aircraft, and now there are some questions.How to add a new flight mode in px4 and use MAV link to control the aircraft in this mode?

There is no complete documentation on how to add a new flight mode.
Depending on what you’re trying to achieve, that might not be needed. Have you looked into offboard control through MAVROS or Dronecore?

I want to write a code in pixhawk to control the take-off and landing of the plane by mavlink.but I don’t know what to do.

Can you be more specific about what you want to achieve?

At this point it is not clear to me why uploading missions is not sufficient for you.

Now I want to control the aircraft in the takeoff mode to fly a certain distance forward and then fly back to the point of departure. What should I do?