Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from paparazzi/spektrum_sim
[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
- Loading branch information
Showing
11 changed files
with
200 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <inttypes.h> | ||
|
||
#if USE_NPS | ||
#include "nps_radio_control.h" | ||
#elif !USE_JSBSIM | ||
#include <caml/mlvalues.h> | ||
#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 |
64 changes: 64 additions & 0 deletions
64
sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2010 Eric Parsonage <eric@eparsonage.com> | ||
* | ||
* 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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters