Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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  }
52 
53 }
54 
55 
56 typedef void (*rc_script)(double);
57 
58 static void radio_control_script_takeoff(double time);
59 static void radio_control_script_hover(double time);
60 static void radio_control_script_step_roll(double time);
61 static void radio_control_script_step_pitch(double time);
62 static void radio_control_script_step_yaw(double time);
63 static void radio_control_script_ff(double time);
64 
65 static rc_script scripts[] = {
71 };
72 
73 
74 #define RADIO_CONTROL_TAKEOFF_TIME 8
75 
76 
77 bool nps_radio_control_available(double time)
78 {
79  if (time >= nps_radio_control.next_update) {
81 
89  //printf("throttle: %f, roll: %f, pitch: %f, yaw: %f\n", nps_joystick.throttle, nps_joystick.roll, nps_joystick.pitch, nps_joystick.yaw);
90  } else if (nps_radio_control.type == SCRIPT) {
91  if (time < RADIO_CONTROL_TAKEOFF_TIME) {
93  } else {
95  }
96  }
97  return TRUE;
98  }
99  return FALSE;
100 }
101 
102 
103 
104 
105 /*
106  * Scripts
107  *
108  *
109  */
110 
112 {
113  nps_radio_control.roll = 0.;
115  nps_radio_control.yaw = 0.;
118  /* starts motors */
119  if (time < 1.) {
120  nps_radio_control.yaw = 1.;
121  } else {
122  nps_radio_control.yaw = 0.;
123  }
124 
125 }
126 
127 void radio_control_script_hover(double time __attribute__((unused)))
128 {
131  nps_radio_control.roll = 0.;
132  nps_radio_control.yaw = 0.;
133 }
134 
135 
137 {
140 
141  if (((int32_t)rint((time * 0.5))) % 2) {
142  nps_radio_control.roll = 0.2;
143  nps_radio_control.yaw = 0.5;
144  } else {
145  nps_radio_control.roll = -0.2;
146  nps_radio_control.yaw = 0.;
147  }
148 }
149 
151 {
152  nps_radio_control.roll = 0.;
153  nps_radio_control.yaw = 0.;
156  if (((int32_t)rint((time * 0.5))) % 2) {
157  nps_radio_control.pitch = 0.2;
158  } else {
159  nps_radio_control.pitch = -0.2;
160  }
161 }
162 
164 {
165  nps_radio_control.roll = 0.;
169 
170  if (((int32_t)rint((time * 0.5))) % 2) {
171  nps_radio_control.yaw = 0.5;
172  } else {
173  nps_radio_control.yaw = -0.5;
174  }
175 }
176 
177 void radio_control_script_ff(double time __attribute__((unused)))
178 {
181  if (time < RADIO_CONTROL_TAKEOFF_TIME + 3) {
182  nps_radio_control.pitch = -1.;
183  } else if (time < RADIO_CONTROL_TAKEOFF_TIME + 6) {
184  // nps_radio_control.roll = 0.5;
185  nps_radio_control.pitch = -1.;
186  } else {
188  nps_radio_control.roll = 0.;
189  }
190 }
#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)