mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-09 22:49:53 +08:00
Merge pull request #975 from paparazzi/cleanup_rc_nb_channel_defines
[radio_control] cleanup channel defines - PPM: remove PPM_NB_CHANNEL define an always decode RADIO_CTL_NB (number of channels in radio.xml) - PPM: the actually used/needed channels RADIO_CONTROL_NB_CHANNEL default to RADIO_CTL_NB but can be overwritten by user e.g. to use less channels for intermcu - SBUS: only provide a default for RADIO_CONTROL_NB_CHANNEL - Spektrum: always try to decode up to SPEKTRUM_NB_CHANNEL (12), but copy only used RADIO_CONTROL_NB_CHANNEL to radio_control.values - error if RADIO_CONTROL_NB_CHANNEL > max available channels As far as I can discern this should finally make it possible to override the actually used RADIO_CONTROL_NB_CHANNEL from the airframe file (e.g. to transfer less via intermcu) while still using the proper number of channels for parsing.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<!-- ************************* FIRMWARE ************************* -->
|
||||
|
||||
<firmware name="fixedwing">
|
||||
<define name="RADIO_CONTROL_NB_CHANNEL" value="8" />
|
||||
<target name="ap" board="lisa_l_1.0">
|
||||
<configure name="SEPARATE_FBW" value="1"/>
|
||||
<configure name="AHRS_ALIGNER_LED" value="1"/>
|
||||
|
||||
+1
-1
@@ -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"
|
||||
/>
|
||||
<aircraft
|
||||
|
||||
@@ -44,8 +44,6 @@
|
||||
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) signed_cpu_ticks_of_usec(_v)
|
||||
#define USEC_OF_RC_PPM_TICKS(_v) usec_of_cpu_ticks(_v)
|
||||
|
||||
#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL
|
||||
|
||||
#define PPM_IT PPM_CRI
|
||||
|
||||
#define PPM_ISR() { \
|
||||
|
||||
@@ -39,8 +39,6 @@
|
||||
#define RC_PPM_SIGNED_TICKS_OF_USEC(_x) (_x)
|
||||
#define USEC_OF_RC_PPM_TICKS(_x) (_x)
|
||||
|
||||
#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL
|
||||
|
||||
#if USE_NPS
|
||||
extern void radio_control_feed(void);
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
#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
|
||||
|
||||
/* channel assignments */
|
||||
#define RADIO_THROTTLE 0
|
||||
#define RADIO_ROLL 1
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user