Ardupilot SITL simulation error

Hello. I am trying to do a SITL simulation with SITL for linux.I was able to run SITL successfully with the file I cloned from GitHub (GitHub - ArduPilot/ardupilot: ArduPlane, ArduCopter, ArduRover, ArduSub source), but the Ardupilot file I am using in my experiments (an Ardupilot file from about a year ago I have edited the controller program and parameters a bit in the ArduPlane file section), the SITL simulation does not work, and the following error message appears.

SIM_VEHICLE: Start
SIM_VEHICLE: Killing tasks
SIM_VEHICLE: Starting up at SITL location
SIM_VEHICLE: WAF build
SIM_VEHICLE: Configure waf
SIM_VEHICLE: “/home/username/orange/modules/waf/waf-light” “configure” “–board” “sitl”
Setting top to : /home/username/orange
Setting out to : /home/username/orange/build
Autoconfiguration : enabled
Setting board to : sitl
Using toolchain : native
Checking for ‘g++’ (C++ compiler) : /usr/lib/ccache/g++
Checking for ‘gcc’ (C compiler) : /usr/lib/ccache/gcc
Checking for c flags ‘-MMD’ : yes
Checking for cxx flags ‘-MMD’ : yes
CXX Compiler : g++ 11.4.0
Checking for need to link with librt : not necessary
Checking for feenableexcept : yes
Checking for HAVE_CMATH_ISFINITE : yes
Checking for HAVE_CMATH_ISINF : yes
Checking for HAVE_CMATH_ISNAN : yes
Checking for NEED_CMATH_ISFINITE_STD_NAMESPACE : yes
Checking for NEED_CMATH_ISINF_STD_NAMESPACE : yes
Checking for NEED_CMATH_ISNAN_STD_NAMESPACE : yes
Checking for header endian.h : yes
Checking for header byteswap.h : yes
Checking for HAVE_MEMRCHR : yes
Configured VSCode Intellisense: : no
Checking for program ‘python’ : /usr/bin/python
Checking for python version >= 2.7.0 : 3.10.12
Checking for program ‘python’ : /usr/bin/python
Checking for python version >= 2.7.0 : 3.10.12
Source is git repository : yes
Update submodules : yes
Checking for program ‘git’ : /usr/bin/git
Checking for program ‘size’ : /usr/bin/size
Benchmarks : disabled
Unit tests : enabled
Scripting : enabled
Scripting runtime checks : enabled
Debug build : disabled
Coverage build : disabled
SITL 32-bit build : disabled
Checking for program ‘rsync’ : /usr/bin/rsync
‘configure’ finished successfully (6.883s)
{‘waf_target’: ‘bin/arduplane’, ‘default_params_filename’: ‘models/plane.parm’, ‘model’: ‘plane’, ‘sitl-port’: True}
SIM_VEHICLE: Building
SIM_VEHICLE: “/home/username/orange/modules/waf/waf-light” “build” “–target” “bin/arduplane”
Waf: Entering directory /home/username/orange/build/sitl' Embedding file locations.txt:Tools/autotest/locations.txt Embedding file models/Callisto.json:Tools/autotest/models/Callisto.json Embedding file models/plane-3d.parm:Tools/autotest/models/plane-3d.parm Embedding file models/plane.parm:Tools/autotest/models/plane.parm Embedding file models/xplane_heli.json:Tools/autotest/models/xplane_heli.json Embedding file models/xplane_plane.json:Tools/autotest/models/xplane_plane.json Waf: Leaving directory /home/katsuakitakeuchi/orange/build/sitl’

BUILD SUMMARY
Build directory: /home/username/orange/build/sitl
Target Text (B) Data (B) BSS (B) Total Flash Used (B) Free Flash (B)

bin/arduplane 3751026 181885 198728 3932911 Not Applicable

Build commands will be stored in build/sitl/compile_commands.json
‘build’ finished successfully (5.049s)
SIM_VEHICLE: Using defaults from (Tools/autotest/models/plane.parm)
SIM_VEHICLE: Run ArduPlane
SIM_VEHICLE: “/home/katsuakitakeuchi/orange/Tools/autotest/run_in_terminal_window.sh” “ArduPlane” “/home/username/orange/build/sitl/bin/arduplane” “-S” “-w” “–model” “plane” “–speedup” “1” “–slave” “0” “–defaults” “Tools/autotest/models/plane.parm” “–sim-address=127.0.0.1” “-I0”
RiTW: Starting ArduPlane : /home/username/orange/build/sitl/bin/arduplane -S -w --model plane --speedup 1 --slave 0 --defaults Tools/autotest/models/plane.parm --sim-address=127.0.0.1 -I0
SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: “mavproxy.py” “–out” “172.22.0.1:14550” “–master” “tcp:127.0.0.1:5760” “–sitl” “127.0.0.1:5501”
xterm: cannot load font “10x20”
xterm: cannot load font “-misc-fixed-medium-r-normal–20-200-75-75-c-100-iso10646-1”
Connect tcp:127.0.0.1:5760 source_system=255
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from tcp:127.0.0.1:5760
MAV> Connection reset or closed by peer on TCP socket
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
link 1 down
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Attempting reconnect
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping

In the other one.

Setting SIM_SPEEDUP=1.000000
Starting sketch ‘ArduPlane’
Starting SITL input
Using Irlock at port : 9005
bind port 5760 for 0
Serial port 0 on TCP port 5760
Waiting for connection …
Connection on serial port 5760
Loaded defaults from Tools/autotest/default_params/plane.parm
Home: -35.363262 149.165237 alt=584.000000m hdg=353.000000
Smoothing reset at 0.001
bind port 5762 for 2
Serial port 2 on TCP port 5762
bind port 5763 for 3
Serial port 3 on TCP port 5763
validate_structures:469: Validating structures
ERROR: segmentation fault - aborting
Running: sh Tools/scripts/dumpstack.sh 8230 >dumpstack.sh_arduplane.8230.out 2>&1
dumpstack.sh has been run. Output was:
-------------- begin dumpstack.sh output ----------------
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
0x00007fa1869ce45a in __GI___wait4 (pid=8231, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0, usage=usage@entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
30 …/sysdeps/unix/sysv/linux/wait4.c: No such file or directory.
#0 0x00007fa1869ce45a in __GI___wait4 (pid=8231, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0, usage=usage@entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
sc_ret = -512
sc_ret =
#1 0x00007fa1869ce41b in __GI___waitpid (pid=, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0) at ./posix/waitpid.c:38
No locals.
#2 0x00007fa186934bcb in do_system (line=) at …/sysdeps/posix/system.c:171
__result = 1:18 2023/08/08 1:24 2023/08/081:24 2023/08/0866666666666666666
_cleanup_start_doit = true
_buffer = {__routine = 0x7fa186934c50 <cancel_handler>, __arg = 0x7ffc888ded50, __canceltype = 0, __prev = 0x0}
_cleanup_routine = 0x7fa186934c50 <cancel_handler>
cancel_args = {quit = 0x7fa186aff7a0 , intr = 0x7fa186aff840 , pid = 8231}
status = -1
ret = 0
pid = 8231
sa = {__sigaction_handler = {sa_handler = 0x1, sa_sigaction = 0x1}, sa_mask = {__val = {65536, 0, 0, 0, 0, 0, 0, 0, 0, 2141192192, 0, 18446744073709551615, 0, 18446744073709551615, 0, 18446744073709551615}}, sa_flags = 0, sa_restorer = 0x7fa00000ffffffff}
omask = {__val = {1024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 140722599490208, 3473174956023346023, 13239181903880427520, 140722599490208, 2}}
reset = {__val = {6, 199, 140722599489136, 94338285314413, 140722599489520, 140331724490010, 140722599489536, 140722599489376, 140724530937857, 140722599490208, 140722599490208, 140722599490208, 140722599490208, 140722599490280, 140722599490407, 140722599490208}}
spawn_attr = {__flags = 12, __pgrp = 0, __sd = {__val = {6, 199, 140722599489136, 94338285314413, 140722599489520, 140331724490010, 140722599489536, 140722599489376, 140724530937857, 140722599490208, 140722599490208, 140722599490208, 140722599490208, 140722599490280, 140722599490407, 140722599490208}}, __ss = {__val = {1024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 140722599490208, 3473174956023346023, 13239181903880427520, 140722599490208, 2}}, __sp = {sched_priority = 0}, __policy = 0, __pad = {0 <repeats 16 times>}}
#3 0x000055ccd7ea43f1 in AP_HAL::run_command_on_ownpid(char const*) ()
No symbol table info available.
#4 0x000055ccd7ea4e2c in _sig_segv(int) ()
No symbol table info available.
#5
No locals.
#6 __strnlen_avx2 () at …/sysdeps/x86_64/multiarch/strlen-avx2.S:74
No locals.
#7 0x000055ccd7de311a in AP_Logger::validate_structure(LogStructure const*, short) ()
#10 0x000055ccd7d367e7 in Plane::init_ardupilot() ()
No symbol table info available.
#11 0x000055ccd7ddf929 in AP_Vehicle::setup() ()
No symbol table info available.
#12 0x000055ccd7e9e69d in HAL_SITL::run(int, char* const*, AP_HAL::HAL::Callbacks*) const ()
No symbol table info available.
#13 0x000055ccd7cf9f54 in main ()
No symbol table info available.

Thread 1 (Thread 0x7fa1868df740 (LWP 8230) “arduplane”):
#0 0x00007fa1869ce45a in __GI___wait4 (pid=8231, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0, usage=usage@entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
sc_ret = -512
sc_ret =
#1 0x00007fa1869ce41b in __GI___waitpid (pid=, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0) at ./posix/waitpid.c:38
No locals.
#2 0x00007fa186934bcb in do_system (line=) at …/sysdeps/posix/system.c:171
__result =
_cleanup_start_doit = true
_buffer = {__routine = 0x7fa186934c50 <cancel_handler>, __arg = 0x7ffc888ded50, __canceltype = 0, __prev = 0x0}
_cleanup_routine = 0x7fa186934c50 <cancel_handler>
cancel_args = {quit = 0x7fa186aff7a0 , intr = 0x7fa186aff840 , pid = 8231}
status = -1
ret = 0
pid = 8231
sa = {__sigaction_handler = {sa_handler = 0x1, sa_sigaction = 0x1}, sa_mask = {__val = {65536, 0, 0, 0, 0, 0, 0, 0, 0, 2141192192, 0, 18446744073709551615, 0, 18446744073709551615, 0, 18446744073709551615}}, sa_flags = 0, sa_restorer = 0x7fa00000ffffffff}
omask = {__val = {1024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 140722599490208, 3473174956023346023, 13239181903880427520, 140722599490208, 2}}
reset = {__val = {6, 199, 140722599489136, 94338285314413, 140722599489520, 140331724490010, 140722599489536, 140722599489376, 140724530937857, 140722599490208, 140722599490208, 140722599490208, 140722599490208, 140722599490280, 140722599490407, 140722599490208}}
spawn_attr = {__flags = 12, __pgrp = 0, __sd = {__val = {6, 199, 140722599489136, 94338285314413, 140722599489520, 140331724490010, 140722599489536, 140722599489376, 140724530937857, 140722599490208, 140722599490208, 140722599490208, 140722599490208, 140722599490280, 140722599490407, 140722599490208}}, __ss = {__val = {1024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 9196350441231745024, 140722599490208, 3473174956023346023, 13239181903880427520, 140722599490208, 2}}, __sp = {sched_priority = 0}, __policy = 0, __pad = {0 <repeats 16 times>}}
#3 0x000055ccd7ea43f1 in AP_HAL::run_command_on_ownpid(char const*) ()
No symbol table info available.
#4 0x000055ccd7ea4e2c in _sig_segv(int) ()
No symbol table info available.
#5
No locals.
#6 __strnlen_avx2 () at …/sysdeps/x86_64/multiarch/strlen-avx2.S:74
No locals.
#7 0x000055ccd7de311a in AP_Logger::validate_structure(LogStructure const*, short) ()
No symbol table info available.
#8 0x000055ccd7de3641 in AP_Logger::validate_structures(LogStructure const*, unsigned char) ()
No symbol table info available.
#9 0x000055ccd7de392d in AP_Logger::Init(LogStructure const*, unsigned char) ()
No symbol table info available.
#10 0x000055ccd7d367e7 in Plane::init_ardupilot() ()
No symbol table info available.
#11 0x000055ccd7ddf929 in AP_Vehicle::setup() ()
No symbol table info available.
#12 0x000055ccd7e9e69d in HAL_SITL::run(int, char* const*, AP_HAL::HAL::Callbacks*) const ()
No symbol table info available.
#13 0x000055ccd7cf9f54 in main ()
No symbol table info available.
A debugging session is active.
Inferior 1 [process 8230] will be detached.

Quit anyway? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 8230) detached]
-------------- end dumpstack.sh output ----------------
Running: sh Tools/scripts/dumpcore.sh 8230 >dumpcore.sh_arduplane.8230.out 2>&1
dumpcore.sh has been run. Output was:
-------------- begin dumpcore.sh output ----------------
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
0x00007fa1869ce45a in __GI___wait4 (pid=8249, stat_loc=stat_loc@entry=0x7ffc888ded48, options=options@entry=0, usage=usage@entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
30 …/sysdeps/unix/sysv/linux/wait4.c: No such file or directory.
warning: target file /proc/8230/cmdline contained unexpected null characters
Saved corefile ap-8250.core
A debugging session is active.

    Inferior 1 [process 8230] will be detached.

Quit anyway? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 8230) detached]
-------------- end dumpcore.sh output ----------------

No symbol table info available.
#8 0x000055ccd7de3641 in AP_Logger::validate_structures(LogStructure const*, unsigned char) ()
No symbol table info available.
#9 0x000055ccd7de392d in AP_Logger::Init(LogStructure const*, unsigned char) ()
No symbol table info available.

I would like some advice on how to deal with this error and make SITL simulation work well.

Well, your modified code does not work. It exits with the error above. It is quite hard to tell without exactly knowing what and how did you modified.
But for first, did you merged your modifications from the old arudpilot to the latest ?
For debugging see these videos, they tell everything that you need :

Thank you very much for your reply and the video on how to debug.
The part that I have modified is the part of the file that controls the UAV. In terms of file names, it is the attitude.cpp, Parameters.cpp, and Parameter.h files in the ArduPlane file.
The part causing the segmentation fault this time is the AP_Logger file, AP_HAL file, and other files in the libraries file, and the programs in these files have not been modified in any way from their source files.
Also, the version of ardupilot is Plane 4.1.7, so we are not using the latest files.
If I do not use the latest version of ardupilot, does the SITL simulation generate an error?

I’m sorry. I deleted my reply once by mistake and I am not sure if you received my reply well, so please let me know if you did not receive my reply well.

The build environment could be different, especially with something old as 4.1
So I recommend to clone your repository at the version you used, and run the tool setup from that version.

Thank you very much for your answer.
I am going to try to do it this way.

@Eosbandi I’m seeing a similar problem, but my exception is

ERROR: Floating point exception - aborting.

This is fresh source. Thanks.

UPDATE:
The error is bogus. It came down to gdp not being codesigned, but that still wasn’t the problem. I needed to specify --lldb to sim_vehicle.py. That was all well and good, and I was able to get past that error, and on to the next:

Process 11220 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_ARITHMETIC (code=EXC_I386_SSEEXTERR, subcode=0x1921)
    frame #0: 0x000000010004b38b ardurover`AP_Declination::get_mag_field_ef(float, float, float&, float&, float&) + 91
ardurover`AP_Declination::get_mag_field_ef:
->  0x10004b38b <+91>:  cvttps2dq %xmm3, %xmm3
    0x10004b38f <+95>:  cvtdq2ps %xmm3, %xmm5
    0x10004b392 <+98>:  mulss  %xmm6, %xmm5
    0x10004b396 <+102>: leaq   0x2167db(%rip), %rcx      ; AP_Declination::SAMPLING_MAX_LAT
Process 11220 launched: '/Users/davidbbitton/src/ardupilot/build/sitl/bin/ardurover' (x86_64)
(lldb) 

any ideas on this one?

Perhaps somebody who uses mac to build sitl can help. All I can say that it is working on Ubuntu and WSL2/Ubuntu

My SITL only works on WSL1 and not WSL2…

I’m using Ubuntu.

That would be a problem with your setup,wsl2 works flawlessly.

but I don’t have a clue about this.

it compiles and runs well in WSL2, but won’t connect to window’s mission planner sometimes.

If the mistake is critical, my connection would not estabilished only for one time.

but at first time it connects and after that it won’t connect. I checked anti-virus and firewalls but don’t have clue.

@Eosbandi I finally have SITL on the debugger. The exception is being thrown at line 280 in SIM_Aircraft.cpp

that math becomes:

1019 += 833.333312 - 18446744073709366476

and yeah, thats not fitting in an int64. I’m now off to see what’s up.