diff --git a/conf/airframes/examples/bumblebee_quad.xml b/conf/airframes/examples/bumblebee_quad.xml index 560ada1280..2b6575b76d 100644 --- a/conf/airframes/examples/bumblebee_quad.xml +++ b/conf/airframes/examples/bumblebee_quad.xml @@ -20,19 +20,19 @@ - - - - - - + + + + + + diff --git a/conf/airframes/examples/lisa_asctec.xml b/conf/airframes/examples/lisa_asctec.xml index 64872bf951..0e73f68184 100644 --- a/conf/airframes/examples/lisa_asctec.xml +++ b/conf/airframes/examples/lisa_asctec.xml @@ -176,13 +176,9 @@ - - - - @@ -192,6 +188,12 @@ + + + + + + diff --git a/conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml b/conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml index 4310f31007..6185641d32 100644 --- a/conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml +++ b/conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml @@ -12,18 +12,18 @@ - - - - - + + + + + diff --git a/conf/airframes/examples/quadrotor_lisa_mx.xml b/conf/airframes/examples/quadrotor_lisa_mx.xml index b391cca192..886e4956a0 100644 --- a/conf/airframes/examples/quadrotor_lisa_mx.xml +++ b/conf/airframes/examples/quadrotor_lisa_mx.xml @@ -12,18 +12,18 @@ - - - - - + + + + + diff --git a/conf/airframes/examples/quadrotor_navstik.xml b/conf/airframes/examples/quadrotor_navstik.xml index b81dc54287..1c39eb92c1 100644 --- a/conf/airframes/examples/quadrotor_navstik.xml +++ b/conf/airframes/examples/quadrotor_navstik.xml @@ -12,18 +12,18 @@ - - - - + + + + diff --git a/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile b/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile index b19d2cdf4d..e7af64351e 100644 --- a/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile +++ b/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile @@ -31,8 +31,8 @@ RC_SRCS += $(SRC_SUBSYSTEMS)/radio_control.c \ $(SRC_SUBSYSTEMS)/radio_control/spektrum.c \ $(SRC_ARCH)/subsystems/radio_control/spektrum_arch.c -ap.CFLAGS += $(RC_CFLAGS) -ap.srcs += $(RC_SRCS) +$(TARGET).CFLAGS += $(RC_CFLAGS) +$(TARGET).srcs += $(RC_SRCS) test_radio_control.CFLAGS += $(RC_CFLAGS) test_radio_control.srcs += $(RC_SRCS) diff --git a/conf/radios/spektrum.xml b/conf/radios/spektrum.xml index 70a16490e7..98b790bbb0 100644 --- a/conf/radios/spektrum.xml +++ b/conf/radios/spektrum.xml @@ -44,14 +44,14 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.c b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.c new file mode 100644 index 0000000000..23a3a20f16 --- /dev/null +++ b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010-2012 The Paparazzi Team + * + * 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 arch/sim/spektrum_arch.c + * + * Simulator implementation for spektrum radio control. + * + */ + +#include "subsystems/radio_control.h" +#include "subsystems/radio_control/spektrum.h" + +#include + +#if USE_NPS +#include "nps_radio_control.h" +#elif !USE_JSBSIM +#include +#endif + +static bool_t spektrum_available; + +void radio_control_spektrum_try_bind(void) {} + +void radio_control_impl_init(void) +{ + spektrum_available = FALSE; +} +void RadioControlEventImp(void (*frame_handler)(void) ) { + if (spektrum_available) { + radio_control.frame_cpt++; + radio_control.time_since_last_frame = 0; + radio_control.status = RC_OK; + (*frame_handler)(); + } + spektrum_available = FALSE; +} + +#if USE_NPS +#ifdef RADIO_CONTROL +void radio_control_feed(void) { + radio_control.values[RADIO_ROLL] = nps_radio_control.roll * MAX_PPRZ; + radio_control.values[RADIO_PITCH] = nps_radio_control.pitch * MAX_PPRZ; + radio_control.values[RADIO_YAW] = nps_radio_control.yaw * MAX_PPRZ; + radio_control.values[RADIO_THROTTLE] = nps_radio_control.throttle * MAX_PPRZ; + radio_control.values[RADIO_MODE] = nps_radio_control.mode * MAX_PPRZ; + spektrum_available = TRUE; +} +#else //RADIO_CONTROL +void radio_control_feed(void) {} +#endif //RADIO_CONTROL + +#elif !USE_JSBSIM // not NPS and not JSBSIM -> simple ocaml sim +#ifdef RADIO_CONTROL +value update_rc_channel(value c, value v) { + // OCaml sim sends ppm values read from radio xml + //assume "ppm" value range from 1000 to 2000 for now.. like in fake spektrum.xml + if (Int_val(c) == 0) { + // throttle channel has neutral at 1000 + radio_control.values[Int_val(c)] = (Double_val(v) - 1000.0) / 1000 * MAX_PPRZ; + } + else { + // all other channels at 1500 + radio_control.values[Int_val(c)] = (Double_val(v) - 1500.0) / 500 * MAX_PPRZ; + } + return Val_unit; +} + +value send_ppm(value unit) { + spektrum_available = TRUE; + return unit; +} +#else // RADIO_CONTROL +value update_rc_channel(value c __attribute__ ((unused)), value v __attribute__ ((unused))) { + return Val_unit; +} +value send_ppm(value unit) {return unit;} +#endif // RADIO_CONTROL +#endif // USE_NPS diff --git a/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h new file mode 100644 index 0000000000..95f7b901e8 --- /dev/null +++ b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Eric Parsonage + * + * 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. + * + */ + +#ifndef RADIO_CONTROL_SPEKTRUM_ARCH_H +#define RADIO_CONTROL_SPEKTRUM_ARCH_H + + +/* + * All Spektrum and JR 2.4 GHz transmitters + * have the same channel assignments. + */ + + +#ifndef RADIO_CONTROL_NB_CHANNEL +#define RADIO_CONTROL_NB_CHANNEL 12 +#endif + +/* channel assignments */ +#define RADIO_THROTTLE 0 +#define RADIO_ROLL 1 +#define RADIO_PITCH 2 +#define RADIO_YAW 3 +#define RADIO_GEAR 4 +#define RADIO_FLAP 5 +#define RADIO_AUX1 5 +#define RADIO_AUX2 6 +#define RADIO_AUX3 7 +#define RADIO_AUX4 8 +#define RADIO_AUX5 9 +#define RADIO_AUX6 10 +#define RADIO_AUX7 11 + +/* really for a 9 channel transmitter + we would swap the order of these */ +#ifndef RADIO_MODE +#define RADIO_MODE RADIO_GEAR +#endif + +extern void RadioControlEventImp(void (*_received_frame_handler)(void)); + +#if USE_NPS +extern void radio_control_feed(void); +#endif + +#endif /* RADIO_CONTROL_SPEKTRUM_ARCH_H */ diff --git a/sw/simulator/nps/nps_autopilot_fixedwing.c b/sw/simulator/nps/nps_autopilot_fixedwing.c index 08056cf77c..9e0c3e726b 100644 --- a/sw/simulator/nps/nps_autopilot_fixedwing.c +++ b/sw/simulator/nps/nps_autopilot_fixedwing.c @@ -95,12 +95,10 @@ void nps_autopilot_run_step(double time) { nps_electrical_run_step(time); -#ifdef RADIO_CONTROL_TYPE_PPM if (nps_radio_control_available(time)) { radio_control_feed(); Fbw(event_task); } -#endif if (nps_sensors_gyro_available()) { imu_feed_gyro_accel(); diff --git a/sw/simulator/nps/nps_autopilot_rotorcraft.c b/sw/simulator/nps/nps_autopilot_rotorcraft.c index cd21313acf..46bfe2a5f7 100644 --- a/sw/simulator/nps/nps_autopilot_rotorcraft.c +++ b/sw/simulator/nps/nps_autopilot_rotorcraft.c @@ -82,12 +82,10 @@ void nps_autopilot_run_step(double time) { nps_electrical_run_step(time); -#ifdef RADIO_CONTROL_TYPE_PPM if (nps_radio_control_available(time)) { radio_control_feed(); main_event(); } -#endif if (nps_sensors_gyro_available()) { imu_feed_gyro_accel();