I am running the HITL mode on jMAVSim using a Pixhawk 1. I am working on using offboard mode to control the velocity. I was testing just sending vx = 5, vy =0 and vz =0. The X and Y positions act how I expect them to, but the Z position fluctuates. The fluctuation is usually around ~5m. You can see the local_position_ned.z from the analyze widget.
This happens in hold mode, altitude mode and offboard mode (it only happens if I set z=0 in offboard mode).
How do I stop the fluctuation? Could it be the weight or some kind of wind parameter causing it? Is it normal?
Does the HITL simulation work responsive in X, Y direction or could it be some kind of delay somewhere in the system? Do you have a fast computer or might it be at the limit? Usually HITL runs more responsive for me than SITL even.
The error clearly looks like you edited the file sitl_run.sh and saved it using a windows specific editor that switches every new line in the file to CR LF instead of just LF. Cygwin needs to have the files with unix style line feeds to work correctly. More info: newline - Difference between CR LF, LF and CR line break types - Stack Overflow
Use e.g. Notepad++ or Visual Studio Code to switch the line endings.
If you didn’t edit anything and still have the problem you might have setup git for windows to check out the files in CR LF style. In this case either reconfigure your windows git (it asked you all this stuff during installation and I wrote commands in the cygwin docs linked above) or just use the git within Cygwin for this project.
most of my flights have this error
That is an error which can happen in SITL especially if performance is an issue or you run the simulation for a long time. Are you using the latest PX4 master? Because since lockstep (improved simulation timing when some relatime deadlines are missed) was introduced by @JulianOes these problems vanished for me.
Thank you for the reply!
I will try to tune the parameters again soon, after editing the sitl_run file.
I am using the latest PX4 master, I updated it recently and it still gave the same error, but I will check again.
I am sending velocity data in the offboard mavlink message, so the X and Y velocity setpoints follow exactly what I am sending. The estimated values of X and Y follow these setpoints closely.
The Z velocity is the only one that does not follow what I am sending it. The Z velocity setpoint fluctuates (in the graph jMAVSim drone Local_position Z fluctuating) which makes the estimated z values go up and down too. I don’t think this could be caused by the computer being too slow, since X and Y are fine.
I may try and see if I can test it on a faster computer though, if possible, to rule that out.
Maybe as an additional reference of possible values, I use the HITL jMAVSim with these vehicle customized values:
param set MPC_Z_VEL_P 0.25
param set MPC_Z_P 0.85
param set MPC_Z_VEL_D 0.0
param set MPC_Z_VEL_I 0.085
These are of course tuned for the real drone and not HITL but it looks fine in simulation. I didn’t check the logs in detail though. Are the high tracking errors already visible in the simulation’s drone state visualization (without graph)?