From 2813bad7f87d79ce6b4e8bdf1731ee708091c799 Mon Sep 17 00:00:00 2001 From: Antoine Drouin Date: Mon, 19 Jul 2010 01:03:52 +0000 Subject: [PATCH] adding hardware test programm --- conf/settings/settings_lisa_test_boards.xml | 9 + sw/airborne/lisa/test/test_board.c | 318 ++++++++++++++++++++ sw/airborne/lisa/test/test_board.h | 21 ++ 3 files changed, 348 insertions(+) create mode 100644 conf/settings/settings_lisa_test_boards.xml create mode 100644 sw/airborne/lisa/test/test_board.c create mode 100644 sw/airborne/lisa/test/test_board.h diff --git a/conf/settings/settings_lisa_test_boards.xml b/conf/settings/settings_lisa_test_boards.xml new file mode 100644 index 0000000000..650dbadd5c --- /dev/null +++ b/conf/settings/settings_lisa_test_boards.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sw/airborne/lisa/test/test_board.c b/sw/airborne/lisa/test/test_board.c new file mode 100644 index 0000000000..d464365898 --- /dev/null +++ b/sw/airborne/lisa/test/test_board.c @@ -0,0 +1,318 @@ +/* + * $Id$ + * + * Copyright (C) 2008-2009 Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi 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 2, or (at your option) + * any later version. + * + * paparazzi 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 paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#define DATALINK_C + +#include "test_board.h" + +#include "std.h" +#include "init_hw.h" +#include "sys_time.h" +#include "downlink.h" +#include "led.h" +#include "uart.h" + +#include "datalink.h" +#include "settings.h" + +#include "lisa/lisa_baro.h" +#include "booz/actuators/booz_actuators_pwm.h" + +static inline void main_init( void ); +static inline void main_periodic_task( void ); +static inline void main_event_task( void ); + +static void test_none_start(void); +static void test_none_periodic(void); +static void test_none_event(void); + +static void test_baro_start(void); +static void test_baro_periodic(void); +static void test_baro_event(void); + +static void test_bldc_start(void); +static void test_bldc_periodic(void); +static void test_bldc_event(void); + +static void test_srvo_start(void); +static void test_srvo_periodic(void); +static void test_srvo_event(void); + +static void test_uart_start(void); +static void test_uart_periodic(void); +static void test_uart_event(void); + +static void all_led_green(void); +static void all_led_red(void); +static void all_led_off(void); + +struct TestFuns { + void (*_start)(void); + void (*_periodic)(void); + void (*_event)(void); +}; + +struct TestFuns tests[] = { + {._start=test_none_start, ._periodic=test_none_periodic, ._event=test_none_event}, + {._start=test_baro_start, ._periodic=test_baro_periodic, ._event=test_baro_event}, + {._start=test_bldc_start, ._periodic=test_bldc_periodic, ._event=test_bldc_event}, + {._start=test_srvo_start, ._periodic=test_srvo_periodic, ._event=test_srvo_event}, + {._start=test_uart_start, ._periodic=test_uart_periodic, ._event=test_uart_event} +}; + +enum TestType cur_test; + + +int main( void ) { + main_init(); + while(1) { + if (sys_time_periodic()) + main_periodic_task(); + main_event_task(); + } + return 0; +} + +static inline void main_init( void ) { + hw_init(); + sys_time_init(); + led_init(); + + baro_init(); + booz_actuators_pwm_hw_init(); + + cur_test = TestTypeNone; + +} + +static inline void main_periodic_task( void ) { + + LED_PERIODIC(); + RunOnceEvery(256, {DOWNLINK_SEND_ALIVE(DefaultChannel, 16, MD5SUM);}); + + tests[cur_test]._periodic(); + +} + +static inline void main_event_task( void ) { + + DatalinkEvent(); + + tests[cur_test]._event(); + +} + +void start_test(void) { + all_led_off(); + tests[cur_test]._start(); +} + + + + +/* + * + * Test nothing + * + */ +static void test_none_start(void) {} +static void test_none_periodic(void) {} +static void test_none_event(void) {} + + +/* + * + * Test baro + * + */ +static inline void test_baro_on_baro_diff(void); +static inline void test_baro_on_baro_abs(void); +static void test_baro_start(void) {all_led_green();} +static void test_baro_periodic(void) { RunOnceEvery(2, {baro_periodic();}); } +static void test_baro_event(void) {BaroEvent(test_baro_on_baro_abs, test_baro_on_baro_diff);} +static inline void test_baro_on_baro_abs(void) { + RunOnceEvery(5,{DOWNLINK_SEND_BOOZ_BARO2_RAW(DefaultChannel, &baro.abs_raw, &baro.diff_raw);}); +} +static inline void test_baro_on_baro_diff(void) { + RunOnceEvery(5,{DOWNLINK_SEND_BOOZ_BARO2_RAW(DefaultChannel, &baro.abs_raw, &baro.diff_raw);}); +} + +/* + * + * Test motor controller + * + */ +static void test_bldc_start(void) {} +static void test_bldc_periodic(void) { + i2c1_buf[0] = 0x04; + i2c1_transmit(0x58, 1, NULL); +} +static void test_bldc_event(void) {} + + +/* + * + * Test servos + * + */ +static void test_srvo_start(void) {} +static void test_srvo_periodic(void) { + static float foo = 0.; + foo += 0.0025; + int32_t bar = 1500 + 500. * sin(foo); + for (uint8_t i=0; i<6; i++) + booz_actuators_pwm_values[i] = bar; + booz_actuators_pwm_commit(); +} +static void test_srvo_event(void) {} + + + +/* + * + * Test Uarts + * + */ +enum UartTestType { OneToThree, ThreeToOne}; +static const uint8_t buf_src[] = { 42, 43, 44, 45, 46, 122, 126, 128 }; +static uint8_t buf_dest[sizeof(buf_src)]; +static uint8_t idx_tx; +static uint8_t idx_rx; +static enum UartTestType direction; + +static void test_uart_start(void) { + idx_rx = 0; + idx_tx = 0; + direction = OneToThree; +} + +static void test_uart_periodic(void) { + + if (idx_tx