# Offboard automatic TakeOff / Landing using MAV\_CMD\_LAND/TAKEOFF\_LOCAL

**URL:** <https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333>\
**Category:** PX4 Autopilot\
**Created:** [September 28, 2016, 4:18pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333 "2016-09-28T16:18:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [September 28, 2016, 4:18pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/1 "2016-09-28T16:18:04Z")

</div>

Hello,

Using this portion of Code [GitHub - mavlink/c\_uart\_interface\_example: Simple MAVLink to UART interface example for \*nix systems](https://github.com/mavlink/c_uart_interface_example/) and HITL quadcopter (jmavsim) on the pixhawk, I’ve managed to have a raspberry pi (without ROS) communicating with the autopilot.

I’ve played a little around and I wanted to send long command with MAV\_CMD\_LAND\_LOCAL and MAV\_CMD\_TAKEOFF\_LOCAL instructions.

At beginning of the program I send a ‘null NED’ SET\_POSITION\_TARGET\_LOCAL\_NED at 4Hz whith a drone DISARMED.  
This allow the Offboard mode to be enabled (as seen in QGC) then I arm it by MAV\_CMD\_COMPONENT\_ARM\_DISARM (still OK)  
Then I stop sending SET\_POSITION\_TARGET\_LOCAL\_NED and start sending MAV\_CMD\_TAKEOFF\_LOCAL command at 4Hz but the Autopilot leave offboard mode.

My intend was to send the MAV\_CMD\_TAKEOFF\_LOCAL command at 4Hz until the status reported by EXTENDED\_SYS\_STATE indicates MAV\_LANDED\_STATE\_IN\_AIR. Then send SET\_POSITION\_TARGET\_LOCAL\_NED at 4Hz (like in the example) and finaly MAV\_CMD\_LAND\_LOCAL at 4Hz until EXTENDED\_SYS\_STATE report MAV\_LANDED\_STATE\_ON\_GROUND to finally disarm the drone

If i don’t send SET\_POSITION\_TARGET\_LOCAL\_NED (during takeoff phase, and I suspect it will be the same for landing), the px4 leave the offboard mode.  
What are valid command for offboard mode ? Is there some other commands for autmatic takeoff/landing in offboard mode ?

Takeoff is not so much of a trouble as I can use NED coordonate the ask for an altitude to be reached, the more troublesome is landing as a setpoint with ‘down’ value set to 0 let my UAV hover at 10cm from the ground (observed once with a F450).

Thank you for your help and advices

---

<div class="post-metadata">

**Author:** ![Joseph\_Garret\_Sulliv](https://discuss.px4.io/user_avatar/discuss.px4.io/joseph_garret_sulliv/32/365_2.png) [@Joseph\_Garret\_Sulliv](https://discuss.px4.io/u/Joseph_Garret_Sulliv)\
**Post date:** [September 28, 2016, 8:33pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/2 "2016-09-28T20:33:49Z")

</div>

Hi there,

I believe in order for offboard control mode to be enabled, offboard\_control\_mode ORB messages need to be continually published.

These messages are published by the mavlink receiver whenever the pixhawk receives either SET\_POSITION\_TARGET\_LOCAL\_NED messages, SET\_ATTITUDE\_TARGET, or SET\_ACTUATOR\_CONTROL\_TARGET messages.

In other words, unless your companion computer regularly sets a target position, attitude, or motor input, then the vehicle will exit offboard control mode.

If you need to stay in offboard control mode, try publishing attitude targets, where you can simply command the attitude to some vector, such as [0,0,0]

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [September 28, 2016, 9:23pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/3 "2016-09-28T21:23:24Z")

</div>

Thank you for your help.

I was afrad this was the reason. You’re giving me an Idea, I can keep sending SET\_POSITION\_TARGET\_LOCAL\_NED during takeoff/land phases with a bitmask telling to consider none of the information inside the message (or juste Yaw angle) and check if sending MAV\_CMD\_TAKEOFF\_LOCAL at same time allows me to takeoff

I’m gonna try this and report back.

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [September 29, 2016, 9:17am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/4 "2016-09-29T09:17:14Z")

</div>

By sending SET\_POSITION\_TARGET\_LOCAL\_NED messages with bitmask with value 0xFFFF, it allows me to stay in offboard mode.

However, I’m now facing a new trouble as it seems the MAV\_CMD\_TAKEOFF\_LOCAL is not supported (QGC report Takeoff local command not supported and the led of pixhawk blink red as it does when it reject an improper flight mode)

I’ve tried with PX4 1.4.1 and 1.4.4. Perhaps there is another Takeoff/Land command I might use and that is working with offboard flight mode ?

Thank you for your help and advices

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [September 29, 2016, 11:51am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/5 "2016-09-29T11:51:20Z")

</div>

I’ve managed to make automatic Takeoff/Landing without using MAV\_CMD\_TAKEOFF\_LOCAL and MAV\_CMD\_LAND\_LOCAL.

As reported here [http://www.gitterforum.com/discussion/mavlink-mavros?page=289](http://www.gitterforum.com/discussion/mavlink-mavros?page=289), there is an hidden feature in the bitmask field of the SET\_POSITION\_TARGET\_LOCAL\_NED message

In Px4 firmware there are 4 undocummented values :

> <https://github.com/PX4/Firmware/blob/2f48317a9ea7b05d8c61b3d1c44f8229491350b1/src/modules/mavlink/mavlink_receiver.cpp#L678-L681>

By ORing the bitmask with 0x2000, the UAV automatically landed even if the Z setpoint was 4meters above the ground.  
Tested on px4 flightstack v1.4.4

---

<div class="post-metadata">

**Author:** ![patrick\_smith](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@patrick\_smith](https://discuss.px4.io/u/patrick_smith)\
**Post date:** [September 29, 2016, 3:35pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/6 "2016-09-29T15:35:01Z")

</div>

I have had success getting the vehicle to takeoff by raising the altitude seetpoint in the local ned message

E.g

setpoint.z = -3;  
then arm the vehicle.  
It should shoot up like a rocket.  
You won’t get to monitor the status unless you observe the position relative to the starting position

One more note, for effectiveness I would recommend resetting the setpoint target position to the current position similar to this

target.x = curren.x  
target.y = current.y  
target.z = current.z - desired\_altitude

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [September 30, 2016, 3:39pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/7 "2016-09-30T15:39:07Z")

</div>

Hello,

Thank you for your help.

As I have indicated this method is OK for takeoff but don’t work for Landing as drift may occur in altitude estimation and UAV might hover some inch above the ground. Also it is not ‘clean’ as the drone does not know it’s a takeoff phase (not indicated in message)

The solution is to use SET\_POSITION\_TARGET\_LOCAL\_NED and ORing the bitmask with the value 0x2000 (land setpoint) or 0x1000 (Takeoff setpoint).

> <https://github.com/PX4/Firmware/blob/2f48317a9ea7b05d8c61b3d1c44f8229491350b1/src/modules/mavlink/mavlink_receiver.cpp#L678-L681>

Thanks to ‘land setpoint bitmask’, even if the setpoint is above the real groud, the UAV will continue it’s descent until it reached the ground.

However it is a good idea to use current location for X and Y information (ensuring a vertical takeoff/landing)

---

<div class="post-metadata">

**Author:** ![patrick\_smith](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@patrick\_smith](https://discuss.px4.io/u/patrick_smith)\
**Post date:** [September 30, 2016, 4:02pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/8 "2016-09-30T16:02:11Z")

</div>

Thanks for the reply,

This will certainly help me out. I had no idea of this bitmask.

Can I ask when the land\_sp is enabled, is the position even relevant? or will it land regardless?

---

<div class="post-metadata">

**Author:** ![AndreasAntener](https://discuss.px4.io/user_avatar/discuss.px4.io/andreasantener/32/36_2.png) [@AndreasAntener](https://discuss.px4.io/u/AndreasAntener)\
**Post date:** [October 1, 2016, 7:44am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/9 "2016-10-01T07:44:40Z")

</div>

It will move to the horizontal position you set but ignore the Z part of the setpoint as it will determine itself when its on the ground. To not get into a diagonal landing my recommendation is to first move to the landing spot on flight height and then engage the landing.

---

<div class="post-metadata">

**Author:** ![patrick\_smith](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@patrick\_smith](https://discuss.px4.io/u/patrick_smith)\
**Post date:** [October 3, 2016, 4:40pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/10 "2016-10-03T16:40:44Z")

</div>

Thanks,

This will surely prove useful.

---

<div class="post-metadata">

**Author:** ![Al\_B](https://discuss.px4.io/user_avatar/discuss.px4.io/al_b/32/2717_2.png) [@Al\_B](https://discuss.px4.io/u/Al_B)\
**Post date:** [October 4, 2016, 4:49pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/11 "2016-10-04T16:49:36Z")

</div>

Wow, a lot of good information in this thread. Just a thought. If you are using LPE (which is the default in the latest firmware release), then you might want to add an optical flow to avoid any drifting.

---

<div class="post-metadata">

**Author:** ![patrick\_smith](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@patrick\_smith](https://discuss.px4.io/u/patrick_smith)\
**Post date:** [October 4, 2016, 4:54pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/12 "2016-10-04T16:54:37Z")

</div>

That is something to consider.

Do you know the altitude range of the optical flow in meters?

If you happen to know anything about the “hidden bitmasks” related to setpoint modes, could you consider adding some input in this thread.

> [@PX4 Hidden Flight BitMasks](http://discuss.px4.io/t/px4-hidden-flight-bitmasks/1371):
>
> This is a request for the PX4 Dev Team to chime in on the purpose and functionality of these hidden flight setpoint typemasks featured below bool is\_takeoff\_sp = (bool)(set\_position\_target\_local\_ned.type\_mask & 0x1000); bool is\_land\_sp = (bool)(set\_position\_target\_local\_ned.type\_mask & 0x2000); bool is\_loiter\_sp = (bool)(set\_position\_target\_local\_ned.type\_mask & 0x3000); bool is\_idle\_sp = (bool)(set\_position\_target\_local\_ned.type\_mask & 0x4000); I have been experimenting with outdoor auton…

I would like some clarity on the topic.

Patrick

---

<div class="post-metadata">

**Author:** ![Al\_B](https://discuss.px4.io/user_avatar/discuss.px4.io/al_b/32/2717_2.png) [@Al\_B](https://discuss.px4.io/u/Al_B)\
**Post date:** [October 4, 2016, 5:29pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/13 "2016-10-04T17:29:21Z")

</div>

> [@patrick\_smith](#):
>
> Do you know the altitude range of the optical flow in meters?

We only use it for [indoor test-flights](https://youtu.be/fCxzxttrUgs), but I believe the altitude range is 5 meters.

> [@](#):
>
> If you happen to know anything about the “hidden bitmasks” related to setpoint modes, could you consider adding some input in this thread.

No, I didn’t know about those “hidden bitmasks” either. I’m curious about that too so you might want to post that question in the [PX4 Gitter](https://gitter.im/PX4/PX4Devguide) as well.

---

<div class="post-metadata">

**Author:** ![patrick\_smith](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@patrick\_smith](https://discuss.px4.io/u/patrick_smith)\
**Post date:** [October 4, 2016, 5:43pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/14 "2016-10-04T17:43:46Z")

</div>

Sounds Good,

My goal was to get a complete description in one place, So myself/future users don’t have to go searching everywhere.

Thanks again,

Patrick

---

<div class="post-metadata">

**Author:** ![Al\_B](https://discuss.px4.io/user_avatar/discuss.px4.io/al_b/32/2717_2.png) [@Al\_B](https://discuss.px4.io/u/Al_B)\
**Post date:** [April 9, 2017, 10:24pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/15 "2017-04-09T22:24:22Z")

</div>

> [@patrick\_smith](#):
>
> My goal was to get a complete description in one place

Did you reach this goal and posted the complete description?

---

<div class="post-metadata">

**Author:** ![Al\_B](https://discuss.px4.io/user_avatar/discuss.px4.io/al_b/32/2717_2.png) [@Al\_B](https://discuss.px4.io/u/Al_B)\
**Post date:** [April 27, 2017, 7:48pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/16 "2017-04-27T19:48:42Z")

</div>

> [@tdo](#):
>
> The solution is to use SET\_POSITION\_TARGET\_LOCAL\_NED and ORing the bitmask with the value 0x2000 (land setpoint) or 0x1000 (Takeoff setpoint).

@tdo Do you set the is\_takeoff\_sp once or do you keep it enable until it reaches the desired\_altitude (target.z)?

0b0001110111111000 vs 0b0000110111111000

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [May 16, 2017, 7:48am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/17 "2017-05-16T07:48:29Z")

</div>

I do set the is\_takeoff\_sp at takeoff and keep it until I reach at least 3 meters (even if the target z given is higher than 3 meters). At that point (3 meters), I switch to a ‘normal’ SET\_POSITION\_TARGET\_LOCAL\_NED message (without using the extra bitfield functionnality).

Here is my takeoff bitfield

> (0x1000 | 0b110111000011)

---

<div class="post-metadata">

**Author:** ![Duy\_Vu](https://discuss.px4.io/letter_avatar_proxy/v4/letter/d/73ab20/32.png) [@Duy\_Vu](https://discuss.px4.io/u/Duy_Vu)\
**Post date:** [June 27, 2017, 1:16pm UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/18 "2017-06-27T13:16:09Z")

</div>

Hi,  
Have you successfully flown your drone indoor?

---

<div class="post-metadata">

**Author:** ![easyABC](https://discuss.px4.io/user_avatar/discuss.px4.io/easyabc/32/2364_2.png) [@easyABC](https://discuss.px4.io/u/easyABC)\
**Post date:** [August 3, 2018, 6:09am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/19 "2018-08-03T06:09:47Z")

</div>

Hi, happy to see this convenient way to realize takeoff/landing in offboard mode but that seems doesn’t work for me. I tried these bitmasks as you said. When I used this bitfield to takeoff,

> [@tdo](#):
>
> (0x1000 | 0b110111000011)

the drone in JMAVSIM didn’t move. I expect the drone will take off to the default altitude. The target position was set as follows:  
target.x = current.x  
target.y = current.y  
target.z = current.z

I really need your help, thank you.

---

<div class="post-metadata">

**Author:** ![tdo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/71c47a/32.png) [@tdo](https://discuss.px4.io/u/tdo)\
**Post date:** [August 3, 2018, 9:01am UTC](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333/20 "2018-08-03T09:01:02Z")

</div>

Hello,

From some time now I do use this bitfield for taking off (work with version 1.6.5) : (0x1000 | 0b100111000000)  
For target.z you can try current.z - 5; (this will request a takeoff point 5 meters above the current location, as the z axis in inversed).

Are you in correct offboard mode. To do so you have to send a HEARTBEAT at 2Hz and a request to switch to offboard mode MAV\_CMD\_NAV\_GUIDED\_ENABLE.

And then you also need to arm the drone using MAV\_CMD\_COMPONENT\_ARM\_DISARM. These two command are ‘long command’ type.

Hope this will help you. I’ll be glad to help you if it’s not the case

[Next page](https://discuss.px4.io/t/offboard-automatic-takeoff-landing-using-mav-cmd-land-takeoff-local/1333.md?page=2)
