Servers by jDrones

Question about Copter initialisation


(Aditya) #1

Hi,
I have some custom code, which needs initialisation. I used the Copter::setup() function (ArduCopter.cpp) to call my initialisation functions, assuming that this function will be called after every power cycle, since it is doing the basic system initialisation. But after some digging around, I found the following: If I restart my Pixhawk (with all the peripherals connected) by simply removing the power cord and plugging it in again, the setup() function does not get called! I verified this by sending a message to GCS through this function. The message reaches only some times (e.g. when I command a reboot through GCS), but not when I disconnect the power and reconnect.

Is my understanding wrong? Should I be using some other function to initialise my custom code?


(peterbarker) #2

I have some custom code, which needs initialisation. I used the
Copter::setup() function (ArduCopter.cpp) to call my initialisation
functions, assuming that this function will be called after every power
cycle, since it is doing the basic system initialisation. But after some
digging around, I found the following: If I restart my Pixhawk (with all
the peripherals connected) by simply removing the power cord and plugging
it in again, the setup() function does not get called! I verified this by
sending a message to GCS through this function. The message reaches only
some times (e.g. when I command a reboot through GCS), but not when I
disconnect the power and reconnect.

Is my understanding wrong? Should I be using some other function to
initialise my custom code?

If you’re connecting via a radio - are you removing power to the radio to?
If so, the radio modems probably aren’t synced when going through the
setup routine.

Instead, to convince yourself you’re going through the setup routine,
set a variable in setup() and send a gcs().send_text(…) in a 1Hz loop
containing the value of that variable.


(Aditya) #3

Hi,
Thanks for your reply! Actually I am using the USB connection during testing, but I also need to connect battery since I’m doing custom payload testing and it needs power. I am disconnecting both power and USB, when I “disconnect”. And when I reconnect, I’m not seeing the gcs_send_text commands from setup().

For now I’ve circumvented the problem by using my own internal initialization variable, but I’m still curious, since it doesn’t sound right that setup won’t be called after a power cycle.