diff --git a/conf/airframes/airframe.dtd b/conf/airframes/airframe.dtd index 9a1e5c36b6..5950084218 100644 --- a/conf/airframes/airframe.dtd +++ b/conf/airframes/airframe.dtd @@ -1,21 +1,18 @@ - + - - - - - + + @@ -54,7 +51,6 @@ driver CDATA #IMPLIED> - - - - - - - @@ -87,6 +72,9 @@ value CDATA #REQUIRED command CDATA #IMPLIED servo CDATA #IMPLIED> + + diff --git a/conf/firmwares/subsystems/shared/actuators_4015.makefile b/conf/firmwares/subsystems/shared/actuators_4015.makefile index 6451c757b0..cc1951717a 100644 --- a/conf/firmwares/subsystems/shared/actuators_4015.makefile +++ b/conf/firmwares/subsystems/shared/actuators_4015.makefile @@ -1,4 +1,4 @@ # for Tiny v1.1 -$(TARGET).CFLAGS += -DACTUATORS=\"servos_4015_MAT_hw.h\" -DSERVOS_4015_MAT -$(TARGET).srcs += $(SRC_ARCH)/servos_4015_MAT_hw.c actuators.c +$(TARGET).CFLAGS += -DACTUATORS -DSERVOS_4015_MAT +$(TARGET).srcs += $(SRC_ARCH)/subsystems/actuators/servos_4015_MAT_hw.c subsystems/actuators.c diff --git a/conf/firmwares/subsystems/shared/actuators_4017.makefile b/conf/firmwares/subsystems/shared/actuators_4017.makefile index 471e3c3433..7750d2a992 100644 --- a/conf/firmwares/subsystems/shared/actuators_4017.makefile +++ b/conf/firmwares/subsystems/shared/actuators_4017.makefile @@ -1,4 +1,4 @@ # for Tiny v2 or Twog v1 -$(TARGET).CFLAGS += -DACTUATORS=\"servos_4017_hw.h\" -DSERVOS_4017 -$(TARGET).srcs += $(SRC_ARCH)/servos_4017_hw.c actuators.c +$(TARGET).CFLAGS += -DACTUATORS -DSERVOS_4017 +$(TARGET).srcs += $(SRC_ARCH)/subsystems/actuators/servos_4017_hw.c subsystems/actuators.c diff --git a/conf/firmwares/subsystems/shared/actuators_direct.makefile b/conf/firmwares/subsystems/shared/actuators_direct.makefile index 019bb6fac2..21ed2f6fb2 100644 --- a/conf/firmwares/subsystems/shared/actuators_direct.makefile +++ b/conf/firmwares/subsystems/shared/actuators_direct.makefile @@ -1,5 +1,5 @@ -$(TARGET).CFLAGS += -DACTUATORS=\"subsystems/actuators/actuators_pwm.h\" -DSERVOS_DIRECT -$(TARGET).srcs += subsystems/actuators/actuators_pwm.c actuators.c +$(TARGET).CFLAGS += -DACTUATORS -DSERVOS_DIRECT +$(TARGET).srcs += subsystems/actuators/actuators_pwm.c subsystems/actuators.c $(TARGET).srcs += $(SRC_ARCH)/subsystems/actuators/actuators_pwm_arch.c diff --git a/conf/firmwares/subsystems/shared/actuators_ppm.makefile b/conf/firmwares/subsystems/shared/actuators_ppm.makefile index 99171e4448..f88eb3e3c0 100644 --- a/conf/firmwares/subsystems/shared/actuators_ppm.makefile +++ b/conf/firmwares/subsystems/shared/actuators_ppm.makefile @@ -5,6 +5,6 @@ # The PPM is output on the SERV_CLK pin. The PPM frame rate, pulse width, and number of channels # can be adjusted in the "servos_ppm_hw.h" file to suit your particular receiver. -$(TARGET).CFLAGS += -DACTUATORS=\"servos_ppm_hw.h\" -DSERVOS_PPM_MAT -$(TARGET).srcs += $(SRC_ARCH)/servos_ppm_hw.c actuators.c +$(TARGET).CFLAGS += -DACTUATORS -DSERVOS_PPM_MAT +$(TARGET).srcs += $(SRC_ARCH)/subsystems/actuators/servos_ppm_hw.c subsystems/actuators.c diff --git a/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c b/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c index 1b9a020303..ed2335ff66 100644 --- a/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c +++ b/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c @@ -37,7 +37,15 @@ #define SYS_TICK_IT TIR_MR0I #if defined ACTUATORS && ( defined SERVOS_4017 || defined SERVOS_4015_MAT || defined SERVOS_PPM_MAT) -#include ACTUATORS +#ifdef SERVOS_4015_MAT +#include "subsystems/actuators/servos_4015_MAT_hw.h" +#endif +#ifdef SERVOS_4017 +#include "subsystems/actuators/servos_4017_hw.h" +#endif +#ifdef SERVOS_PPM +#include "subsystems/actuators/servos_ppm_hw.h" +#endif #else #define ACTUATORS_IT 0x00 #endif /* ACTUATORS */ diff --git a/sw/airborne/arch/lpc21/servos_csc.h b/sw/airborne/arch/lpc21/servos_csc.h deleted file mode 100644 index b7d8acb6b3..0000000000 --- a/sw/airborne/arch/lpc21/servos_csc.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SERVOS_CSC_H -#define SERVOS_CSC_H - -#include "LPC21xx.h" -#include "generated/airframe.h" -#include "actuators.h" -#include "mcu_periph/sys_time.h" - -#define SERVOS_TICS_OF_USEC(s) CPU_TICKS_OF_USEC(s) -#define ChopServo(x,a,b) Chop(x, a, b) -#define SERVO_COUNT 4 - -#define Actuator(i) actuators[i] - -static inline void ActuatorsCommit(void) -{ - -} - -#endif /* SERVOS_CSC_H */ diff --git a/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.c b/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.c index 2dfd68cdc8..ae0a10361b 100644 --- a/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.c @@ -28,7 +28,7 @@ const uint8_t pwm_latch_value = 0 #endif ; -void actuators_init ( void ) { +void actuators_pwm_init ( void ) { /* configure pins for PWM */ #if defined PWM_SERVO_0 diff --git a/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.h b/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.h index 0032b075dc..181f0d5b0c 100644 --- a/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.h +++ b/sw/airborne/arch/lpc21/subsystems/actuators/actuators_pwm_arch.h @@ -15,7 +15,7 @@ #define SERVO_REG_5 PWMMR2 #define COMMAND_(i) SERVO_REG_ ## i -#define Actuator(i) COMMAND_(i) +#define ActuatorPwm(i) COMMAND_(i) /* @@ -76,8 +76,11 @@ PWM6 PWM2 SSEL0 EINT2 P0.7 extern const uint8_t pwm_latch_value; -#define ActuatorsCommit() { \ +#define ActuatorsPwmCommit() { \ PWMLER = pwm_latch_value; \ } +extern void actuators_pwm_init(void); +#define ActuatorsPwmInit() actuators_pwm_init() + #endif /* ACTUATORS_PWM_ARCH_H */ diff --git a/sw/airborne/arch/lpc21/servos_4015_MAT_hw.c b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.c similarity index 96% rename from sw/airborne/arch/lpc21/servos_4015_MAT_hw.c rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.c index cf254ffc59..5c777f8235 100644 --- a/sw/airborne/arch/lpc21/servos_4015_MAT_hw.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.c @@ -1,6 +1,4 @@ /* - * $Id$ - * * Copyright (C) 2006 Antoine Drouin * * This file is part of paparazzi. @@ -27,7 +25,7 @@ */ -#include "actuators.h" +#include "subsystems/actuators.h" #include "paparazzi.h" #include "generated/airframe.h" @@ -36,7 +34,7 @@ uint32_t servos_delay = SERVO_REFRESH_TICS; #define START_TIMEOUT 0xFFFF; -void actuators_init ( void ) { +void actuators_4015_init ( void ) { /* select clock pin as MAT0.1 output */ IO0DIR |= _BV(SERVO_CLOCK_PIN); SERVO_CLOCK_PINSEL |= SERVO_CLOCK_PINSEL_VAL << SERVO_CLOCK_PINSEL_BIT; diff --git a/sw/airborne/arch/lpc21/servos_4015_MAT_hw.h b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.h similarity index 92% rename from sw/airborne/arch/lpc21/servos_4015_MAT_hw.h rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.h index d157e86bda..2e03368e5f 100644 --- a/sw/airborne/arch/lpc21/servos_4015_MAT_hw.h +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_MAT_hw.h @@ -42,9 +42,11 @@ #define _4015_NB_CHANNELS 8 extern uint16_t servos_values[_4015_NB_CHANNELS]; -#define Actuator(i) servos_values[i] +#define Actuator4015(i) servos_values[i] -#define ActuatorsCommit() {} +extern void actuators_4015_init(void); +#define Actuators4015Commit() {} +#define Actuators4015Init() actuators_4015_init() extern uint8_t servos_4015_idx; extern uint32_t servos_delay; diff --git a/sw/airborne/arch/lpc21/servos_4015_hw.c b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.c similarity index 77% rename from sw/airborne/arch/lpc21/servos_4015_hw.c rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.c index 60eeb6af5e..836d37829a 100644 --- a/sw/airborne/arch/lpc21/servos_4015_hw.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.c @@ -1,4 +1,25 @@ -#include "actuators.h" +/* + * Copyright (C) 2006 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 "subsystems/actuators.h" #include "armVIC.h" #include "generated/airframe.h" @@ -19,7 +40,7 @@ uint16_t servos_values[_4015_NB_CHANNELS]; #define PWMIR_MRI_SERV1 PWMIR_MR2I -void actuators_init ( void ) { +void actuators_4015_init ( void ) { /* PWM selected as IRQ */ VICIntSelect &= ~VIC_BIT(VIC_PWM); /* PWM interrupt enabled */ diff --git a/sw/airborne/arch/lpc21/servos_4015_hw.h b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.h similarity index 83% rename from sw/airborne/arch/lpc21/servos_4015_hw.h rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.h index 60fe1593a0..eab191954b 100644 --- a/sw/airborne/arch/lpc21/servos_4015_hw.h +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw.h @@ -35,9 +35,11 @@ #define _4015_NB_CHANNELS 8 extern uint16_t servos_values[_4015_NB_CHANNELS]; -#define Actuator(i) servos_values[i] +#define Actuator4015(i) servos_values[i] -#define ActuatorsCommit() {} +extern void actuators_4015_init(void); +#define Actuators4015Commit() {} +#define Actuators4015Init() actuators_4015_init() void PWM_ISR ( void ) __attribute__((naked)); diff --git a/sw/airborne/arch/lpc21/servos_4015_hw_new.c b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw_new.c similarity index 82% rename from sw/airborne/arch/lpc21/servos_4015_hw_new.c rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw_new.c index 8a31b359b5..fdbc695682 100644 --- a/sw/airborne/arch/lpc21/servos_4015_hw_new.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4015_hw_new.c @@ -1,4 +1,25 @@ -#include "actuators.h" +/* + * Copyright (C) 2006 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 "subsystems/actuators.h" #include "armVIC.h" #include "generated/airframe.h" @@ -19,7 +40,7 @@ uint16_t servos_values[_4015_NB_CHANNELS]; #define PWMIR_MRI_SERV1 PWMIR_MR2I -void actuators_init ( void ) { +void actuators_4015_init ( void ) { /* PWM selected as IRQ */ VICIntSelect &= ~VIC_BIT(VIC_PWM); /* PWM interrupt enabled */ diff --git a/sw/airborne/arch/lpc21/servos_4017_hw.c b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.c similarity index 64% rename from sw/airborne/arch/lpc21/servos_4017_hw.c rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.c index 72022c414e..20a7d63b16 100644 --- a/sw/airborne/arch/lpc21/servos_4017_hw.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.c @@ -1,4 +1,25 @@ -#include "actuators.h" +/* + * Copyright (C) 2006 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 "subsystems/actuators.h" #include "paparazzi.h" #include "generated/airframe.h" @@ -7,7 +28,7 @@ uint8_t servos_4017_idx; #define START_TIMEOUT 0xFFFF; -void actuators_init ( void ) { +void actuators_4017_init ( void ) { /* select clock pin as MAT0.1 output */ IO0DIR |= _BV(SERVO_CLOCK_PIN); SERVO_CLOCK_PINSEL |= SERVO_CLOCK_PINSEL_VAL << SERVO_CLOCK_PINSEL_BIT; diff --git a/sw/airborne/arch/lpc21/servos_4017_hw.h b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.h similarity index 93% rename from sw/airborne/arch/lpc21/servos_4017_hw.h rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.h index 9f2989c791..865fa7cf79 100644 --- a/sw/airborne/arch/lpc21/servos_4017_hw.h +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_4017_hw.h @@ -19,9 +19,11 @@ #endif extern uint16_t servos_values[_4017_NB_CHANNELS]; -#define Actuator(i) servos_values[i] +#define Actuator4017(i) servos_values[i] -#define ActuatorsCommit() {} +extern void actuators_4017_init(void); +#define Actuators4017Commit() {} +#define Actuators4017Init() actuators_4017_init() extern uint8_t servos_4017_idx; diff --git a/sw/airborne/arch/lpc21/servos_ppm_hw.c b/sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.c similarity index 96% rename from sw/airborne/arch/lpc21/servos_ppm_hw.c rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.c index 6162f48f9f..5a5271e504 100644 --- a/sw/airborne/arch/lpc21/servos_ppm_hw.c +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.c @@ -26,7 +26,7 @@ * \ for a R/C receiver which has a microcontroller to drive the servos * \(not a 4015 or 4017 decade counter chip). */ -#include "actuators.h" +#include "subsystems/actuators.h" #include "paparazzi.h" #include "generated/airframe.h" @@ -36,7 +36,7 @@ uint32_t servos_delay = SERVO_REFRESH_TICS; #define START_TIMEOUT 0xFFFF; -void actuators_init ( void ) { +void actuators_ppm_init ( void ) { /* select ppm output pin as MAT0.1 output */ SERVO_CLOCK_PINSEL |= SERVO_CLOCK_PINSEL_VAL << SERVO_CLOCK_PINSEL_BIT; diff --git a/sw/airborne/arch/lpc21/servos_ppm_hw.h b/sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.h similarity index 94% rename from sw/airborne/arch/lpc21/servos_ppm_hw.h rename to sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.h index eb40c18d25..13e8b5e382 100644 --- a/sw/airborne/arch/lpc21/servos_ppm_hw.h +++ b/sw/airborne/arch/lpc21/subsystems/actuators/servos_ppm_hw.h @@ -40,9 +40,11 @@ #define _PPM_NB_CHANNELS 8 extern uint16_t servos_values[_PPM_NB_CHANNELS]; -#define Actuator(i) servos_values[i] +#define ActuatorPpm(i) servos_values[i] -#define ActuatorsCommit() {} +extern void actuators_ppm_init(void); +#define ActuatorsPpmCommit() {} +#define ActuatorsPpmInit() actuators_ppm_init() extern uint8_t servos_PPM_idx; extern uint32_t servos_delay; extern uint8_t ppm_pulse; /* 1=start of pulse, 0=end of pulse */ diff --git a/sw/airborne/boards/tiny_0.99.h b/sw/airborne/boards/tiny_0.99.h index b6915b33eb..f7055626c0 100644 --- a/sw/airborne/boards/tiny_0.99.h +++ b/sw/airborne/boards/tiny_0.99.h @@ -35,6 +35,12 @@ #define LED_2_BANK 1 #define LED_2_PIN 19 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4015.h" +#define ActuatorDefault(_x) Actuator4015(_x) +#define ActuatorsDefaultInit() Actuators4015Init() +#define ActuatorsDefaultCommit() Actuators4015Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/boards/tiny_1.1.h b/sw/airborne/boards/tiny_1.1.h index d76d4aa61e..21f806732f 100644 --- a/sw/airborne/boards/tiny_1.1.h +++ b/sw/airborne/boards/tiny_1.1.h @@ -46,6 +46,12 @@ #define POWER_SWITCH_LED 3 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4015.h" +#define ActuatorDefault(_x) Actuator4015(_x) +#define ActuatorsDefaultInit() Actuators4015Init() +#define ActuatorsDefaultCommit() Actuators4015Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/boards/tiny_2.0.h b/sw/airborne/boards/tiny_2.0.h index ac512c8ea9..c48148f6bd 100644 --- a/sw/airborne/boards/tiny_2.0.h +++ b/sw/airborne/boards/tiny_2.0.h @@ -49,6 +49,12 @@ #define POWER_SWITCH_LED 4 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4017.h" +#define ActuatorDefault(_x) Actuator4017(_x) +#define ActuatorsDefaultInit() Actuators4017Init() +#define ActuatorsDefaultCommit() Actuators4017Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/boards/tiny_2.1.h b/sw/airborne/boards/tiny_2.1.h index 572f2b6cf0..598f679c9f 100644 --- a/sw/airborne/boards/tiny_2.1.h +++ b/sw/airborne/boards/tiny_2.1.h @@ -86,6 +86,12 @@ #define Set_GPS_RESET_Pin_LOW() LED_ON(GPS_RESET) #define Open_GPS_RESET_Pin() ClearBit(LED_DIR(GPS_RESET), LED_PIN(GPS_RESET)) +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4017.h" +#define ActuatorDefault(_x) Actuator4017(_x) +#define ActuatorsDefaultInit() Actuators4017Init() +#define ActuatorsDefaultCommit() Actuators4017Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/boards/tiny_sim.h b/sw/airborne/boards/tiny_sim.h index c3cb2f3b91..c020bada14 100644 --- a/sw/airborne/boards/tiny_sim.h +++ b/sw/airborne/boards/tiny_sim.h @@ -29,6 +29,12 @@ #define LED_2_BANK 1 #define LED_2_PIN 19 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4017.h" +#define ActuatorDefault(_x) Actuator4017(_x) +#define ActuatorsDefaultInit() Actuators4017Init() +#define ActuatorsDefaultCommit() Actuators4017Commit() + /* p0.21 aka PWM5 */ #define SERV0_CLOCK_PIN 21 #define SERV0_CLOCK_PINSEL PINSEL1 diff --git a/sw/airborne/boards/umarim_1.0.h b/sw/airborne/boards/umarim_1.0.h index f17d5df75d..52d2c68688 100644 --- a/sw/airborne/boards/umarim_1.0.h +++ b/sw/airborne/boards/umarim_1.0.h @@ -30,6 +30,12 @@ #define LED_2_BANK 1 #define LED_2_PIN 24 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4017.h" +#define ActuatorDefault(_x) Actuator4017(_x) +#define ActuatorsDefaultInit() Actuators4017Init() +#define ActuatorsDefaultCommit() Actuators4017Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/boards/umarim_lite_2.0.h b/sw/airborne/boards/umarim_lite_2.0.h index 2690f73c0c..e3d8527cc8 100644 --- a/sw/airborne/boards/umarim_lite_2.0.h +++ b/sw/airborne/boards/umarim_lite_2.0.h @@ -30,6 +30,12 @@ #define LED_2_BANK 1 #define LED_2_PIN 24 +/* Default actuators driver */ +#define DEFAULT_ACTUATORS "subsystems/actuators/actuators_4017.h" +#define ActuatorDefault(_x) Actuator4017(_x) +#define ActuatorsDefaultInit() Actuators4017Init() +#define ActuatorsDefaultCommit() Actuators4017Commit() + /* P0.5 aka MAT0.1 */ #define SERVO_CLOCK_PIN 5 #define SERVO_CLOCK_PINSEL PINSEL0 diff --git a/sw/airborne/firmwares/fixedwing/fbw_downlink.h b/sw/airborne/firmwares/fixedwing/fbw_downlink.h index 38609e9082..0bc8cd48ab 100644 --- a/sw/airborne/firmwares/fixedwing/fbw_downlink.h +++ b/sw/airborne/firmwares/fixedwing/fbw_downlink.h @@ -40,7 +40,7 @@ #include "generated/periodic_telemetry.h" #include "generated/airframe.h" #include "commands.h" -#include "actuators.h" +#include "subsystems/actuators.h" #include "mcu_periph/uart.h" #include "firmwares/fixedwing/main_fbw.h" @@ -78,7 +78,7 @@ #endif // RADIO_CONTROL #ifdef ACTUATORS -#define PERIODIC_SEND_ACTUATORS(_trans, _dev) DOWNLINK_SEND_ACTUATORS(_trans, _dev, SERVOS_NB, actuators) +#define PERIODIC_SEND_ACTUATORS(_trans, _dev) DOWNLINK_SEND_ACTUATORS(_trans, _dev, ACTUATORS_NB, actuators) #else #define PERIODIC_SEND_ACTUATORS(_trans, _dev) {} #endif diff --git a/sw/airborne/firmwares/fixedwing/main_fbw.c b/sw/airborne/firmwares/fixedwing/main_fbw.c index 0c7b22060a..60e008d7d6 100644 --- a/sw/airborne/firmwares/fixedwing/main_fbw.c +++ b/sw/airborne/firmwares/fixedwing/main_fbw.c @@ -37,7 +37,7 @@ #include "mcu.h" #include "mcu_periph/sys_time.h" #include "commands.h" -#include "firmwares/fixedwing/actuators.h" +#include "subsystems/actuators.h" #include "subsystems/electrical.h" #include "subsystems/radio_control.h" #include "firmwares/fixedwing/autopilot.h" diff --git a/sw/airborne/firmwares/setup/setup_actuators.c b/sw/airborne/firmwares/setup/setup_actuators.c index 875e9dc2fb..1b72f44107 100644 --- a/sw/airborne/firmwares/setup/setup_actuators.c +++ b/sw/airborne/firmwares/setup/setup_actuators.c @@ -30,7 +30,7 @@ void dl_parse_msg( void ) { uint8_t servo_no = DL_SET_ACTUATOR_no(dl_buffer); uint16_t servo_value = DL_SET_ACTUATOR_value(dl_buffer); LED_TOGGLE(2); - if (servo_no < SERVOS_NB) + if (servo_no < ACTUATORS_NB) SetServo(servo_no, servo_value); } #ifdef DlSetting @@ -58,7 +58,7 @@ void init_fbw( void ) { actuators_init(); uint8_t i; - for(i = 0; i < SERVOS_NB; i++) { + for(i = 0; i < ACTUATORS_NB; i++) { SetServo(i, 1500); } @@ -83,7 +83,7 @@ void periodic_task_fbw(void) { /* SetServo(SERVO_THROTTLE, servo_value); */ RunOnceEvery(300, DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM)); - RunOnceEvery(300, DOWNLINK_SEND_ACTUATORS(DefaultChannel, DefaultDevice, SERVOS_NB, actuators )); + RunOnceEvery(300, DOWNLINK_SEND_ACTUATORS(DefaultChannel, DefaultDevice, ACTUATORS_NB, actuators )); } void event_task_fbw(void) { diff --git a/sw/airborne/actuators.c b/sw/airborne/subsystems/actuators.c similarity index 84% rename from sw/airborne/actuators.c rename to sw/airborne/subsystems/actuators.c index 0d2a660b22..ead30dea2d 100644 --- a/sw/airborne/actuators.c +++ b/sw/airborne/subsystems/actuators.c @@ -24,6 +24,13 @@ * */ -#include "firmwares/fixedwing/actuators.h" +#include "subsystems/actuators.h" -uint16_t actuators[SERVOS_NB]; +uint16_t actuators[ACTUATORS_NB]; + +void actuators_init(void) { + + // Init macro from generated airframe.h + AllActuatorsInit(); + +} diff --git a/sw/airborne/firmwares/fixedwing/actuators.h b/sw/airborne/subsystems/actuators.h similarity index 71% rename from sw/airborne/firmwares/fixedwing/actuators.h rename to sw/airborne/subsystems/actuators.h index 5f310f7a3c..9d3ee02fdb 100644 --- a/sw/airborne/firmwares/fixedwing/actuators.h +++ b/sw/airborne/subsystems/actuators.h @@ -1,5 +1,6 @@ /* * (c) 2003-2005 Pascal Brisset, Antoine Drouin + * (c) 2012 Gautier Hattenberger * * This file is part of paparazzi. * @@ -26,32 +27,29 @@ #ifndef ACTUATORS_H #define ACTUATORS_H -#if defined ACTUATORS - #include "paparazzi.h" -/** Defines SetActuatorsFromCommands() macro */ +/** Defines SetActuatorsFromCommands() macro + * Defines ACTUATORS_NB to 0 if no servo + * Include servos drivers + */ #include "generated/airframe.h" -/** Must be defined by specific hardware implementation */ +#if ACTUATORS_NB + extern void actuators_init( void ); /** Temporary storage (for debugging purpose, downlinked via telemetry) */ -extern uint16_t actuators[SERVOS_NB]; +extern uint16_t actuators[ACTUATORS_NB]; -#include ACTUATORS +#define SetServo(x, v) { actuators[x##_IDX] = v; } -#define SetServo(x, v) { \ - Actuator(x) = SERVOS_TICS_OF_USEC(ChopServo(v,700,2400)); \ - actuators[x] = v; \ - } +#else /* ACTUATORS_NB */ -#else /* ACTUATORS */ - -// define empty SetServo makro for sim +// define empty SetServo makro for sim (really needed ?) #define SetServo(x, v) {} -#endif /* ACTUATORS */ +#endif /* ACTUATORS_NB */ #endif /* ACTUATORS_H */ diff --git a/sw/airborne/subsystems/actuators/actuators_4015.h b/sw/airborne/subsystems/actuators/actuators_4015.h new file mode 100644 index 0000000000..07cd56875d --- /dev/null +++ b/sw/airborne/subsystems/actuators/actuators_4015.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 Gautier Hattenberger + * + * 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. + */ + +#ifndef ACTUATORS_4015_H +#define ACTUATORS_4015_H + +#include "subsystems/actuators/servos_4015_MAT_hw.h" + +#endif /* ACTUATORS_4015_H */ diff --git a/sw/airborne/subsystems/actuators/actuators_4017.h b/sw/airborne/subsystems/actuators/actuators_4017.h new file mode 100644 index 0000000000..315382d628 --- /dev/null +++ b/sw/airborne/subsystems/actuators/actuators_4017.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 Gautier Hattenberger + * + * 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. + */ + +#ifndef ACTUATORS_4017_H +#define ACTUATORS_4017_H + +#include "subsystems/actuators/servos_4017_hw.h" + +#endif /* ACTUATORS_4017_H */ diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_asctec.c b/sw/airborne/subsystems/actuators/actuators_asctec.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_asctec.c rename to sw/airborne/subsystems/actuators/actuators_asctec.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_asctec.h b/sw/airborne/subsystems/actuators/actuators_asctec.h similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_asctec.h rename to sw/airborne/subsystems/actuators/actuators_asctec.h diff --git a/sw/airborne/firmwares/rotorcraft/actuators.h b/sw/airborne/subsystems/actuators/actuators_default.h similarity index 51% rename from sw/airborne/firmwares/rotorcraft/actuators.h rename to sw/airborne/subsystems/actuators/actuators_default.h index e8d0c056d1..f3a0e750f0 100644 --- a/sw/airborne/firmwares/rotorcraft/actuators.h +++ b/sw/airborne/subsystems/actuators/actuators_default.h @@ -1,36 +1,30 @@ /* - * Copyright (C) 2010-2012 The Paparazzi Team + * Copyright (C) 2012 Gautier Hattenberger * - * This file is part of paparazzi. + * This file is part of Paparazzi. * - * paparazzi is free software; you can redistribute it and/or modify + * 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, + * 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 + * 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. */ -/** @file actuators.h - * Generic Actuators API. +#ifndef ACTUATORS_DEFAULT_H +#define ACTUATORS_DEFAULT_H + +/** Dummy include of default actuators header */ +#include BOARD_CONFIG +#include DEFAULT_ACTUATORS -#ifndef ACTUATORS_H -#define ACTUATORS_H - -//#include ACTUATORS - -#include "std.h" - -extern void actuators_init(void); -extern void actuators_set(bool_t motors_on); - -#endif /* ACTUATORS_H */ +#endif /* ACTUATORS_DEFAULT_H */ diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_dummy.c b/sw/airborne/subsystems/actuators/actuators_dummy.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_dummy.c rename to sw/airborne/subsystems/actuators/actuators_dummy.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_heli.c b/sw/airborne/subsystems/actuators/actuators_heli.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_heli.c rename to sw/airborne/subsystems/actuators/actuators_heli.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_mkk.c b/sw/airborne/subsystems/actuators/actuators_mkk.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_mkk.c rename to sw/airborne/subsystems/actuators/actuators_mkk.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_mkk.h b/sw/airborne/subsystems/actuators/actuators_mkk.h similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_mkk.h rename to sw/airborne/subsystems/actuators/actuators_mkk.h diff --git a/sw/airborne/subsystems/actuators/actuators_ppm.h b/sw/airborne/subsystems/actuators/actuators_ppm.h new file mode 100644 index 0000000000..eba3f6915e --- /dev/null +++ b/sw/airborne/subsystems/actuators/actuators_ppm.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 Gautier Hattenberger + * + * 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. + */ + +#ifndef ACTUATORS_PPM_H +#define ACTUATORS_PPM_H + +#include "subsystems/actuators/servos_ppm_hw.h" + +#endif /* ACTUATORS_PPM_H */ diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_pwm_supervision.c b/sw/airborne/subsystems/actuators/actuators_pwm_supervision.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_pwm_supervision.c rename to sw/airborne/subsystems/actuators/actuators_pwm_supervision.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_skiron.c b/sw/airborne/subsystems/actuators/actuators_skiron.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_skiron.c rename to sw/airborne/subsystems/actuators/actuators_skiron.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/actuators_skiron.h b/sw/airborne/subsystems/actuators/actuators_skiron.h similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/actuators_skiron.h rename to sw/airborne/subsystems/actuators/actuators_skiron.h diff --git a/sw/airborne/firmwares/rotorcraft/actuators/supervision.c b/sw/airborne/subsystems/actuators/supervision.c similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/supervision.c rename to sw/airborne/subsystems/actuators/supervision.c diff --git a/sw/airborne/firmwares/rotorcraft/actuators/supervision.h b/sw/airborne/subsystems/actuators/supervision.h similarity index 100% rename from sw/airborne/firmwares/rotorcraft/actuators/supervision.h rename to sw/airborne/subsystems/actuators/supervision.h diff --git a/sw/tools/gen_airframe.ml b/sw/tools/gen_airframe.ml index 3ce7e5ad18..677ffbd8a2 100644 --- a/sw/tools/gen_airframe.ml +++ b/sw/tools/gen_airframe.ml @@ -150,7 +150,10 @@ let preprocess_value = fun s v prefix -> let s = Str.global_replace pprz_value (sprintf "%s[%s_\\1]" v prefix) s in Str.global_replace var_value "_var_\\1" s - +let print_actuators_idx = fun () -> + let nb = Hashtbl.fold (fun s _d i -> printf "#define SERVO_%s_IDX %d\n" s i; i+1) servos_drivers 0 in + define "ACTUATORS_NB" (string_of_int nb); + nl () let parse_command_laws = fun command -> let a = fun s -> ExtXml.attrib command s in @@ -162,15 +165,18 @@ let parse_command_laws = fun command -> printf " command_value = %s;\\\n" v; printf " command_value *= command_value>0 ? SERVO_%s_TRAVEL_UP : SERVO_%s_TRAVEL_DOWN;\\\n" servo servo; printf " servo_value = SERVO_%s_NEUTRAL + (int32_t)(command_value);\\\n" servo; - printf " actuators[SERVO_%s] = ChopServo(servo_value, SERVO_%s_MIN, SERVO_%s_MAX);\\\n\\\n" servo servo servo; + printf " actuators[SERVO_%s_IDX] = ChopServo(servo_value, SERVO_%s_MIN, SERVO_%s_MAX);\\\n\\\n" servo servo servo; let driver = get_servo_driver servo in - printf " Actuator%s(SERVO_%s) = SERVOS_TICS_OF_USEC(actuators[SERVO_%s]);\\\n\\\n" driver servo servo + printf " Actuator%s(SERVO_%s) = SERVOS_TICS_OF_USEC(actuators[SERVO_%s_IDX]);\\\n\\\n" driver servo servo | "let" -> let var = a "var" and value = a "value" in let v = preprocess_value value "values" "COMMAND" in printf " int16_t _var_%s = %s;\\\n" var v + | "call" -> + let f = a "fun" in + printf " %s;\\\n" f | "ratelimit" -> let var = a "var" and value = a "value" @@ -182,40 +188,6 @@ let parse_command_laws = fun command -> parse_element "" command | _ -> xml_error "set|let" -let parse_csc_fields = fun csc_fields -> - let a = fun s -> ExtXml.attrib csc_fields s in - match Xml.tag csc_fields with - "field_map" -> - let servo_id = a "servo_id" - and field = a "field" in - printf " temp.%s = actuators[%s]; \\\n" field servo_id; - | _ -> xml_error "field_map" - -let parse_csc_messages = (let msg_index_ref = ref 0 in fun csc_id csc_messages -> - let a = fun s -> ExtXml.attrib csc_messages s in - match Xml.tag csc_messages with - "msg" -> - let msg_id = a "id" - and msg_type = a "type" - and msg_index = msg_index_ref.contents in - msg_index_ref.contents <- msg_index + 1; - printf "{\\\n struct Csc%s temp; \\\n" msg_type; - List.iter parse_csc_fields (Xml.children csc_messages); - printf " can_write_csc(%s, CSC_%s, (uint8_t *)&temp, sizeof(struct Csc%s)); \\\n" csc_id msg_id msg_type; - printf "} \\\n" - | _ -> xml_error "msg" - ) - -let parse_csc_boards = fun csc_board -> - let a = fun s -> ExtXml.attrib csc_board s in - match Xml.tag csc_board with - "board" -> - let csc_id = a "id" in - List.iter (parse_csc_messages csc_id) (Xml.children csc_board); - | "define" -> - parse_element "" csc_board - | _ -> xml_error "board" - let parse_rc_commands = fun rc -> let a = fun s -> ExtXml.attrib rc s in match Xml.tag rc with @@ -255,11 +227,12 @@ let rec parse_section = fun s -> List.iter (parse_element prefix) (Xml.children s); nl () | "servos" -> - let driver = ExtXml.attrib_or_default s "driver" "" in + let driver = ExtXml.attrib_or_default s "driver" "Default" in let servos = Xml.children s in let nb_servos = List.fold_right (fun s m -> Pervasives.max (int_of_string (ExtXml.attrib s "no")) m) servos min_int + 1 in - define "SERVOS_NB" (string_of_int nb_servos); + define (sprintf "SERVOS_%s_NB" (String.uppercase driver)) (string_of_int nb_servos); + printf "#include \"subsystems/actuators/actuators_%s.h\"\n" (String.lowercase driver); nl (); List.iter (parse_servo driver) servos; nl () @@ -282,6 +255,8 @@ let rec parse_section = fun s -> List.iter parse_ap_only_commands (Xml.children s); printf "}\n\n" | "command_laws" -> + print_actuators_idx (); + printf "#define SetActuatorsFromCommands(values) { \\\n"; printf " uint32_t servo_value;\\\n"; printf " float command_value;\\\n"; @@ -295,12 +270,6 @@ let rec parse_section = fun s -> printf "#define AllActuatorsInit() { \\\n"; List.iter (fun d -> printf " Actuators%sInit();\\\n" d) drivers; printf "}\n\n"; - | "csc_boards" -> - let boards = Array.of_list (Xml.children s) in - define "CSC_BOARD_NB" (string_of_int (Array.length boards)); - printf "#define SendCscFromActuators() { \\\n"; - List.iter parse_csc_boards (Xml.children s); - printf "}\n" | "include" -> let filename = ExtXml.attrib s "href" in let subxml = Xml.parse_file filename in