diff --git a/conf/airframes/mm/fixed-wing/funjetmm.xml b/conf/airframes/mm/fixed-wing/funjetmm.xml index 71a79df3ab..3ce0e0cbe9 100755 --- a/conf/airframes/mm/fixed-wing/funjetmm.xml +++ b/conf/airframes/mm/fixed-wing/funjetmm.xml @@ -61,6 +61,8 @@ + + diff --git a/conf/messages.xml b/conf/messages.xml index b28435b31b..7068a6c23e 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -634,7 +634,11 @@ - + + + + + diff --git a/conf/modules/dust_gp2y.xml b/conf/modules/dust_gp2y.xml new file mode 100644 index 0000000000..1d443d4ea2 --- /dev/null +++ b/conf/modules/dust_gp2y.xml @@ -0,0 +1,14 @@ + + + +
+ +
+ + + + + + +
+ diff --git a/sw/airborne/firmwares/helper/README b/sw/airborne/firmwares/helper/README new file mode 100644 index 0000000000..7dee026b3f --- /dev/null +++ b/sw/airborne/firmwares/helper/README @@ -0,0 +1,2 @@ +This folder contains software that runs in separate on-board processors that are not +part of the main autopilot. \ No newline at end of file diff --git a/sw/airborne/firmwares/helper/dustsens/dustsens.pde b/sw/airborne/firmwares/helper/dustsens/dustsens.pde new file mode 100644 index 0000000000..c3a1bc266f --- /dev/null +++ b/sw/airborne/firmwares/helper/dustsens/dustsens.pde @@ -0,0 +1,136 @@ +/* + * $Id$ + * + * Copyright (C) 2010 Martin Mueller, + * + * 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. + * + */ + +/* I2C interface for Sharp GP2Y1010AU optical dust sensor */ + +#include + + +/* infrared LED pin PB1, high active */ +#define IR_FLASH_PIN 9 +/* adc_in pin ADC0 */ +#define ADC_PIN 0 +/* green LED pin PB5 (on arduino pro mini) */ +#define LED_GR_PIN 13 + +#define GP2Y_I2C_ADDR 0x76 +#define AVG_NB_SAMPLE 25 + + +struct adc_buf { + unsigned long sum; + unsigned short values[AVG_NB_SAMPLE]; + unsigned char head; +}; + +struct adc_buf buf; + +unsigned char i2c_out[2]; +unsigned long time_us; +unsigned long time_ms; +unsigned long trig_next; +unsigned long cnt; +unsigned short adc_val; +unsigned char new_head; + + +ISR(ADC_vect) { + adc_val = ADCL; + adc_val |= ADCH << 8; + new_head = buf.head + 1; + if (new_head >= AVG_NB_SAMPLE) + new_head=0; + buf.sum -= buf.values[new_head]; + buf.values[new_head] = adc_val; + buf.sum += adc_val; + buf.head = new_head; +} + +void read_i2c() { + i2c_out[0] = ((unsigned int)(buf.sum / AVG_NB_SAMPLE) >> 8) & 0xFF; + i2c_out[1] = (unsigned int)(buf.sum / AVG_NB_SAMPLE) & 0xFF; + + Wire.send(i2c_out, 2); +} + +void setup() { + /* I2C init */ + Wire.begin(GP2Y_I2C_ADDR); + Wire.onRequest(read_i2c); + + /* green LED init */ + digitalWrite(LED_GR_PIN, LOW); + pinMode(LED_GR_PIN, OUTPUT); + + /* infrared LED switch init */ + digitalWrite(IR_FLASH_PIN, HIGH); + pinMode(IR_FLASH_PIN, OUTPUT); + + /* init adc, default reference */ + ADCSRA |= (1<= trig_next) { + trig_next += 10; + + noInterrupts(); + + time_us = micros(); + + /* flash the infrared, LED on */ + digitalWrite(IR_FLASH_PIN, HIGH); + + /* delay 0.28ms for reflection */ + while((micros() - time_us) < 280); + + /* start conversion */ + ADCSRA |= 1 << ADSC; + + /* fill delay to 0.32ms for end of reflection */ + while((micros() - time_us) < 320); + + /* infrared LED off */ + digitalWrite(IR_FLASH_PIN, LOW); + + interrupts(); + +#if 0 + /* blink green LED */ + if (cnt++ > 90) { + digitalWrite(LED_GR_PIN, HIGH); + if (cnt > 100) { + digitalWrite(LED_GR_PIN, LOW); + cnt = 0; + } + } +#endif + } +} + diff --git a/sw/airborne/modules/meteo/dust_gp2y.c b/sw/airborne/modules/meteo/dust_gp2y.c new file mode 100644 index 0000000000..283ac80865 --- /dev/null +++ b/sw/airborne/modules/meteo/dust_gp2y.c @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (C) 2010 Martin Mueller + * + * 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. + * + */ + +/** \file dust_gp2y.c + * \brief Sharp GP2Y1010AU dust sensor interface + * + * This reads the values for dust density from the Sharp GP2Y1010AU0F sensor + * through I2C (needs I2C ADC at the sensor). + */ + + +#include "dust_gp2y.h" +#include "i2c.h" +#include "sys_time.h" +#include "uart.h" +#include "messages.h" +#include "downlink.h" + +uint8_t dust_gp2y_status; +uint16_t dust_gp2y_density; +float dust_gp2y_density_f; + +struct i2c_transaction gp2y_trans; + +#ifndef GP2Y_I2C_DEV +#define GP2Y_I2C_DEV i2c0 +#endif + +#define GP2Y_SLAVE_ADDR 0xED + +void dust_gp2y_init( void ) { + dust_gp2y_status = DUST_GP2Y_UNINIT; +} + +void dust_gp2y_periodic( void ) { + if (dust_gp2y_status == DUST_GP2Y_IDLE) { + I2CReceive(GP2Y_I2C_DEV, gp2y_trans, GP2Y_SLAVE_ADDR, 2); + } + else if (dust_gp2y_status == DUST_GP2Y_UNINIT && cpu_time_sec > 1) { + dust_gp2y_status = DUST_GP2Y_IDLE; + } +} + +void dust_gp2y_event( void ) { + if (gp2y_trans.status == I2CTransSuccess) { + /* read two byte particle density */ + dust_gp2y_density = gp2y_trans.buf[0] << 8; + dust_gp2y_density |= gp2y_trans.buf[1]; + + /* "just for reference and not for guarantee" */ + dust_gp2y_density_f = ((dust_gp2y_density / 1024.) * 3.3 * (51. / 33.) - 0.6) * (0.5 / 3.); + if (dust_gp2y_density_f < 0) + dust_gp2y_density_f = 0; + + DOWNLINK_SEND_GP2Y_STATUS(DefaultChannel, &dust_gp2y_density, &dust_gp2y_density_f); + + gp2y_trans.status = I2CTransDone; + } +} + + diff --git a/sw/airborne/modules/meteo/dust_gp2y.h b/sw/airborne/modules/meteo/dust_gp2y.h new file mode 100644 index 0000000000..3150088bf0 --- /dev/null +++ b/sw/airborne/modules/meteo/dust_gp2y.h @@ -0,0 +1,18 @@ +#ifndef DUST_GP2Y_H +#define DUST_GP2Y_H + +#include "std.h" + +#define DUST_GP2Y_UNINIT 0 +#define DUST_GP2Y_IDLE 1 + +extern uint8_t dust_gp2y_status; +extern uint16_t dust_gp2y_density; +extern float dust_gp2y_density_f; + +void dust_gp2y_init(void); +void dust_gp2y_periodic(void); +void dust_gp2y_event(void); + +#endif +