Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nps_radio_control.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "nps_radio_control.h"
23 
26 
27 #include <stdio.h>
28 
29 #define RADIO_CONTROL_DT (1./40.)
30 
32 
33 
34 
36 {
37 
41 
42  switch (type) {
43  case JOYSTICK:
45  break;
46  case SPEKTRUM:
48  break;
49  case SCRIPT:
50  break;
51  case NORC:
52  break;
53  default:
54  break;
55  }
56 
57 }
58 
59 
60 typedef void (*rc_script)(double);
61 
62 static void radio_control_script_takeoff(double time);
63 static void radio_control_script_hover(double time);
64 static void radio_control_script_step_roll(double time);
65 static void radio_control_script_step_pitch(double time);
66 static void radio_control_script_step_yaw(double time);
67 static void radio_control_script_ff(double time);
68 
69 static rc_script scripts[] = {
75 };
76 
77 
78 #define RADIO_CONTROL_TAKEOFF_TIME 8
79 
80 
81 bool nps_radio_control_available(double time)
82 {
85 
93  //printf("throttle: %f, roll: %f, pitch: %f, yaw: %f\n", nps_joystick.throttle, nps_joystick.roll, nps_joystick.pitch, nps_joystick.yaw);
94  } else if (nps_radio_control.type == SCRIPT) {
95  if (time < RADIO_CONTROL_TAKEOFF_TIME) {
97  } else {
99  }
100  }
101  return TRUE;
102  }
103  return FALSE;
104 }
105 
106 
107 
108 
109 /*
110  * Scripts
111  *
112  *
113  */
114 
116 {
117  nps_radio_control.roll = 0.;
119  nps_radio_control.yaw = 0.;
122  /* starts motors */
123  if (time < 1.) {
124  nps_radio_control.yaw = 1.;
125  } else {
126  nps_radio_control.yaw = 0.;
127  }
128 
129 }
130 
131 void radio_control_script_hover(double time __attribute__((unused)))
132 {
135  nps_radio_control.roll = 0.;
136  nps_radio_control.yaw = 0.;
137 }
138 
139 
141 {
144 
145  if (((int32_t)rint((time * 0.5))) % 2) {
146  nps_radio_control.roll = 0.2;
147  nps_radio_control.yaw = 0.5;
148  } else {
149  nps_radio_control.roll = -0.2;
150  nps_radio_control.yaw = 0.;
151  }
152 }
153 
155 {
156  nps_radio_control.roll = 0.;
157  nps_radio_control.yaw = 0.;
160  if (((int32_t)rint((time * 0.5))) % 2) {
161  nps_radio_control.pitch = 0.2;
162  } else {
163  nps_radio_control.pitch = -0.2;
164  }
165 }
166 
168 {
169  nps_radio_control.roll = 0.;
173 
174  if (((int32_t)rint((time * 0.5))) % 2) {
175  nps_radio_control.yaw = 0.5;
176  } else {
177  nps_radio_control.yaw = -0.5;
178  }
179 }
180 
181 void radio_control_script_ff(double time __attribute__((unused)))
182 {
185  if (time < RADIO_CONTROL_TAKEOFF_TIME + 3) {
186  nps_radio_control.pitch = -1.;
187  } else if (time < RADIO_CONTROL_TAKEOFF_TIME + 6) {
188  // nps_radio_control.roll = 0.5;
189  nps_radio_control.pitch = -1.;
190  } else {
192  nps_radio_control.roll = 0.;
193  }
194 }
#define MODE_SWITCH_MANUAL
NpsRadioControlType
int nps_radio_control_spektrum_init(const char *device)
struct NpsRadioControl nps_radio_control
#define RADIO_CONTROL_DT
#define FALSE
Definition: std.h:5
int nps_radio_control_joystick_init(const char *device)
Initializes SDL and the joystick.
static void radio_control_script_step_pitch(double time)
#define TRUE
Definition: std.h:4
void nps_radio_control_init(enum NpsRadioControlType type, int num_script, char *js_dev)
#define MODE_SWITCH_AUTO2
struct NpsJoystick nps_joystick
signed long int32_t
Definition: types.h:19
#define RADIO_CONTROL_TAKEOFF_TIME
static void radio_control_script_hover(double time)
bool nps_radio_control_available(double time)
void nps_radio_control_joystick_update(void)
Updates joystick buttons from events, directly reads current axis positions.
static void radio_control_script_takeoff(double time)
static void radio_control_script_step_roll(double time)
static rc_script scripts[]
static void radio_control_script_ff(double time)
void(* rc_script)(double)
enum NpsRadioControlType type
static void radio_control_script_step_yaw(double time)