How to take off a PX4 autopilot using mavlink message?

797 Views Asked by At

I follow the following link's sample code

http://android.dronekit.io/first_app.html

and when I set API VehicleApi.getApi(this.drone).arm(true); vehicleState.isFlying() automatically becomes true.

Can anybody tell me what this problem is?

What I need is: 1. take off, land

I read from some website that the dronekit-android does not support the mode changing. If so, how should I send the mavlink message to take off and land? So far, I can sucessfully send the mavlink message to the PX4 board.

Thanks for replying.

Thank you for replying.

BR SeanH

2

There are 2 best solutions below

0
On

If you trace though some of the code in dronekit-android, you can see that isFlying is set here with the code below.

boolean isFlying = systemStatus == MAV_STATE.MAV_STATE_ACTIVE || ...;

MAV_STATE_ACTIVE, defined here states

System is active and might be already airborne. Motors are engaged.

So isFlying doesn't mean it's airborne but just that the motors are turned on. That occurs when you call VehicleApi.getApi(this.drone).arm(true); because you are literally arming the vehicle at that point.

For takeoff, you want to use the ControlApi. ControlApi.getApi(drone).takeOff(desired_altitude, listener) and for land you need to use VehicleApi.getApi(drone).setVehicleMode(VehicleMode.COPTER_LAND, listener)

The sample code you're looking at is very old. I suggest you follow the sample app from github.

0
On

I have not tried android-dronekit before and I noticed that the src folder have not been updated for more than two years on github.

I advice you to use python-dronekit because there is a powerful library called pymavlink in python and used in python-dronekit. You can build hyper application if you want but first try to takeoff and land in python.