This fixes the initialization for Linux boards using the PX4Flow module.
The problem is that after the conversion to use I2CDevice we now need to
use I2CDeviceManager, which is statically constructed after the vehicle
object.
So, if we try to call hal.i2c_mgr->get_device(), it will call the
get_device() method before the constructor is called and receive a
SIGSEGV:
Program received signal SIGSEGV, Segmentation fault.
0x000b06c0 in OpticalFlow::OpticalFlow (this=0x140914 <copter+4980>, ahrs=...)
at ../../libraries/AP_OpticalFlow/OpticalFlow.cpp:54
54 ../../libraries/AP_OpticalFlow/OpticalFlow.cpp: No such file or directory.
Each library in ardupilot is a folder with the source in. That avoids build
failures when there are files in libraries/. That fixes#4099 ("waf doesn't
seem to like TAGS files") and #4093 ("sim_vehicle.py /w waf /w eclipse project
broken on Cygwin").
That problem can be reproduced by just creating a file in libraries/ and trying
to build with waf.
There should be a better way to confirm a path is an ardupilot library. That
can be done later.
Running the vehicles we check the stack size doesn't grow too much by
enabling the DEBUG_STACK in the scheduler. Even on 64bit boards the
stack is consistent around 4k. Just to be a little conservative, let it
be a little bit more that that: 256kB.
Since we have RT prio and we call mlock(), the memory for the stack of
each thread is locked in memory. This means we are effectively taking
that much memory. The default stack size varies per distro, but it's
common to have 8MB for 64 bit boards and 4MB for 32 bit boards. Here is
the output of ps -L -o 'comm,rtprio,rss $(pidof arducopter-quad)', showing the
RSS of arducopter-quad before and after this change:
Before:
COMMAND RTPRIO RSS
arducopter-quad 12 46960
sched-timer 15 46960
sched-uart 14 46960
sched-rcin 13 46960
sched-tonealarm 11 46960
sched-io 10 46960
After:
COMMAND RTPRIO RSS
arducopter-quad 12 7320
sched-timer 15 7320
sched-uart 14 7320
sched-rcin 13 7320
sched-tonealarm 11 7320
sched-io 10 7320
When trying to execute sim_vehicle.py this is the current output:
Warning: Could not find '../Tools/autotest/../../ArduCopter/../build/sitl/bin/arducopter-quad',
starting '/bin/bash' instead. Please check your profile settings.
Fix the path to the binary and use absolute paths to ease the debug.