PX4 / jMAVSim

Simple multirotor simulator with MAVLink protocol support
BSD 3-Clause "New" or "Revised" License
82 stars 207 forks source link

Recent implementation for HIL_STATE_QUATERNION is causing quite a few issues #43

Closed sytelus closed 5 years ago

sytelus commented 7 years ago

Recently user @kd0aij added HIL_STATE_QUATERNION message along with few other changes such as removing nav_mode check. This is causing following issues:

  1. With all default HIL setup (see steps in this issue if needed for repro) you will flickers in qGroundControl where Altitude keeps switching between 0 and 480m.
  2. With RC control, you will frequently see quadcopter suddenly flip over and dive to ground.
  3. You may see heading for the vehicle at 90 degrees instead of 0.

The cause of this is below problem is in the implementation:

  1. altitude (alt) is set to z value of vehicle position. This is incorrect. The z position needs to be projected on global frame to get altitude.
  2. The lat and lon fields of message are not set at all.
  3. The ind_windspeed is not set at all (this might be ok, however).
  4. The quaternion has some issue which is causing wrong heading.

Additionally, I also think this message is possibly interfering PX4 autopilot. See the function MavlinkReceiver::handle_message_hil_state_quaternion(mavlink_message_t *msg) in the PX4 code.

I reverted the MAVLinkHILSystem.java file to version before Sep 1 and above problems went away with vehicle having stable flight.

bkueng commented 7 years ago

44 should at least solve your first issue. Can you test it?

sytelus commented 7 years ago

Looks like @lovettchris already tried this change https://github.com/PX4/jMAVSim/pull/41. BTW, the reason GPS is 0,0 because lat and lon fields of HIL_STATE_QATERNION are not set. Also alt is set wrongly to z instead of projected value of z.

sytelus commented 7 years ago

@kd0aij, @bkueng I think I now understand the purpose of HIL_STATE_QUATERNION . So basically, HIL can be used in two modes: (1) "state-level" mode (2) "sensor-level" mode. In Mode 1, pose estimation is disabled. This mode is useful for high throughput simulation where you don't care about errors from sensors. Mode 2 is normal simulation mode where pose estimation is enabled. Mode 2 should be the default and should be used majority of the times. So basically jMavSim should provide a command line switch to select one of these two modes instead of always sending HIL_STATE_QUATERNION all the time as it is doing now and thus always enforcing Mode 1.

Reference: https://pixhawk.org/dev/hil/start

bkueng commented 7 years ago

The reference is outdated and I don't think we support state-level HIL anymore. As I wrote in https://github.com/PX4/jMAVSim/pull/41#issuecomment-255348808, HIL_STATE_QUATERNION is only used for logging.

julianoes commented 5 years ago

@bkueng do we still need this for logging? #82 would not be needed then.

bkueng commented 5 years ago

Yes it is, as it provides the ground-truth.

julianoes commented 5 years ago

Ah ok.