How to manual contol the plane

hi,

i need to control vehicle in “manual” manner. I dont know how it’s named correctly, may be semi-automatic may be somehow differrently. What i mean. I need to programmatically control such vehicle’s parameters as yaw, roll, pitch, airspeed, vertical speed and others. How can i achieve this?

I tried to send MANUAL_SETPOINT with freq > 2Hz and set flight mode to Offboard - px4 declines set mode command. Also i tried to send SET_POSITION_TARGET_GLOBAL_INT commands, but without any success - seems like vehicle ignores them.

Tell me please what i do wrong and how to do right?

Offboard was only recently enabled for fixedwing. You’ll need current master and then you can use SET_POSITION_TARGET_LOCAL_NED (http://mavlink.org/messages/common#SET_POSITION_TARGET_LOCAL_NED).

dagar, could you please describe the algorithm of manual control? What mode should i set and what should be frequency of sending SET_POSITION_TARGET_LOCAL_NED message?

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

write_message(message);


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.

Hi,

Could you tell me if mavlink message MANUAL_CONTROL is possible to use in this case? (https://pixhawk.ethz.ch/mavlink/#MANUAL_CONTROL) 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. (http://mavlink.org/messages/common#SET_POSITION_TARGET_LOCAL_NED1)

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 - http://mavlink.org/messages/common

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.