Enabling SIM_STATE message in ArduCopter SITL logs?

Hi all,

I’m running some tests using the SITL framework in ArduCopter, and injecting in faults to the GPS, barometer etc. For analysis, I need to get the simulation ground truth data about the position, altitude, vx, vy, vz etc. as the GLOBAL_POSITION message data and any sensor messages will necessarily be affected by the faults I inject and not representative of the actual behaviour of the copter.

The log files contain the SIMSTATE message, which contains the latitude, longitude and some other useful information about the copter in the simulation, but doesn’t have all of the data I need like the altitude or velocities. The MAVLink protocol specifies a SIM_STATE message in the common message set which includes all the variables I am interested in, but this message doesn’t seem to be saved into the log files if indeed it is sent at all.

Is there any way to enable the SIM_STATE message so that it is included in the .tlog files? Or any other workaround that could get me access to the variables contained in the SIM_STATE message?

Thanks!

Hello,

We aren’t supporting the SIM_STATE message for now. I am working on a fix so that SIMSTATE will be even to SIM_STATE

Hi,
While you’re at it, do you think it possible to add a timestamp to the SIMSTATE message?

Thanks!

Hi,

Thanks for the response, if the SIMSTATE message achieves parity with the SIM_STATE message then that’ll work for me. What sort of timeline is there for this change, i.e. weeks, months? I could use this in a paper I’m writing, though I have a backup strategy in mind if it will take more than a few weeks.

Valtteri,

I seem to have a similar use case as you. I need the true simulated absolute position and rotation. I’d like precision for position down to 1cm or so.

Today I discovered that while the SIM_STATE mavlink metadata was added in 2013, no implementation was done.

I managed to get the following patch to compile. It emits mavlink with msgid=108 to my client, as intended. I have only taken a quick glance at the altitude field, and so far it looks good. I will proceed with checking the other fields that I need. YMMV.

Cheers,

Jeff

PS: Here is the mavlink commit that added the SIM_STATE message:

    commit 6eb8cfcec1f343d6cfca1d0b43261aebf7a3549a
    Author: Andrew Tridgell <tridge@samba.org>
    Date:   Thu Jun 6 16:41:03 2013 +1000

        message_defintions: added RADIO_STATUS, SIM_STATE and HIL_SENSOR

        the RADIO_STAUS is a copy from ardupilotmega

        HIL_SENSOR is intended to replace HIL_STATE, giving missing
        information

        SIM_STATE is used to provide feedback to ground stations on true SIM
        state

        Pair-programmed-with: Lorenz Meier
1 Like

Hi Jeff,

Thanks for this, I’ve checked your code out and understand a bit better how to get access to the simulation state. Unfortunately for me the messages aren’t being saved into the .tlog files produced after running a SITL simulation which is what I use, so I’ll need to keep investigating why that is.

Is there a reason that SIMSTATE doesn’t contain the altitude?
Do I need to integrate AccZ from takeoff? or is there a better way?
Thanks!

Is there a reason that SIMSTATE doesn¢t contain the altitude?

Somebody managed to overlook it when the message was created…

Do I need to integrate AccZ from takeoff? or is there a better way?

Probably a mavlink2 extension to the message…

Peter

Try ahrs2 message, which contains relative altitude

1 Like

Anything changed on the topic?

I downloaded AP from github and it looks like the SIM_STATE MAVLink message is implemented. I can see that sim_state appears in many places in the code: mavlink messages definitions (dialects), SITL.cpp, ArduPlane and ArduCopter cpp files. It also looks like there are some calculations conducted using this variable.

I can read the MAVLink message with type=SIMSTATE, however it’s not possible to read a message with type=SIM_STATE.

SIM_STATE provides richer knowledge about the state of the simulation than SIMSTATE and it would be fabulous to be able to read it…

Update:
One can request AP to send SIM_STATE message by its ID, which is 108.

I am unable to get this to work in SITL with either Plane or Copter. I am currently on master and have tried requesting the message with message 511 (set_message_interval) and 512 (request_message). I have confirmed that other messages work with the same parameters such as attitude and SIMSTATE, but am unable to get SIM_STATE info.

What vehicle/commit were you using where it replied with SIM_STATE?

I stand corrected. Ardupilot is sending SIM_STATE, however both the wireshark lua script and the library I am using to parse them seem to have some discrepancy of the structure (seemingly because of the extension fields lat_int and lon_int). From what I can find, the pymavlink .xml does not have the extensions in the xml, which explains the wireshark plugin or anything generated from pymavlink. The library I am using does have them and I suspect that it is not parsing the extensions properly. I would suggest others who are experiencing this issue to check if their library includes the lat_int and lon_int extensions or not.

I am using a standard installation of pymavlink (pip3 install …) and make use of lat_int and lon_int from the SIM_STATE.