From 28e26cb7c596b970d72fc960a53cb1f79a11742a Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Wed, 29 Dec 2010 12:23:09 +0100 Subject: [PATCH] ir adc and i2c are available as modules and subsystems --- .../fixedwing/attitude_infrared.makefile | 1 + .../fixedwing/attitude_infrared_i2c.makefile | 8 ++++ conf/modules/infrared_adc.xml | 20 ++++++++++ conf/modules/infrared_i2c.xml | 11 +++--- conf/modules/module.dtd | 6 ++- sw/airborne/ap_downlink.h | 2 +- sw/airborne/arch/sim/sim_ir.c | 3 +- sw/airborne/modules/sensors/infrared_adc.h | 33 +++++++++++++++++ sw/airborne/subsystems/sensors/infrared_adc.c | 23 +++++++++--- sw/airborne/subsystems/sensors/infrared_adc.h | 37 +++++++++++++++++++ sw/airborne/subsystems/sensors/infrared_i2c.c | 3 +- sw/tools/gen_aircraft.ml | 6 ++- 12 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 conf/autopilot/subsystems/fixedwing/attitude_infrared_i2c.makefile create mode 100644 conf/modules/infrared_adc.xml create mode 100644 sw/airborne/modules/sensors/infrared_adc.h create mode 100644 sw/airborne/subsystems/sensors/infrared_adc.h diff --git a/conf/autopilot/subsystems/fixedwing/attitude_infrared.makefile b/conf/autopilot/subsystems/fixedwing/attitude_infrared.makefile index aa4509a479..7395522edb 100644 --- a/conf/autopilot/subsystems/fixedwing/attitude_infrared.makefile +++ b/conf/autopilot/subsystems/fixedwing/attitude_infrared.makefile @@ -33,6 +33,7 @@ ap.CFLAGS += -DADC_CHANNEL_IR_NB_SAMPLES=$(ADC_IR_NB_SAMPLES) $(TARGET).CFLAGS += -DUSE_INFRARED $(TARGET).srcs += subsystems/sensors/infrared.c +$(TARGET).srcs += subsystems/sensors/infrared_adc.c sim.srcs += $(SRC_ARCH)/sim_ir.c jsbsim.srcs += $(SRC_ARCH)/jsbsim_ir.c diff --git a/conf/autopilot/subsystems/fixedwing/attitude_infrared_i2c.makefile b/conf/autopilot/subsystems/fixedwing/attitude_infrared_i2c.makefile new file mode 100644 index 0000000000..b3f9355b11 --- /dev/null +++ b/conf/autopilot/subsystems/fixedwing/attitude_infrared_i2c.makefile @@ -0,0 +1,8 @@ +# attitude via IR I2C sensors + +$(TARGET).CFLAGS += -DUSE_INFRARED_I2C +$(TARGET).srcs += subsystems/sensors/infrared.c +$(TARGET).srcs += subsystems/sensors/infrared_i2c.c + +sim.srcs += $(SRC_ARCH)/sim_ir.c +jsbsim.srcs += $(SRC_ARCH)/jsbsim_ir.c diff --git a/conf/modules/infrared_adc.xml b/conf/modules/infrared_adc.xml new file mode 100644 index 0000000000..30f484e574 --- /dev/null +++ b/conf/modules/infrared_adc.xml @@ -0,0 +1,20 @@ + + + + +
+ +
+ + + + + + + + + + +
+ + diff --git a/conf/modules/infrared_i2c.xml b/conf/modules/infrared_i2c.xml index a8e3cac8ea..b73dd757d6 100644 --- a/conf/modules/infrared_i2c.xml +++ b/conf/modules/infrared_i2c.xml @@ -1,4 +1,5 @@ +
@@ -9,14 +10,12 @@ - - ap.srcs += subsystems/sensors/infrared.c - ap.srcs += subsystems/sensors/infrared_i2c.c - sim.srcs += subsystems/sensors/infrared.c - sim.srcs += subsystems/sensors/infrared_i2c.c + + + - sim.srcs += $(SRC_ARCH)/sim_ir.c + diff --git a/conf/modules/module.dtd b/conf/modules/module.dtd index 84a4b8138f..33122841b8 100644 --- a/conf/modules/module.dtd +++ b/conf/modules/module.dtd @@ -60,8 +60,10 @@ value CDATA #IMPLIED type CDATA #IMPLIED> +name CDATA #REQUIRED +dir CDATA #IMPLIED> +name CDATA #REQUIRED +dir CDATA #IMPLIED> diff --git a/sw/airborne/ap_downlink.h b/sw/airborne/ap_downlink.h index 1bec3e1081..c8aa3e389e 100644 --- a/sw/airborne/ap_downlink.h +++ b/sw/airborne/ap_downlink.h @@ -115,7 +115,7 @@ #define PERIODIC_SEND_SETTINGS(_chan) {} #endif -#if defined USE_INFRARED || USE_INFRARED_I2C +#if defined USE_INFRARED || USE_INFRARED_TELEMETRY #define PERIODIC_SEND_IR_SENSORS(_chan) DOWNLINK_SEND_IR_SENSORS(_chan, &infrared.value.ir1, &infrared.value.ir2, &infrared.pitch, &infrared.roll, &infrared.top); #else #define PERIODIC_SEND_IR_SENSORS(_chan) ; diff --git a/sw/airborne/arch/sim/sim_ir.c b/sw/airborne/arch/sim/sim_ir.c index 88441205f8..1ec7884faf 100644 --- a/sw/airborne/arch/sim/sim_ir.c +++ b/sw/airborne/arch/sim/sim_ir.c @@ -21,7 +21,8 @@ value set_ir(value roll __attribute__ ((unused)), value top __attribute__ ((unused)), value air_speed ) { -#if defined USE_INFRARED || USE_INFRARED_I2C + // INFRARED_TELEMETRY : Stupid hack to use with modules +#if defined USE_INFRARED || USE_INFRARED_TELEMETRY infrared.roll = Int_val(roll); infrared.pitch = Int_val(front); infrared.top = Int_val(top); diff --git a/sw/airborne/modules/sensors/infrared_adc.h b/sw/airborne/modules/sensors/infrared_adc.h new file mode 100644 index 0000000000..9a0efb291a --- /dev/null +++ b/sw/airborne/modules/sensors/infrared_adc.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010 ENAC + * + * 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. + * + */ + +/* + * Wrapper for adc infrared sensor module + */ + +#ifndef INFRARED_ADC_H +#define INFRARED_ADC_H + +#include "subsystems/sensors/infrared_adc.h" + +#endif // INFRARED_ADC_H + diff --git a/sw/airborne/subsystems/sensors/infrared_adc.c b/sw/airborne/subsystems/sensors/infrared_adc.c index 715871d5de..86533aeb67 100644 --- a/sw/airborne/subsystems/sensors/infrared_adc.c +++ b/sw/airborne/subsystems/sensors/infrared_adc.c @@ -31,7 +31,7 @@ #include -#include "subsystems/sensors/infrared.h" +#include "subsystems/sensors/infrared_adc.h" #include "mcu_periph/adc.h" #include BOARD_CONFIG @@ -53,10 +53,22 @@ static struct adc_buf buf_ir3; struct Infrared_raw ir_adc; +// Standard infrared implementation +void infrared_init(void) { + infrared_adc_init(); +} + +void infrared_update(void) { + infrared_adc_update(); +} + +/* No event with adc ir */ +void infrared_event(void) {} + /** \brief Initialisation of \a ir */ /** Initialize \a adc_buf_channel */ -void infrared_init(void) { +void infrared_adc_init(void) { #if ! (defined SITL || defined HITL) adc_buf_channel(ADC_CHANNEL_IR1, &buf_ir1, ADC_CHANNEL_IR_NB_SAMPLES); adc_buf_channel(ADC_CHANNEL_IR2, &buf_ir2, ADC_CHANNEL_IR_NB_SAMPLES); @@ -76,18 +88,17 @@ void infrared_init(void) { /** \brief Update \a ir_roll and ir_pitch from ADCs or from simulator * message in HITL and SITL modes */ -void infrared_update(void) { +void infrared_adc_update(void) { #if ! (defined SITL || defined HITL) ir_adc.ir1 = (int32_t)(buf_ir1.sum/buf_ir1.av_nb_sample) - IR_ADC_IR1_NEUTRAL; ir_adc.ir2 = (int32_t)(buf_ir2.sum/buf_ir2.av_nb_sample) - IR_ADC_IR2_NEUTRAL; #ifdef ADC_CHANNEL_IR_TOP ir_adc.ir3 = (int32_t)(buf_ir3.sum/buf_ir3.av_nb_sample) - IR_ADC_TOP_NEUTRAL; #endif // IR_TOP +#ifndef IR_ADC_READ_ONLY UpdateIRValue(ir_adc); +#endif #endif /* !SITL && !HITL */ /** #else ir_roll set by simulator in sim_ir.c */ } -/* No event with adc ir */ -void infrared_event(void) {} - diff --git a/sw/airborne/subsystems/sensors/infrared_adc.h b/sw/airborne/subsystems/sensors/infrared_adc.h new file mode 100644 index 0000000000..d3ab245a54 --- /dev/null +++ b/sw/airborne/subsystems/sensors/infrared_adc.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 ENAC + * + * 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. + * + */ + +/* + * Driver for adc infrared sensor + */ + +#ifndef SUBSYSTEMS_SENSORS_INFRARED_ADC_H +#define SUBSYSTEMS_SENSORS_INFRARED_ADC_H + +#include "std.h" +#include "subsystems/sensors/infrared.h" + +void infrared_adc_init(); +void infrared_adc_update(); + +#endif // SUBSYSTEMS_SENSORS_INFRARED_ADC_H + diff --git a/sw/airborne/subsystems/sensors/infrared_i2c.c b/sw/airborne/subsystems/sensors/infrared_i2c.c index 3ddc91ad9c..893a5e1bd6 100644 --- a/sw/airborne/subsystems/sensors/infrared_i2c.c +++ b/sw/airborne/subsystems/sensors/infrared_i2c.c @@ -70,7 +70,6 @@ struct i2c_transaction irh_trans, irv_trans; // Standard infrared implementation void infrared_init(void) { infrared_i2c_init(); - infrared_struct_init(); } void infrared_update(void) { @@ -92,6 +91,8 @@ void infrared_i2c_init( void ) { ir_i2c_conf_ver_done = FALSE; irh_trans.status = I2CTransDone; irv_trans.status = I2CTransDone; + + infrared_struct_init(); } void infrared_i2c_update( void ) { diff --git a/sw/tools/gen_aircraft.ml b/sw/tools/gen_aircraft.ml index cc5130f8e5..6d290cf5fc 100644 --- a/sw/tools/gen_aircraft.ml +++ b/sw/tools/gen_aircraft.ml @@ -137,10 +137,12 @@ let dump_module_section = fun xml f -> ) targets | "file" -> let name = Xml.attrib field "name" in - List.iter (fun target -> fprintf f "%s.srcs += $(%s)/%s\n" target dir_name name) targets + let dir_name = ExtXml.attrib_or_default field "dir" ("$("^dir_name^")") in + List.iter (fun target -> fprintf f "%s.srcs += %s/%s\n" target dir_name name) targets | "file_arch" -> let name = Xml.attrib field "name" in - List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/$(%s)/%s\n" target dir_name name) targets + let dir_name = ExtXml.attrib_or_default field "dir" ("$("^dir_name^")") in + List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/%s/%s\n" target dir_name name) targets | "raw" -> begin match Xml.children field with [Xml.PCData s] -> fprintf f "%s\n" s