How to manual contol the plane

You’re able to select the type of setpoints with the type_mask in that mavlink message. The only real requirement for update frequency is preventing the offboard failsafe from triggering. Beyond that it depends specifically what you’re trying to do.

and what about set offboard mode? does it need?

i’ve send packet as follows:

mavlink_message_t message;
mavlink_set_position_target_local_ned_t cmd;
cmd.coordinate_frame = MAV_FRAME_LOCAL_NED;
cmd.type_mask = 0b0000011111111111; // control only yaw rate
cmd.yaw_rate = 20*M_PI/180; // 20 degrees per second
mavlink_msg_set_position_target_local_ned_encode(255, 1,&message,&cmd);


seems that vehicle do nothing after receiving this packet. also, if i understand correctly, vehicle should send response with POSITION_TARGET_LOCAL_NED, but it doesn’t.


Could you tell me if mavlink message MANUAL_CONTROL is possible to use in this case? ( Is there any possibility of using it to control yaw/roll/pitch programmatically? I’m asking becouse maybe I have similar problem, wondering how to control position of multirotor without any GPS and magnetometer, strictly reacting on different sensors signals.

@bourne - you have to be in the offboard mode (nav_state).

@MaStrz - MANUAL_CONTROL is intended for stick input from an operator. So you could use this to command the vehicle in an assist mode like stabilized, altitude control, etc, but you’re much better off sending setpoints with SET_POSITION_TARGET_LOCAL_NED. (

Thank You for your response!
But is it possible to use SET_POSITION_TARGET_LOCAL_NED without knowing the orientation according to Geographical directions? In my application, drone will fly indoor in spaces where we can’t trust magnetometer and without GPS. In flying with camera, virtual north can be estimated and kept by computer vision algorithms. I want to use only a few sonars installed horizontaly in order to avoid crashes with close walls, so I won’t know where any direction is. Maybe I would be able to take in my navigation, that North is always in front of the drone ? Do you think that I will be able to use SET_POSITION_TARGET_LOCAL_NED ?

i tried to set offboard mode using MAV_CMD_DO_SET_MODE command but px4 declined it…why it may happens?

Did you get any message? Are you sure you set the flags correctly?

i’m trying to switch in Offboard using mavlink_msg_set_mode_pack, but i receive command_ack with result = 1. Also i tried to use command_long as follows:

mavlink_message_t msg;
mavlink_command_long_t cmd;
cmd.command = (uint16_t) MAV_CMD_DO_SET_MODE;
cmd.confirmation = 1;
cmd.param1 = MAV_MODE_GUIDED_ARMED (there i tried also MAV_MODE_AUTO_ARMED;
cmd.param2 = bm;
cmd.param3 = cm;
cmd.param4 = 0.0f;
cmd.param5 = 0.0f;
cmd.param6 = 0.0f;
cmd.param7 = 0.0f;
cmd.target_system = vehicle_id;
cmd.target_component = default_component;    
mavlink_msg_command_long_encode(system_id, component_id, &msg, &cmd);

in my case for Offboard i have base mode = 121 and custom mode = 393216

after sending this command to px4 i’m receiving COMMAND_ACK with result = 1 and statustext “Not switching off HIL (safety)”. Does it mean that Offboard mode isn’t supported in HIL?

The first parameter of MAV_CMD_DO_SET_MODE is a bitmask. Take a look at MAV_MODE_FLAG here -

If doing this in HIL you need to preserve the HIL bit (MAV_MODE_FLAG_HIL_ENABLED), otherwise you’re forcing it out of HIL.

excuse me, but i don’t understand how to achieve my goal(

I tried to add flag MAV_MODE_FLAG_HIL_ENABLED to mode bitmask as you said. After sending MAV_CMD_DO_SET_MODE command with 1st parameter = MAV_MODE_FLAG_HIL_ENABLED | MAV_MODE_GUIDED_ARMED and BM and CM corresponding to “Offboard”, flight mode changes to “Position”, not “Offboard”. And vehicle still hasn’t any reaction on SET_POSITION_TARGET_LOCAL_NED messages.

could you please provide a step-by-step instructions for switching vehicle to offboard mode if it possible?

btw, it seems that firmware in master branch have bugs when works in hil mode - coordinates changes as Flash from DC comics, relative altitude sometimes is negative, although i’m flying above more or less smooth landscape.

upd now i’m able to switch to Offboard mode using deprecated SET_MODE command. But after doing that HIL is being disabled. How to switch to Offboard with preserving HIL using MAV_DO_SET_MODE command?

hmm…could i get any support from anybody?

1 Like

Make sure you keep the HIL flag set. Then take a look at how QGroundControl handles PX4 custom modes.

I’m trying to use offboard mode from dronekit with fixedwing…I couldn’t achieve takeoff via offboard mode trying all the different typemasks for position and velocity but no luck. I’ve taken off in mission mode and then successfully switched to offboard mode but with type masks than only enable position and velocity (tried both) and the plane with just lock altitude and heading…with the type mask that enables everything, the plane just circles and climbs nonstop.

Which version of PX4? Can you share a log and details of the typemasks you were trying?

I’m using the master branch from the github that I cloned 1-2 weeks ago. I followed this post: OFFBOARD takeoff, land, loiter via SET_POSITION_TARGET_LOCAL_NED, along with looking at the mavlink_receiver.cpp code and tried all the typemasks. Even with the 0b0000000000000000 wide open typemask with zeros for all the values, the plane still circles and climbs. Every other type mask fails to takeoff and if I takeoff first with mission, the selective type masks just lock heading and altitude. I’ve made a post here: Offboard control problem with fixed wing. Where can I get logs from? I have logs in build_posix_sitl_default/logs but theres also the qgroundcontrol ones. How can I give them?

I’ve looked through all of the fixed wing position control module and I don’t see any code to support the set_position_target_local_ned command…Could you point me to where in the position control file this is supported, or where else in the code? I know from mavlink_receiving.cpp it populates the position_sp_triplet msg but MC_pos_control has support for the local_position_setpoint but I dont see anything in fixed wing. Thanks.

Look for position_setpoint_triplet.

Yes I saw that the set_position_target_local_ned populated the x,y,and z variables for the position_setpoint_triplet.current uORB message. What I don’t see in FixedWingPostionControl are any conditions to control position when the offboard control mode is True or any use of pos_sp_triplet.x/y/z…it seems to only use or pos_sp.lon here:

They plane just locks heading and altitude

FW currently only uses lat/lon/alt, but in the near future it will be converted to local position.

If you’re interested please comment in the github PR and we may be able to make the jump sooner with additional help reviewing and testing.

Hi, Im trying to receive on a arduino a command from pixhawk, de cmd_id =21. I´m doing the next but it doesn´t work;

mavlink_message_t msg;
mavlink_command_long_t cmd;
mavlink_status_t status;
while (Serial.available() > 0) {

uint8_t c =;

if (mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {

  mavlink_msg_command_long_decode(&msg, &cmd);

    digitalWrite(ledPIN , HIGH);

  switch (msg.msgid) {
    case MAVLINK_MSG_ID_HEARTBEAT:  // #0: Heartbeat
      { }



Can you help me?