AP_Module: added external module hook library

this allows for external modules to be called at defined hook
locations in ArduPilot. The initial example is a module that consumes
the AHRS state, but this can be generalised to a wide variety of hooks
This commit is contained in:
Andrew Tridgell committed 2016-07-14 13:39:46 +10:00
1 parent 59e4e8def6
commit bd00beaf99
8 files changed
+466

No files matched your search

@@ -0,0 +1 @@
include ../../../../mk/apm.mk
@@ -0,0 +1,38 @@
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
//
// Simple test for the AP_AHRS interface
//
#include <AP_ADC/AP_ADC.h>
#include <AP_AHRS/AP_AHRS.h>
#include <AP_HAL/AP_HAL.h>
#include <AP_Module/AP_Module.h>
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
// sensor declaration
AP_InertialSensor ins;
AP_GPS gps;
AP_Baro baro;
AP_SerialManager serial_manager;
// choose which AHRS system to use
AP_AHRS_DCM ahrs(ins, baro, gps);
void setup(void)
{
serial_manager.init();
ins.init(100);
baro.init();
ahrs.init();
gps.init(NULL, serial_manager);
}
void loop(void)
{
ahrs.update();
}
AP_HAL_MAIN();
@@ -0,0 +1,13 @@
# minimal makefile setup for ARM linux targets
CC=arm-linux-gnueabihf-gcc
CFLAGS=-Wall -fPIC -g -shared
all: moduletest.so
moduletest.so: moduletest.c
$(CC) $(CFLAGS) -o moduletest.so moduletest.c -ldl
clean:
rm -f moduletest.so
@@ -0,0 +1,37 @@
/*
very simple example module
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "../../../AP_Module_Structures.h"
void hook_setup_start(uint64_t time_us)
{
printf("setup_start called\n");
}
void hook_setup_complete(uint64_t time_us)
{
printf("setup_complete called\n");
}
#define degrees(x) (x * 180.0 / M_PI)
void hook_AHRS_update(const struct AHRS_state *state)
{
static uint64_t last_print_us;
if (state->time_us - last_print_us < 1000000UL) {
return;
}
last_print_us = state->time_us;
// print euler angles once per second
printf("AHRS_update (%.1f,%.1f,%.1f)\n",
degrees(state->eulers[0]),
degrees(state->eulers[1]),
degrees(state->eulers[2]));
}
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
def build(bld):
bld.ap_example(
use='ap',
)