Closed GoogleCodeExporter closed 9 years ago
I'll second this one and add a request for a user hook in the initialization
code also
Andrew
Original comment by agmatth...@gmail.com
on 28 Aug 2011 at 1:37
Third!
Original comment by loonmoun...@gmail.com
on 29 Sep 2011 at 11:34
Fourth! ;)
Original comment by voipmi...@gmail.com
on 29 Sep 2011 at 11:12
If anyone would be able to make an implementation I'd be glad to include it.
#if exist "userhooks.pde"
userhook_1hz;
#endif
that actually is not valid code. I don't know a way to handle it exactly, so
please send me a proof of concept!
Jason
Original comment by jasonshort
on 29 Sep 2011 at 11:16
One way to do that is :
In the 1Hz loop add
#ifdef USERHOOK_1HZ
userhook_1hz();
#endif
Then the user who wants to use this feature, will drop his PDE file in the
arducopter directory (the file name is not important) and add
#define USERHOOK_1HZ in APM_config.h
Original comment by list...@free.fr
on 30 Sep 2011 at 5:54
Alternatively you could do something like this:
in APM_Config.h
#define USERHOOK_INIT userhook_init(); // the choice of function name is up to
the user and does not have to match these
#define USERHOOK_1HZ userhook_1hz();
#define USERHOOK_FASTLOOP userhook_fastloop();
#define USERHOOK_MEDIUMLOOP userhook_mediumloop();
#define USERHOOK_SLOWLOOP userhook_slowloop();
//repeat for each other loop
#define USERHOOK_xHz userhook_xHz(); // where xHz matches any other timing
loops
In init_ardupilot() in system.pde
#ifdef USERHOOK_INIT
USERHOOK_INIT
#endif
In each of the loops in Arducopter.pde insert appropriate code eg:
#ifdef USERHOOK_1HZ
USERHOOK_1HZ
#endif
#ifdef USERHOOK_FASTLOOP
USERHOOK_FASTLOOP
#endif
//etc - repeat as necessary
Then in a pde file in the same directory (eg I have used userhooks.pde)
void userhook_init()
{
// my init stuff
}
void userhook_1hz()
{
// my 1 hz stuff
}
//etc - repeat as required
This way allows the user to have their own file name and function names and
only requires editing of APM_Config.h before compiling
This compiles OK in Arduino 0022 but is not yet uploaded to a uC for testing
Original comment by agmatth...@gmail.com
on 30 Sep 2011 at 11:27
and further to the last comments it would be good to have the following in the
global variables section of arducopter.pde
#ifdef USERVARIABLES
#include USERVARIABLES
#endif
then in APM_Config.h
#define USERVARIABLES "UserVariables.h"
and you create your own UserVariables.h file with any user specific variables
Original comment by agmatth...@gmail.com
on 1 Oct 2011 at 2:47
I have a led sequencer for 8 led(strip)s implemented in my code. It's fully
encapsulated in #ifdef statements so it's only compiled if you set #define
SHOW_LEDS 1
I have flown this code with 2.0.44 and 2.0.46 without issues in stabilise,
althold, simple, loiter, RTL and auto.
Multiple sequences are programmable and you can control them with channel 7. I
assigned channel 7 to a dial, so I can choose different patterns with the lower
portion of channel 7 (<600). When channel 7 is set high (>800) it can still be
used for the other possible options (set hover throttle, simple, etc).
Furthermore you could also program a special sequence when chan7 > 800, so you
know when you have the chan7 effect (simple, set hover throttle, in flight
levelling) engaged.
It compiles under 127K for a hexa plus frame, so still usable on atmega 1280
boards (if you turn motorleds off and set ch7 to CH7_ADC_FILTER filtering)
I used bitmath and bitwise setting of PORTK (AN8-AN15) to gain speed as for
fast sequences it hooks into the 50hz loop. This might reduce readability of
the code, but I've added plenty of comment.
I've attached the modified files from version 2.0.47 (unflown on 47, but no
problems on 44 and 46)
Original comment by u4e...@hotmail.com
on 7 Oct 2011 at 8:39
Attachments:
All,
I have updated a clean copy of version 2.0.48 with a my 'userhooks' code.
Please see attached.
@jasonshort please consider including this in your master branch of the
Arducopter code for others to use.
To use userhooks
Modify the "APM_Config.h" file to uncomment the hooks you wish to use
Then in "usercode.pde" you add or edit the hook functions you need to do your
thing.
You can also edit "userVariables.h" to include your own global variables to the
arducopter code
I've included hooks for initialisation, global variables, and the main loops.
Others may want hooks in additional places, eg in logs, leds, etc
regards
Andrew
Original comment by agmatth...@gmail.com
on 15 Oct 2011 at 2:29
Attachments:
Andrew,
I integrated the code into 49. It's on git now.
Jason
Original comment by jasonshort
on 15 Oct 2011 at 10:28
Jason,
I missed one file that needs a patch
We need to include a hook in the init function in system.pde to allow
initialising libraries or other such code.
Can you add this change in next release. Attached file is 2.0.49 "system.pde"
with modification
-Andrew
Original comment by agmatth...@gmail.com
on 18 Oct 2011 at 6:31
Attachments:
On GIT now,
Jason
Original comment by jasonshort
on 18 Oct 2011 at 6:52
Original comment by jasonshort
on 29 Oct 2011 at 9:08
Original issue reported on code.google.com by
pvwor...@gmail.com
on 27 Jul 2011 at 11:49