From a22013c4122e7d2494f5b31c63fdd018d87bc6db Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 9 Oct 2014 22:00:29 +0200 Subject: [PATCH 1/2] [radio_control] spektrum for nps/sim Ocaml sim always uses the radio.xml file and sends ppm values in usec. So for the time beeing you need to use the spektrum.xml radio file for the sim target if you really want to use the RC in the simple OCaml sim. closes #503 --- .../shared/radio_control_spektrum.makefile | 4 +- conf/radios/spektrum.xml | 20 ++-- .../subsystems/radio_control/spektrum_arch.c | 98 +++++++++++++++++++ .../subsystems/radio_control/spektrum_arch.h | 64 ++++++++++++ sw/simulator/nps/nps_autopilot_fixedwing.c | 2 - sw/simulator/nps/nps_autopilot_rotorcraft.c | 2 - 6 files changed, 174 insertions(+), 16 deletions(-) create mode 100644 sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.c create mode 100644 sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h diff --git a/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile b/conf/firmwares/subsystems/shared/radio_control_spektrum.makefile index b19d2cdf4df..e7af64351ee 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 70a16490e74..98b790bbb06 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 00000000000..23a3a20f169 --- /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 00000000000..95f7b901e8d --- /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 08056cf77c3..9e0c3e726b4 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 cd21313acfe..46bfe2a5f7c 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(); From 0a612a0bc78ff2b2774965505307d450076cf192 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 9 Oct 2014 22:43:27 +0200 Subject: [PATCH 2/2] [conf] update examples using spektrum for sim --- conf/airframes/examples/bumblebee_quad.xml | 12 ++++++------ conf/airframes/examples/lisa_asctec.xml | 10 ++++++---- .../examples/quadrotor_lisa_m_2_pwm_spektrum.xml | 10 +++++----- conf/airframes/examples/quadrotor_lisa_mx.xml | 10 +++++----- conf/airframes/examples/quadrotor_navstik.xml | 8 ++++---- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/conf/airframes/examples/bumblebee_quad.xml b/conf/airframes/examples/bumblebee_quad.xml index 560ada12806..2b6575b76d7 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 64872bf9516..0e73f681843 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 4310f31007d..6185641d329 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 b391cca192b..886e4956a0a 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 b81dc542873..1c39eb92c10 100644 --- a/conf/airframes/examples/quadrotor_navstik.xml +++ b/conf/airframes/examples/quadrotor_navstik.xml @@ -12,18 +12,18 @@ - - - - + + + +