diff --git a/conf/airframes/ENAC/fixed-wing/twinjet2.xml b/conf/airframes/ENAC/fixed-wing/twinjet2.xml index 959a400c62..a2c9fe7535 100644 --- a/conf/airframes/ENAC/fixed-wing/twinjet2.xml +++ b/conf/airframes/ENAC/fixed-wing/twinjet2.xml @@ -14,10 +14,10 @@ - + @@ -33,7 +33,7 @@ - + @@ -217,103 +217,4 @@ - - diff --git a/conf/airframes/ENAC/quadrotor/blender.xml b/conf/airframes/ENAC/quadrotor/blender.xml index c1682f0477..7be545c03f 100644 --- a/conf/airframes/ENAC/quadrotor/blender.xml +++ b/conf/airframes/ENAC/quadrotor/blender.xml @@ -1,11 +1,11 @@ - + @@ -22,13 +22,13 @@ - - - + + + @@ -48,17 +48,11 @@ - - - - - - + @@ -67,20 +61,15 @@ - + +
- - - -
- - +
diff --git a/conf/airframes/ENAC/quadrotor/navgo.xml b/conf/airframes/ENAC/quadrotor/navgo.xml index a42bd6d411..cbd3ae1fc3 100644 --- a/conf/airframes/ENAC/quadrotor/navgo.xml +++ b/conf/airframes/ENAC/quadrotor/navgo.xml @@ -21,7 +21,6 @@ - @@ -30,11 +29,11 @@ - - - - + + + + @@ -73,31 +72,39 @@
- - - + + + - - - + + + - - - + + + - - - + + + + + + + + + @@ -125,6 +132,8 @@ + + @@ -149,7 +158,8 @@
- + +
diff --git a/conf/autopilot/rotorcraft.makefile b/conf/autopilot/rotorcraft.makefile index c8e4b37502..a4d248a8be 100644 --- a/conf/autopilot/rotorcraft.makefile +++ b/conf/autopilot/rotorcraft.makefile @@ -145,9 +145,11 @@ else ifeq ($(BOARD), lisa_l) ap.CFLAGS += -DUSE_I2C2 else ifeq ($(BOARD), navgo) ap.CFLAGS += -DROTORCRAFT_BARO_LED=$(BARO_LED) -ap.CFLAGS += -DUSE_I2C1 -ap.CFLAGS += -DADS1114_I2C_DEVICE=i2c1 -ap.srcs += peripherals/ads1114.c +include $(CFG_ROTORCRAFT)/spi.makefile +ap.CFLAGS += -DUSE_SPI_SLAVE0 +ap.CFLAGS += -DSPI_NO_UNSELECT_SLAVE +ap.CFLAGS += -DSPI_MASTER +ap.srcs += peripherals/mcp355x.c endif # diff --git a/conf/autopilot/subsystems/shared/imu_navgo.makefile b/conf/autopilot/subsystems/shared/imu_navgo.makefile index e10385bbc3..2a24fbf0d0 100644 --- a/conf/autopilot/subsystems/shared/imu_navgo.makefile +++ b/conf/autopilot/subsystems/shared/imu_navgo.makefile @@ -12,10 +12,12 @@ IMU_NAVGO_CFLAGS += -DUSE_I2C1 -DI2C1_SCLL=25 -DI2C1_SCLH=25 IMU_NAVGO_CFLAGS += -DITG3200_I2C_DEVICE=$(IMU_NAVGO_I2C_DEVICE) IMU_NAVGO_CFLAGS += -DITG3200_I2C_ADDR=ITG3200_ADDR_ALT IMU_NAVGO_CFLAGS += -DITG3200_SMPLRT_DIV=1 +IMU_NAVGO_CFLAGS += -DITG3200_DLFP_CFG=5 IMU_NAVGO_SRCS += peripherals/itg3200.c IMU_NAVGO_CFLAGS += -DADXL345_I2C_DEVICE=$(IMU_NAVGO_I2C_DEVICE) IMU_NAVGO_CFLAGS += -DADXL345_I2C_ADDR=ADXL345_ADDR_ALT +IMU_NAVGO_CFLAGS += -DADXL345_BW_RATE=0x8 IMU_NAVGO_SRCS += peripherals/adxl345.i2c.c IMU_NAVGO_CFLAGS += -DHMC58XX_I2C_DEVICE=$(IMU_NAVGO_I2C_DEVICE) diff --git a/sw/airborne/arch/lpc21/mcu_periph/spi_arch.c b/sw/airborne/arch/lpc21/mcu_periph/spi_arch.c index 5ec122bcb8..d7286e6dcd 100644 --- a/sw/airborne/arch/lpc21/mcu_periph/spi_arch.c +++ b/sw/airborne/arch/lpc21/mcu_periph/spi_arch.c @@ -193,7 +193,9 @@ void SPI1_ISR(void) { } if (bit_is_set(SSPMIS, RTMIS)) { /* Rx fifo is not empty and no receive took place in the last 32 bits period */ +#if !SPI_NO_UNSELECT_SLAVE SpiUnselectCurrentSlave(); +#endif SpiReceive(); SpiDisableRti(); SpiClearRti(); /* clear interrupt */ diff --git a/sw/airborne/boards/navgo/baro_board.c b/sw/airborne/boards/navgo/baro_board.c index 87ac9fdbe7..20048139ab 100644 --- a/sw/airborne/boards/navgo/baro_board.c +++ b/sw/airborne/boards/navgo/baro_board.c @@ -31,53 +31,51 @@ /* Common Baro struct */ struct Baro baro; -/* Number of values to compute an offset at startup */ -#define OFFSET_NBSAMPLES_AVRG 300 -uint16_t offset_cnt; - -#ifdef USE_BARO_AS_ALTIMETER -/* Weight for offset IIR filter */ -#define OFFSET_FILTER 7 - -float baro_alt; -float baro_alt_offset; -#endif +/* Counter to init mcp355x at startup */ +#define STARTUP_COUNTER 200 +uint16_t startup_cnt; void baro_init( void ) { - ads1114_init(); + mcp355x_init(); baro.status = BS_UNINITIALIZED; baro.absolute = 0; baro.differential = 0; /* not handled on this board */ #ifdef ROTORCRAFT_BARO_LED LED_OFF(ROTORCRAFT_BARO_LED); #endif - offset_cnt = OFFSET_NBSAMPLES_AVRG; -#ifdef USE_BARO_AS_ALTIMETER - baro_alt = 0.; - baro_alt_offset = 0.; -#endif + startup_cnt = STARTUP_COUNTER; } +// Need to play with slave select +#include "mcu_periph/spi.h" + void baro_periodic( void ) { if (baro.status == BS_UNINITIALIZED) { -#ifdef USE_BARO_AS_ALTIMETER - // IIR filter to compute an initial offset - baro_alt_offset = (OFFSET_FILTER * baro_alt_offset + (float)baro.absolute) / (OFFSET_FILTER + 1); -#endif + /** + * Crappy code to empty the buffer + * then unselect the device (goes to shutdown ?) + * reselect to go to continious conversion mode + * make some readings before setting BS_RUNNING + * don't unselect the slave ! + */ + if (startup_cnt == 150) { SpiSelectSlave0(); mcp355x_read(); } + else if (startup_cnt == 149) { SpiUnselectSlave0(); } + else if (startup_cnt == 100) { SpiSelectSlave0(); } + else if (startup_cnt < 90) { RunOnceEvery(4, mcp355x_read()); } // decrease init counter - --offset_cnt; + --startup_cnt; #ifdef ROTORCRAFT_BARO_LED LED_TOGGLE(ROTORCRAFT_BARO_LED); #endif - if (offset_cnt == 0) { + if (startup_cnt == 0) { baro.status = BS_RUNNING; #ifdef ROTORCRAFT_BARO_LED LED_ON(ROTORCRAFT_BARO_LED); #endif } } - // Read the ADC - ads1114_read(); + // Read the ADC (at 50/4 Hz, conversion time is 68 ms) + else { RunOnceEvery(4,mcp355x_read()); } } diff --git a/sw/airborne/boards/navgo/baro_board.h b/sw/airborne/boards/navgo/baro_board.h index de705d46d0..250476b148 100644 --- a/sw/airborne/boards/navgo/baro_board.h +++ b/sw/airborne/boards/navgo/baro_board.h @@ -31,22 +31,16 @@ #include "std.h" -#include "peripherals/ads1114.h" - -#ifdef USE_BARO_AS_ALTIMETER -extern float baro_alt; -extern float baro_alt_offset; -#define BaroAltHandler() { baro_alt = BARO_SENS*(baro_alt_offset - (float)baro.absolute); } -#endif +#include "peripherals/mcp355x.h" #define BARO_FILTER_GAIN 5 #define BaroEvent(_b_abs_handler, _b_diff_handler) { \ - Ads1114Event(); \ - if (ads1114_data_available) { \ - baro.absolute = (baro.absolute + BARO_FILTER_GAIN*Ads1114GetValue()) / (BARO_FILTER_GAIN+1); \ + mcp355x_event(); \ + if (mcp355x_data_available) { \ + baro.absolute = (baro.absolute + BARO_FILTER_GAIN*mcp355x_data) / (BARO_FILTER_GAIN+1); \ _b_abs_handler(); \ - ads1114_data_available = FALSE; \ + mcp355x_data_available = FALSE; \ } \ } diff --git a/sw/airborne/boards/navgo/imu_navgo.c b/sw/airborne/boards/navgo/imu_navgo.c index b872219e9e..cf19cfefd6 100644 --- a/sw/airborne/boards/navgo/imu_navgo.c +++ b/sw/airborne/boards/navgo/imu_navgo.c @@ -103,7 +103,7 @@ void imu_navgo_event( void ) // If the itg3200 I2C transaction has succeeded: convert the data itg3200_event(); if (itg3200_data_available) { - RATES_COPY(imu.gyro_unscaled, itg3200_data); + RATES_ASSIGN(imu.gyro_unscaled, -itg3200_data.q, itg3200_data.p, itg3200_data.r); itg3200_data_available = FALSE; gyr_valid = TRUE; } @@ -119,7 +119,7 @@ void imu_navgo_event( void ) // HMC58XX event task hmc58xx_event(); if (hmc58xx_data_available) { - VECT3_ASSIGN(imu.mag_unscaled, -hmc58xx_data.x, -hmc58xx_data.y, hmc58xx_data.z); + VECT3_ASSIGN(imu.mag_unscaled, hmc58xx_data.x, hmc58xx_data.y, hmc58xx_data.z); hmc58xx_data_available = FALSE; mag_valid = TRUE; } diff --git a/sw/airborne/boards/navgo_1.0.h b/sw/airborne/boards/navgo_1.0.h index 17a6fbf118..3f1121dbbe 100644 --- a/sw/airborne/boards/navgo_1.0.h +++ b/sw/airborne/boards/navgo_1.0.h @@ -18,17 +18,17 @@ #define PCLK (CCLK / PBSD_VAL) /* Onboard LEDs */ -#define LED_1_BANK 1 -#define LED_1_PIN 25 +#define LED_1_BANK 0 +#define LED_1_PIN 22 #define LED_2_BANK 1 -#define LED_2_PIN 24 +#define LED_2_PIN 28 #define LED_3_BANK 1 -#define LED_3_PIN 23 +#define LED_3_PIN 29 #define LED_4_BANK 1 -#define LED_4_PIN 31 +#define LED_4_PIN 30 /* PPM : rc rx on P0.28 ( CAP0.2 ) */ #define PPM_PINSEL PINSEL1 @@ -45,19 +45,22 @@ /* battery */ /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/ #ifndef ADC_CHANNEL_VSUPPLY -#define ADC_CHANNEL_VSUPPLY AdcBank1(3) -#ifndef USE_AD1 -#define USE_AD1 +#define ADC_CHANNEL_VSUPPLY AdcBank0(2) +#ifndef USE_AD0 +#define USE_AD0 #endif -#define USE_AD1_3 +#define USE_AD0_2 #endif -#define DefaultVoltageOfAdc(adc) (0.01837*adc) +#define DefaultVoltageOfAdc(adc) (0.017889*adc) /* SPI (SSP) */ #define SPI_SELECT_SLAVE0_PORT 0 #define SPI_SELECT_SLAVE0_PIN 20 +//#define SPI_SELECT_SLAVE1_PORT 1 +//#define SPI_SELECT_SLAVE1_PIN 19 + #define SPI1_DRDY_PINSEL PINSEL1 #define SPI1_DRDY_PINSEL_BIT 0 #define SPI1_DRDY_PINSEL_VAL 1 diff --git a/sw/airborne/peripherals/mcp355x.c b/sw/airborne/peripherals/mcp355x.c index 386f1aae59..3eec8438ab 100644 --- a/sw/airborne/peripherals/mcp355x.c +++ b/sw/airborne/peripherals/mcp355x.c @@ -41,32 +41,20 @@ void mcp355x_init(void) { void mcp355x_read(void) { spi_buffer_length = 4; spi_buffer_input = mcp355x_spi_buf; - SpiSelectSlave0(); + //SpiSelectSlave0(); SpiStart(); } -#ifndef DOWNLINK_DEVICE -#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE -#endif - -#include "mcu_periph/uart.h" -#include "messages.h" -#include "downlink.h" - void mcp355x_event(void) { - static uint32_t filtered = 0; if (spi_message_received) { spi_message_received = FALSE; if ((mcp355x_spi_buf[0]>>4) == 0) { - //mcp355x_data = (int32_t)(((uint32_t)mcp355x_spi_buf[0]<<16) | ((uint32_t)mcp355x_spi_buf[1]<<8) | (mcp355x_spi_buf[2])); mcp355x_data = (int32_t)( ((uint32_t)mcp355x_spi_buf[0]<<17) | ((uint32_t)mcp355x_spi_buf[1]<<9) | ((uint32_t)mcp355x_spi_buf[2]<<1) | (mcp355x_spi_buf[3]>>7)); - filtered = (5*filtered + mcp355x_data) / (6); - DOWNLINK_SEND_DEBUG(DefaultChannel,4,mcp355x_spi_buf); - DOWNLINK_SEND_BARO_RAW(DefaultChannel,&mcp355x_data,&filtered); + mcp355x_data_available = TRUE; } } }