Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 }
scripts
static rc_script scripts[]
Definition: nps_radio_control.c:69
nps_radio_control_spektrum.h
NpsJoystick::roll
double roll
Definition: nps_radio_control_joystick.h:31
nps_joystick
struct NpsJoystick nps_joystick
Definition: nps_radio_control_joystick.c:117
NpsRadioControl::roll
double roll
Definition: nps_radio_control.h:46
NpsRadioControlType
NpsRadioControlType
Definition: nps_radio_control.h:31
NpsRadioControl::yaw
double yaw
Definition: nps_radio_control.h:48
MODE_SWITCH_MANUAL
#define MODE_SWITCH_MANUAL
Definition: nps_radio_control.h:27
NpsJoystick::pitch
double pitch
Definition: nps_radio_control_joystick.h:32
NpsRadioControl::mode
double mode
Definition: nps_radio_control.h:49
SCRIPT
@ SCRIPT
Definition: nps_radio_control.h:32
NORC
@ NORC
Definition: nps_radio_control.h:35
SPEKTRUM
@ SPEKTRUM
Definition: nps_radio_control.h:34
nps_radio_control
struct NpsRadioControl nps_radio_control
Definition: nps_radio_control.c:31
nps_radio_control.h
RADIO_CONTROL_DT
#define RADIO_CONTROL_DT
Definition: nps_radio_control.c:29
NpsRadioControl::next_update
double next_update
Definition: nps_radio_control.h:43
radio_control_script_step_pitch
static void radio_control_script_step_pitch(double time)
Definition: nps_radio_control.c:154
NpsRadioControl::pitch
double pitch
Definition: nps_radio_control.h:47
NpsRadioControl::num_script
int num_script
Definition: nps_radio_control.h:51
MODE_SWITCH_AUTO2
#define MODE_SWITCH_AUTO2
Definition: nps_radio_control.h:29
nps_radio_control_init
void nps_radio_control_init(enum NpsRadioControlType type, int num_script, char *js_dev)
Definition: nps_radio_control.c:35
NpsJoystick::mode
double mode
Definition: nps_radio_control_joystick.h:34
nps_radio_control_spektrum_init
int nps_radio_control_spektrum_init(const char *device)
Definition: nps_radio_control_spektrum.c:31
rc_script
void(* rc_script)(double)
Definition: nps_radio_control.c:60
nps_radio_control_available
bool nps_radio_control_available(double time)
Definition: nps_radio_control.c:81
NpsJoystick::throttle
double throttle
Definition: nps_radio_control_joystick.h:30
NpsJoystick::yaw
double yaw
Definition: nps_radio_control_joystick.h:33
radio_control_script_step_roll
static void radio_control_script_step_roll(double time)
Definition: nps_radio_control.c:140
int32_t
signed long int32_t
Definition: types.h:19
radio_control_script_hover
static void radio_control_script_hover(double time)
Definition: nps_radio_control.c:131
NpsRadioControl::js_dev
char * js_dev
Definition: nps_radio_control.h:52
radio_control_script_takeoff
static void radio_control_script_takeoff(double time)
Definition: nps_radio_control.c:115
RADIO_CONTROL_TAKEOFF_TIME
#define RADIO_CONTROL_TAKEOFF_TIME
Definition: nps_radio_control.c:78
type
timer subsystem type(config options) --------------------------------------------(advanced timers using RCC_APB1) TIM1 adc(if USE_AD_TIM1) radio_control/ppm(if USE_PPM_TIM1
JOYSTICK
@ JOYSTICK
Definition: nps_radio_control.h:33
nps_radio_control_joystick_init
int nps_radio_control_joystick_init(const char *device)
Initializes SDL and the joystick.
Definition: nps_radio_control_joystick.c:130
FALSE
#define FALSE
Definition: std.h:5
nps_radio_control_joystick_update
void nps_radio_control_joystick_update(void)
Updates joystick buttons from events, directly reads current axis positions.
Definition: nps_radio_control_joystick.c:201
TRUE
#define TRUE
Definition: std.h:4
radio_control_script_step_yaw
static void radio_control_script_step_yaw(double time)
Definition: nps_radio_control.c:167
NpsRadioControl::throttle
double throttle
Definition: nps_radio_control.h:45
nps_radio_control_joystick.h
radio_control_script_ff
static void radio_control_script_ff(double time)
Definition: nps_radio_control.c:181
NpsRadioControl
Definition: nps_radio_control.h:42
NpsRadioControl::type
enum NpsRadioControlType type
Definition: nps_radio_control.h:50