Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
setup_actuators.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2013 The Paparazzi Team
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, see
18 * <http://www.gnu.org/licenses/>.
19 */
25#define MODULES_C
26
27/* PERIODIC_C_MAIN is defined before generated/periodic_telemetry.h
28 * in order to implement telemetry_mode_Main_*
29 */
30#define PERIODIC_C_MAIN
31
32#pragma GCC diagnostic push
33#pragma GCC diagnostic ignored "-Wunused-parameter"
34#include "generated/periodic_telemetry.h"
35#pragma GCC diagnostic pop
36
37#include "generated/airframe.h"
38#include "generated/settings.h"
39#include "generated/modules.h"
40
44
45#include "mcu.h"
46#include "mcu_periph/sys_time.h"
47#include "led.h"
48
50
51
52static inline void main_init(void);
53static inline void main_periodic(void);
54static inline void main_event(void);
55
56int main(void)
57{
58
59 main_init();
60 while (1) {
63 }
64 main_event();
65 };
66 return 0;
67}
68
69
70static inline void main_init(void)
71{
72 mcu_init();
76
78 uint8_t i;
79 for (i = 0; i < ACTUATORS_NB; i++) {
80 //SetServo(i, 1500);
81 }
82
84
86}
87
88
89static inline void main_periodic(void)
90{
91 // generated macro from airframe file
93
94 // Downlink the actuators raw driver values
95 int16_t v[ACTUATORS_NB] = {0};
96 for (int i = 0; i < ACTUATORS_NB; i++) {
97 v[i] = actuators[i].driver_val;
98 }
99
100
101 LED_PERIODIC();
104
106}
107
108static inline void main_event(void)
109{
110 mcu_event();
113}
114
115
116#define IdOfMsg(x) (x[1])
117
118void dl_parse_msg(struct link_device *dev __attribute__((unused)), struct transport_tx *trans __attribute__((unused)), uint8_t *buf)
119{
120 uint8_t msg_id = IdOfMsg(buf);
121 if (msg_id == DL_SET_ACTUATOR) {
124 LED_TOGGLE(2);
125
126 /* bad hack:
127 * first arg to ActuatorSet needs to be the servo _name_ as given in the airframe file
128 * here we rely on the servos having number as names in the setup.xml airframe file
129 */
130 switch (actuator_no) {
131#ifdef SERVO_0
132 case 0: ActuatorSet(0, actuator_value); break;
133#endif
134#ifdef SERVO_1
135 case 1: ActuatorSet(1, actuator_value); break;
136#endif
137#ifdef SERVO_2
138 case 2: ActuatorSet(2, actuator_value); break;
139#endif
140#ifdef SERVO_3
141 case 3: ActuatorSet(3, actuator_value); break;
142#endif
143#ifdef SERVO_4
144 case 4: ActuatorSet(4, actuator_value); break;
145#endif
146#ifdef SERVO_5
147 case 5: ActuatorSet(5, actuator_value); break;
148#endif
149#ifdef SERVO_6
150 case 6: ActuatorSet(6, actuator_value); break;
151#endif
152#ifdef SERVO_7
153 case 7: ActuatorSet(7, actuator_value); break;
154#endif
155#ifdef SERVO_8
156 case 8: ActuatorSet(8, actuator_value); break;
157#endif
158 default: break;
159 }
160
161 //if (actuator_no < ACTUATORS_NB) {
162 // actuators[actuator_no] = actuator_value;
163 //}
164 }
165#ifdef DlSetting
166 else if (msg_id == DL_SETTING && DL_SETTING_ac_id(buf) == AC_ID) {
167 uint8_t i = DL_SETTING_index(buf);
168 float val = DL_SETTING_value(buf);
169 DlSetting(i, val);
170 LED_TOGGLE(2);
171
172#ifdef SERVO_0
174#endif
175#ifdef SERVO_1
177#endif
178#ifdef SERVO_2
180#endif
181#ifdef SERVO_3
183#endif
184#ifdef SERVO_4
186#endif
187#ifdef SERVO_5
189#endif
190#ifdef SERVO_6
192#endif
193#ifdef SERVO_7
195#endif
196#ifdef SERVO_8
198#endif
199
201 } else if (msg_id == DL_GET_SETTING && DL_GET_SETTING_ac_id(buf) == AC_ID) {
203 float val = settings_get_value(i);
205 }
206#endif
207}
#define LED_PERIODIC()
Definition led_hw.h:55
#define LED_TOGGLE(i)
Definition led_hw.h:53
void mcu_init(void)
Microcontroller peripherals initialization.
Definition mcu.c:101
void mcu_event(void)
MCU event functions.
Definition mcu.c:276
arch independent LED (Light Emitting Diodes) API
uint16_t foo
Definition main_demo5.c:58
Arch independent mcu ( Micro Controller Unit ) utilities.
void actuators_init(void)
Definition actuators.c:138
Hardware independent API for actuators (servos, motor controllers).
void pprz_dl_init(void)
Init function.
Definition pprz_dl.c:35
void pprz_dl_event(void)
Datalink Event.
Definition pprz_dl.c:40
Datalink using PPRZ protocol.
static void main_event(void)
static void main_periodic(void)
int main(void)
void dl_parse_msg(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
Should be called when chars are available in dl_buffer.
#define IdOfMsg(x)
static void main_init(void)
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition sys_time.c:43
Architecture independent timing functions.
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition sys_time.h:123
uint16_t val[TCOUPLE_NB]
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.