Offboard automatic TakeOff / Landing using MAV_CMD_LAND/TAKEOFF_LOCAL

#1

Hello,

Using this portion of Code 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

1 Like
Flying indoor with optitrack
#2

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]

#3

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.

#4

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

Offboard landing request with px4 V1.6.5 and 1.7.0 in LPE mode no longer working
#5

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, 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 :

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

1 Like
OFFBOARD takeoff, land, loiter via SET_POSITION_TARGET_LOCAL_NED
#6

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

#7

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).

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)

#8

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?

#9

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.

#10

Thanks,

This will surely prove useful.

#11

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.

#12

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.

I would like some clarity on the topic.

Patrick

#13

We only use it for indoor test-flights, but I believe the altitude range is 5 meters.

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 as well.

#14

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

#15

Did you reach this goal and posted the complete description?

1 Like
Offboard mode and mavlink message for this mode
#16

@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

#17

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)

#18

Hi,
Have you successfully flown your drone indoor?

#19

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,

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.

#20

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