minhtq98
(minhtq98)
December 11, 2018, 4:00am
1
Hi everyone,
In version 3.2 when the source code still uses Arduino, the entry point could be found in loop(), which then calls init() and the fast_loop() functions. Then the source code moved to C++, but no main function was found, so I cant find the way how the init() and fast_loop() functions are called. I searched in the forum, but cannot find. It is so strange that such a popular topic like this was not discussed. I highly appreciate if anybody can explain me where is the entry point of the Arducopter.
1 Like
chase this define up:
Peter
minhtq98
(minhtq98)
December 12, 2018, 1:04am
3
Hi Peter,
Thank you very much for the help. I’m now reading the document, but it seems that things are clear now.
minhtq98
(minhtq98)
December 12, 2018, 7:35am
4
Hi Peter,
I saw how setup() and loop() are defined and called, but I still haven’t seen how fast_loop() is called.
fast_loop is a terrible idea and should die
if (_loop_timer_start_us == 0) {
_loop_timer_start_us = sample_time_us;
_last_loop_time_s = get_loop_period_s();
} else {
_last_loop_time_s = (sample_time_us - _loop_timer_start_us) * 1.0e-6;
}
// Execute the fast loop
// ---------------------
if (_fastloop_fn) {
_fastloop_fn();
}
// tell the scheduler one tick has passed
tick();
// run all the tasks that are due to run. Note that we only
// have to call this once per loop, as the tasks are scheduled
// in multiples of the main loop tick. So if they don't run on
// the first call to the scheduler they won't run on a later
minhtq98
(minhtq98)
December 13, 2018, 2:58am
6
I still don’t understand. Line 249 checks if _fastloop_fn variable is true then calls _fastloop_fn() function. So my question is that _fastloop_fn is variable or function?
_fn is typical of symbols that you might not expect to be a function
pointer actually being a function
So yes, it’s a function. It’s passed in in the Scheduler constructor. In
Copter’s case, here:
https://github.com/ardupilot/ardupilot/blob/wait-heartbeat-fixes/ArduCopter/Copter.h#L221
Note that adding stuff to the fastloop function is almost certainly not
what you need to do.
Perhaps if you outline what you’re intending someone might suggest how to
get your code being called.
minhtq98
(minhtq98)
December 14, 2018, 1:42am
8
Thank you for your help and time. Actually I don’t have any concrete intention. I only want to understand the way Arducopter is programmed so that I can learn how to do if later I meet a similar case. But when I try to access the link you provided, I met with 404 error. Can you provide me with another link? Thank you in advance
minhtq98
(minhtq98)
December 14, 2018, 1:50am
9
Hi Peter,
I have a look at copter.h and may be this is what you have talked about
// main loop scheduler
AP_Scheduler scheduler{FUNCTOR_BIND_MEMBER(&Copter::fast_loop, void)};
Am I right?
My bad, sorry. Fixed link:
static const AP_FWVersion fwver;
// key aircraft parameters passed to multiple libraries
AP_Vehicle::MultiCopter aparm;
// Global parameters are all contained within the 'g' class.
Parameters g;
ParametersG2 g2;
// main loop scheduler
AP_Scheduler scheduler{FUNCTOR_BIND_MEMBER(&Copter::fast_loop, void)};
// AP_Notify instance
AP_Notify notify;
// used to detect MAVLink acks from GCS to stop compassmot
uint8_t command_ack_counter;
// primary input control channels
RC_Channel *channel_roll;
RC_Channel *channel_pitch;
mw66
(Mw66)
July 12, 2023, 11:17pm
11
/*
* Copyright (C) 2016 Intel Corporation. All rights reserved.
*
* This file is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "HAL.h"
This file has been truncated. show original
in libraries/AP_HAL/AP_HAL_Main.h
the macro expend to:
int main(int argc, char* const argv[]);
Why this is main
? where is the entry function setup()
and loop()
defined?