diff --git a/conf/airframes/CDW/TwoSeas.xml b/conf/airframes/CDW/TwoSeas.xml index 71bcd57613..39a2c8d6bb 100644 --- a/conf/airframes/CDW/TwoSeas.xml +++ b/conf/airframes/CDW/TwoSeas.xml @@ -13,6 +13,7 @@ + diff --git a/conf/conf_tests.xml b/conf/conf_tests.xml index 48b4cb6b1a..9808b0f09e 100644 --- a/conf/conf_tests.xml +++ b/conf/conf_tests.xml @@ -150,7 +150,7 @@ telemetry="telemetry/default_fixedwing_imu.xml" flight_plan="flight_plans/nav_modules.xml" settings="settings/fixedwing_basic.xml settings/control/ctl_basic.xml settings/control/ctl_dash_loiter_trim.xml" - settings_modules="modules/nav_smooth.xml" + settings_modules="modules/air_data.xml modules/nav_smooth.xml" gui_color="blue" /> 12 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 12." +#endif + /* channel assignments */ #define RADIO_THROTTLE 0 #define RADIO_ROLL 1 diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h b/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h index cf5252860d..c355884fcc 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h +++ b/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h @@ -46,6 +46,4 @@ #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v)*RC_PPM_TICKS_PER_USEC) #define USEC_OF_RC_PPM_TICKS(_v) ((_v)/RC_PPM_TICKS_PER_USEC) -#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL - #endif /* PPM_ARCH_H */ diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c index d863789502..57ea6cfed6 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c +++ b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c @@ -35,6 +35,9 @@ // for timer_get_frequency #include "mcu_arch.h" +// for Min macro +#include "std.h" + #include BOARD_CONFIG #define SPEKTRUM_CHANNELS_PER_FRAME 7 @@ -443,7 +446,7 @@ void RadioControlEventImp(void (*frame_handler)(void)) { case(0) : /* 10 bit */ ChannelNum = (ChannelData >> 10) & 0x0f; /* don't bother decoding unused channels */ - if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) { + if (ChannelNum < SPEKTRUM_NB_CHANNEL) { SpektrumBuf[ChannelNum] = ChannelData & 0x3ff; SpektrumBuf[ChannelNum] -= 0x200; SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x156; @@ -454,7 +457,7 @@ void RadioControlEventImp(void (*frame_handler)(void)) { case(1) : /* 11 bit */ ChannelNum = (ChannelData >> 11) & 0x0f; /* don't bother decoding unused channels */ - if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) { + if (ChannelNum < SPEKTRUM_NB_CHANNEL) { SpektrumBuf[ChannelNum] = ChannelData & 0x7ff; SpektrumBuf[ChannelNum] -= 0x400; SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x2AC; @@ -475,7 +478,10 @@ void RadioControlEventImp(void (*frame_handler)(void)) { radio_control.frame_cpt++; radio_control.time_since_last_frame = 0; radio_control.status = RC_OK; - for (int i = 0; i < (MaxChannelNum + 1); i++) { + /* since it is possible for the user use less than the actually available channels, + * we only transfer only Min(RADIO_CONTROL_NB_CHANNEL, available_channels) + */ + for (int i = 0; i < Min(RADIO_CONTROL_NB_CHANNEL, (MaxChannelNum + 1)); i++) { radio_control.values[i] = SpektrumBuf[i]; if (i == RADIO_THROTTLE ) { radio_control.values[i] += MAX_PPRZ; diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h index bf6a370580..a8e72e5c69 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h +++ b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h @@ -29,11 +29,16 @@ * have the same channel assignments. */ +#define SPEKTRUM_NB_CHANNEL 12 #ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL 12 #endif +#if RADIO_CONTROL_NB_CHANNEL > 12 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 12." +#endif + /* default channel assignments */ #ifndef RADIO_THROTTLE #define RADIO_THROTTLE 0 diff --git a/sw/airborne/subsystems/radio_control.h b/sw/airborne/subsystems/radio_control.h index 6d0543d6e4..48ed0db5bd 100644 --- a/sw/airborne/subsystems/radio_control.h +++ b/sw/airborne/subsystems/radio_control.h @@ -30,10 +30,13 @@ /* underlying hardware, also include if RADIO_CONTROL is not defined for ap in dual mcu case */ #include RADIO_CONTROL_TYPE_H +/* RADIO_CONTROL_NB_CHANNEL needs to be defined to suitable default the implementation. + * If not all available channels are needed, can be overridden in airframe file. + */ + #if defined RADIO_CONTROL /* must be defined by underlying hardware */ extern void radio_control_impl_init(void); -/* RADIO_CONTROL_NB_CHANNEL has to be defined by the implementation */ /* timeouts - for now assumes 60Hz periodic */ #define RC_AVG_PERIOD 8 /* TODO remove if IIR filter is used */ diff --git a/sw/airborne/subsystems/radio_control/ppm.c b/sw/airborne/subsystems/radio_control/ppm.c index 5dc5effbba..b03cc0267c 100644 --- a/sw/airborne/subsystems/radio_control/ppm.c +++ b/sw/airborne/subsystems/radio_control/ppm.c @@ -28,7 +28,7 @@ #include "subsystems/radio_control.h" #include "subsystems/radio_control/ppm.h" -uint16_t ppm_pulses[ PPM_NB_CHANNEL ]; +uint16_t ppm_pulses[RADIO_CTL_NB]; volatile bool_t ppm_frame_available; /* @@ -60,12 +60,12 @@ static bool_t ppm_data_valid; static void send_ppm(struct transport_tx *trans, struct link_device *dev) { - uint16_t ppm_pulses_usec[RADIO_CONTROL_NB_CHANNEL]; - for (int i = 0; i < RADIO_CONTROL_NB_CHANNEL; i++) { + uint16_t ppm_pulses_usec[RADIO_CTL_NB]; + for (int i = 0; i < RADIO_CTL_NB; i++) { ppm_pulses_usec[i] = USEC_OF_RC_PPM_TICKS(ppm_pulses[i]); } pprz_msg_send_PPM(trans, dev, AC_ID, - &radio_control.frame_rate, PPM_NB_CHANNEL, ppm_pulses_usec); + &radio_control.frame_rate, RADIO_CTL_NB, ppm_pulses_usec); } #endif @@ -73,7 +73,7 @@ void radio_control_impl_init(void) { ppm_frame_available = FALSE; ppm_last_pulse_time = 0; - ppm_cur_pulse = RADIO_CONTROL_NB_CHANNEL; + ppm_cur_pulse = RADIO_CTL_NB; ppm_data_valid = FALSE; ppm_arch_init(); @@ -111,7 +111,7 @@ void ppm_decode_frame(uint32_t ppm_time) uint32_t length = ppm_time - ppm_last_pulse_time; ppm_last_pulse_time = ppm_time; - if (ppm_cur_pulse == PPM_NB_CHANNEL) { + if (ppm_cur_pulse == RADIO_CTL_NB) { if (length > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) && length < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) { if (ppm_data_valid && RssiValid()) { @@ -127,11 +127,11 @@ void ppm_decode_frame(uint32_t ppm_time) length < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) { ppm_pulses[ppm_cur_pulse] = length; ppm_cur_pulse++; - if (ppm_cur_pulse == PPM_NB_CHANNEL) { + if (ppm_cur_pulse == RADIO_CTL_NB) { ppm_data_valid = TRUE; } } else { - ppm_cur_pulse = PPM_NB_CHANNEL; + ppm_cur_pulse = RADIO_CTL_NB; ppm_data_valid = FALSE; } } diff --git a/sw/airborne/subsystems/radio_control/ppm.h b/sw/airborne/subsystems/radio_control/ppm.h index e909400c2e..022abb9d7c 100644 --- a/sw/airborne/subsystems/radio_control/ppm.h +++ b/sw/airborne/subsystems/radio_control/ppm.h @@ -24,6 +24,9 @@ #include "std.h" +/* in case you want to override RADIO_CONTROL_NB_CHANNEL */ +#include "generated/airframe.h" + /** * Architecture dependant code */ @@ -38,10 +41,15 @@ extern void ppm_arch_init(void); #include "generated/radio.h" /** - * Define number of channels - * Using generated code radio.h + * Default number of channels to actually use. */ +#ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB +#endif + +#if RADIO_CONTROL_NB_CHANNEL > RADIO_CTL_NB +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than number of channels in radio file." +#endif /** * ppm pulse type : futaba is falling edge clocked whereas JR is rising edge @@ -49,7 +57,7 @@ extern void ppm_arch_init(void); #define PPM_PULSE_TYPE_POSITIVE 0 #define PPM_PULSE_TYPE_NEGATIVE 1 -extern uint16_t ppm_pulses[ RADIO_CONTROL_NB_CHANNEL ]; +extern uint16_t ppm_pulses[RADIO_CTL_NB]; extern volatile bool_t ppm_frame_available; /** diff --git a/sw/airborne/subsystems/radio_control/sbus_common.h b/sw/airborne/subsystems/radio_control/sbus_common.h index 6e8067f183..48b4476662 100644 --- a/sw/airborne/subsystems/radio_control/sbus_common.h +++ b/sw/airborne/subsystems/radio_control/sbus_common.h @@ -30,6 +30,9 @@ #include "std.h" #include "mcu_periph/uart.h" +/* in case you want to override RADIO_CONTROL_NB_CHANNEL */ +#include "generated/airframe.h" + /** * Macro to use radio.h file * @@ -57,7 +60,17 @@ */ #define SBUS_BUF_LENGTH 24 #define SBUS_NB_CHANNEL 16 + +/** + * Default number of channels to actually use. + */ +#ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL +#endif + +#if RADIO_CONTROL_NB_CHANNEL > SBUS_NB_CHANNEL +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 16." +#endif /** * SBUS structure diff --git a/sw/airborne/subsystems/radio_control/superbitrf_rc.h b/sw/airborne/subsystems/radio_control/superbitrf_rc.h index d20458a0f7..ae91df2f52 100644 --- a/sw/airborne/subsystems/radio_control/superbitrf_rc.h +++ b/sw/airborne/subsystems/radio_control/superbitrf_rc.h @@ -33,6 +33,10 @@ #define RADIO_CONTROL_NB_CHANNEL 14 #endif +#if RADIO_CONTROL_NB_CHANNEL > 14 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 14." +#endif + /* The channel ordering is always the same for DSM2 and DSMX */ #define RADIO_THROTTLE 0 #define RADIO_ROLL 1