Offboard Mode not working with Pixhawk4 mini running latest Version of px4 firmware and mavros

@Jaeyoung-Lim I am using normalized thrust as you have mentioned. The desired thrust is in terms of the altitude and rate of change of altitude. I don’t have my position controller (for latitude and longitudinal pose) active and I am commanding 0 roll pitch and yaw angles. So basically the quaternions I am sending to the setpoint plugin is [0;0;0;1]. But when I start my node and command the desired altitude to 1 m, the drone pitches nose up and crashes. I can see the same in the attitude readings I am getting. Is it possible to start the drone to take off and then switch to the position of controller after reaching an altitude?

@arg1885 Could you elaborate more on what you are trying to do? If you are not controlling position control, setting your attitude level will not make the drone stay in a fixed position in a stable manner.

Could you elaborate on what [0, 0, 0, 1] mean? which is the real part of the quaternion?

q.x = 0
q.y = 0
q.z = 0
q.w = 1.

Which means my desired roll pitch and yaw angles are 0 i.e. leveled flight condition.

So basically I am trying to take off from the ground and after reaching the desired altitude I am activating a PID controller to give me desired roll and pitch angles which are converted to the desired quaternions. But I can’t take off in a leveled flight condition for some reason. I can use setpoint position and reach a position before I can kick in the altitude and position controller which might lead to a crash if I don’t have nominal thrust value required to hover set along with the controller gains. So I am trying to reach an altitude before activating the controller to control x and y positions.

Any suggestions on handling this problem?

@arg1885 For me, I am not sure if it is even safer to trigger offboard mode after you hover.

Have you checked if your reference attitude has the same yaw as the current yaw? This can lead to some aggressive behaviors if the yaw error is large.

Hello,
Yes my yaw angle is same as the desired angle. Now I am having trouble tuning the gains for the desired thrust which should be between 0-1. I am having the same logic as yours except that I am not considering rotor drag. I have something like this

Thrust = NominalThrustFactor*(kpposition_error + kvvelocity_error + 9.81)

kp and kv are controller gains for the altitude and NominalThrustFactor is a quadratic function limited between 0.03-0.045 depending on the battery voltage something like

NominalThrustFactor = a*batteryVoltage + b

a and b are the coefficients of the polynomial.

Any suggestions how I can tune the gains ?

Thank you.

@arg1885 Nominal thrust factor is not a quadratic function of the battery voltage. It matters on many different factors such as rotor size, motor kv .etc

This you need to tune by looking at the flight. As suggested before, why can’t you start with a value with a reasonable guess of maximum thrust and start from there? Is there a reason you want to map the Nominal thrust value as a function of the battery voltage?

Hello. Yes Nominal Thrust factor does depend on many factors and I thought for a given Quadcopter I could use voltage as one of the factors to tune it since the voltage drops, the nominal thrust value we are supplying will drop. Hence to compensate for it I was thinking of increasing it as a quadratic function of Voltage.

Is it Possible to use setpoint commands to set the vertical velocity and the desired quaternions at the same time? Something like parrot drone does.

Have you verified that it is a quadratic function of the voltage? In my opinion, this will not be a major issue, and you will be able to do most of the maneuvers without the compensation. Have you tried to fly it without the compensated value?

For the multi setpoints, you can look at the mavros wiki

I was not able to tune the gains and the quadcopter altitude either oscillates or it never reaches the desired altitude. Is it possible to send multiple setpoints? Something like desired altitude and quaternions?

@arg1885 About the gains, what gains are you using, with which controller and what is your maximum thrust? I don’t understand why you cannot tune the controller. It should not be something that is fragile to tune.

I think multisetpoints are supported to some degree, but not for all combinations of setpoints. If you are looking at multi setpoints as a workaround, I suggest using just normalized thrust is enough. As I showed you in the mavros_controllers repo, this controller is capable of flying well even on real platforms.

I have the kp gain for altitude set to 1 and kv to 0.5. with those setting, I am unable to reach desired altitude. If I increase the kp to 2-3, then the altitude starts oscillating.

I was following your code on GitHub and I see you have type_mask set to 128 to ignore the attitude in the mavros_msgs:: Attitude. Can you point me to some resources where I can set the mask to ignore the x and y velocity and just command the z velocity and command the attitude or attitude rates? So basically what my controller can send is desired velocity along z and either desired quaternions or desired angular body rates.

I don’t know how to set these mask types.

Thank you.

@arg1885 Your gain problem sounds like your normalized thrust scaling is wrong. It is PD control, so if it oscillates you should increase the D gain

For multi setpoints I do not know any reference. You need to go through the code

Hello, so as we discussed earlier about the nominal thrust scaling, I am using a polynomial to compute the nominal thrust based on the battery voltage. It works for me now.

@arg1885 Awesome! It would be cool if you could compare with a constant value and see if it improves the hover performance

Sure. I will do that. Thank you. :slight_smile:

Hello everyone !
This post is very useful. I know this post is limited to Pixhawk 4 mini. However I plan to do attitude control using Pixhawk 4. Is the same procedure possible with Pixhawk 4? Additionally @arg1885 what topic do you use to publish attitude setpoints ?

@Vrinda Yes it is the same

Thanks much @Jaeyoung-Lim : )

Hi friend,
– I followed the steps, use the EKF2, now the angle from /mavros/vision_pose/pose match the /mavros/local_position/pose but the position estimation has large drift, any advices? and do I need tune the EKF2 relative position x,y,z, to quad body? Thank u