Auterion / px4-jsbsim-bridge

JSBSim bridge for PX4 SITL/HITL simulations
BSD 3-Clause "New" or "Revised" License
24 stars 39 forks source link

Added sensor_msg.id to avoid out of range error from PX4's SimulatorMavlink #66

Open toshiharutf opened 4 months ago

toshiharutf commented 4 months ago

Problem description

While running PX4_Autopilot (d98800521644ff2ba5d761c66a0d601016b96dac) in SITL with jsbsim, the following problem arise

image

This is originated here src/modules/simulation/simulator_mavlink/SimulatorMavlink.cpp

if (sensors.id >= ACCEL_COUNT_MAX) { PX4_ERR("Number of simulated accelerometer %d out of range. Max: %d", sensors.id, ACCEL_COUNT_MAX); return; if (sensors.id >= MAG_COUNT_MAX) { PX4_ERR("Number of simulated magnetometer %d out of range. Max: %d", sensors.id, MAG_COUNT_MAX); return;

Note Not sure why sensors.id is used as the max field length.

Solution Added sensor_msg.id to acc, gyro and mag to avoid "Number of simulated…… xxx out of range" error from PX4's SimulatorMavlink class.

toshiharutf commented 4 months ago

Hi Jaeyoung, Thanks for the fast response. I have updated the bug description to better explain the fix. I haven't tested the setting you mentioned, but I think it is not related from what I saw in the code.

P.D. I wrote you an email to your instutional account. Please, check when you have the time.

toshiharutf commented 4 months ago

The other possibility would be to address it from PX4, but since Gazebo seems to be working fine, I think this fix presents the least modifications.

Jaeyoung-Lim commented 4 months ago

@toshiharutf The problem is that the simulated sensors would be publishing to instance 0. Therefore, if you hardcode the instance number here, it would interfere with the simulated sensor instances.

@dagar FYI

toshiharutf commented 4 months ago

@Jaeyoung-Lim , in the PX4 codebase, I only see mavlink_hil_sensor_t been used in SimulatorMavlink. If by interference, you mean problems between other sensors in the HIL_SENSOR msg, that is addressed with fields_updated.

TBH, I don't understand why SimulatorMavlink is sensors.id as a max length field. What would be your suggestion? should I attemp a fix for PX4?

Best regards,

ericjohnson97 commented 1 month ago

publishing

I'm not quite sure why that is a problem? The JSBSim bridge code is publishing a simulated sensor's data.

I have been using the suggested change in my simulations for the past couple of weeks and have not noticed an issue. granted maybe I haven't run into a scenario where it is an issue. However, I would like to point out that the jsb simulator that is being provided with the current px4 software does not work.

toshiharutf commented 1 month ago

Hi Eric, Yes, the bridge is indeed publishing data. The issue in this case is that some fields in the data stream create issues in the PX4 side.