Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
setup_actuators.c
Go to the documentation of this file.
1 #include "generated/airframe.h"
2 
3 #include "std.h"
4 #include "mcu.h"
5 #include "mcu_periph/sys_time.h"
6 #include "led.h"
8 //#include "actuators.h"
9 
11 
12 #ifndef DOWNLINK_DEVICE
13 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
14 #endif
15 
16 #define DATALINK_C
19 #include "mcu_periph/uart.h"
21 
22 #include "generated/settings.h"
23 
24 #define IdOfMsg(x) (x[1])
25 
26 
27 void dl_parse_msg( void ) {
28  uint8_t msg_id = IdOfMsg(dl_buffer);
29  if (msg_id == DL_SET_ACTUATOR) {
30  uint8_t servo_no = DL_SET_ACTUATOR_no(dl_buffer);
31  uint16_t servo_value = DL_SET_ACTUATOR_value(dl_buffer);
32  LED_TOGGLE(2);
33  if (servo_no < SERVOS_NB)
34  SetServo(servo_no, servo_value);
35  }
36 #ifdef DlSetting
37  else if (msg_id == DL_SETTING && DL_SETTING_ac_id(dl_buffer) == AC_ID) {
38  uint8_t i = DL_SETTING_index(dl_buffer);
39  float val = DL_SETTING_value(dl_buffer);
40  DlSetting(i, val);
41  LED_TOGGLE(2);
42  for (int j=0 ; j<8 ; j++) {
43  SetServo(j,actuators[j]);
44  }
45  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &val);
46  } else if (msg_id == DL_GET_SETTING && DL_GET_SETTING_ac_id(dl_buffer) == AC_ID) {
47  uint8_t i = DL_GET_SETTING_index(dl_buffer);
48  float val = settings_get_value(i);
49  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &val);
50  }
51 #endif
52 }
53 
54 
55 void init_fbw( void ) {
56  mcu_init();
57 
59 
60  uint8_t i;
61  for(i = 0; i < SERVOS_NB; i++) {
62  SetServo(i, 1500);
63  }
64 
65  // SetServo(SERVO_GAZ, SERVO_GAZ_MIN);
66 
68 
70 }
71 
73 
76 
77 }
78 
79 void periodic_task_fbw(void) {
80  /* static float t; */
81  /* t += 1./60.; */
82  /* uint16_t servo_value = 1500+ 500*sin(t); */
83  /* SetServo(SERVO_THROTTLE, servo_value); */
84 
85  RunOnceEvery(300, DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM));
86  RunOnceEvery(300, DOWNLINK_SEND_ACTUATORS(DefaultChannel, DefaultDevice, SERVOS_NB, actuators ));
87 }
88 
89 void event_task_fbw(void) {
90  DatalinkEvent();
91 }
FBW ( FlyByWire ) process API.
unsigned short uint16_t
Definition: types.h:16
void handle_periodic_tasks_fbw(void)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t actuators[SERVOS_NB]
Definition: actuators.c:31
void event_task_fbw(void)
void periodic_task_fbw(void)
#define SetServo(x, v)
Definition: actuators.h:54
Extra datalink using PPRZ protocol.
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define mcu_int_enable()
Definition: mcu_arch.h:32
Architecture independent timing functions.
uint16_t val[TCOUPLE_NB]
void actuators_init(void)
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
#define LED_TOGGLE(i)
Definition: led_hw.h:30
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
arch independent mcu ( Micro Controller Unit ) utilities
unsigned char uint8_t
Definition: types.h:14
void init_fbw(void)
void dl_parse_msg(void)
#define IdOfMsg(x)
arch independent LED (Light Emitting Diodes) API
void mcu_init(void)
Definition: mcu.c:57